1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
6 Date: $Date: 2009-09-11 14:04:09 $
7 Version: $Revision: 1.55 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmCacheManager_h
18 #define cmCacheManager_h
20 #include "cmStandardIncludes.h"
21 #include "cmPropertyMap.h"
23 class cmMarkAsAdvancedCommand
;
26 /** \class cmCacheManager
27 * \brief Control class for cmake's cache
29 * Load and Save CMake cache files.
35 cmCacheManager(cmake
* cm
);
37 friend class cmCacheManager::CacheIterator
;
38 enum CacheEntryType
{ BOOL
=0, PATH
, FILEPATH
, STRING
, INTERNAL
,STATIC
,
46 cmPropertyMap Properties
;
47 const char* GetProperty(const char*) const;
48 void SetProperty(const char* property
, const char* value
);
49 void AppendProperty(const char* property
, const char* value
);
51 CacheEntry() : Value(""), Type(UNINITIALIZED
), Initialized(false)
60 bool Find(const char*);
63 const char *GetName() const {
64 return this->Position
->first
.c_str(); }
65 const char* GetProperty(const char*) const ;
66 bool GetPropertyAsBool(const char*) const ;
67 bool PropertyExists(const char*) const;
68 void SetProperty(const char* property
, const char* value
);
69 void AppendProperty(const char* property
, const char* value
);
70 void SetProperty(const char* property
, bool value
);
71 const char* GetValue() const { return this->GetEntry().Value
.c_str(); }
72 bool GetValueAsBool() const;
73 void SetValue(const char*);
74 CacheEntryType
GetType() const { return this->GetEntry().Type
; }
75 void SetType(CacheEntryType ty
) { this->GetEntry().Type
= ty
; }
76 bool Initialized() { return this->GetEntry().Initialized
; }
77 cmCacheManager
&Container
;
78 std::map
<cmStdString
, CacheEntry
>::iterator Position
;
79 CacheIterator(cmCacheManager
&cm
) : Container(cm
) {
82 CacheIterator(cmCacheManager
&cm
, const char* key
) : Container(cm
)
90 CacheEntry
const& GetEntry() const { return this->Position
->second
; }
91 CacheEntry
& GetEntry() { return this->Position
->second
; }
94 ///! return an iterator to iterate through the cache map
95 cmCacheManager::CacheIterator
NewIterator()
97 return CacheIterator(*this);
101 * Types for the cache entries. These are useful as
102 * hints for a cache editor program. Path should bring
103 * up a file chooser, BOOL a check box, and STRING a
104 * text entry box, FILEPATH is a full path to a file which
105 * can be different than just a path input
107 static CacheEntryType
StringToType(const char*);
108 static const char* TypeToString(CacheEntryType
);
109 static bool IsType(const char*);
111 ///! Load a cache for given makefile. Loads from ouput home.
112 bool LoadCache(cmMakefile
*);
113 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
114 bool LoadCache(const char* path
);
115 bool LoadCache(const char* path
, bool internal
);
116 bool LoadCache(const char* path
, bool internal
,
117 std::set
<cmStdString
>& excludes
,
118 std::set
<cmStdString
>& includes
);
120 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
121 bool SaveCache(cmMakefile
*) ;
122 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
123 bool SaveCache(const char* path
) ;
125 ///! Delete the cache given
126 bool DeleteCache(const char* path
);
128 ///! Print the cache to a stream
129 void PrintCache(std::ostream
&) const;
131 ///! Get the iterator for an entry with a given key.
132 cmCacheManager::CacheIterator
GetCacheIterator(const char *key
=0);
134 ///! Remove an entry from the cache
135 void RemoveCacheEntry(const char* key
);
137 ///! Get the number of entries in the cache
139 return static_cast<int>(this->Cache
.size()); }
141 ///! Break up a line like VAR:type="value" into var, type and value
142 static bool ParseEntry(const char* entry
,
145 CacheEntryType
& type
);
147 static bool ParseEntry(const char* entry
,
151 ///! Get a value from the cache given a key
152 const char* GetCacheValue(const char* key
) const;
154 /** Get the version of CMake that wrote the cache. */
155 unsigned int GetCacheMajorVersion() { return this->CacheMajorVersion
; }
156 unsigned int GetCacheMinorVersion() { return this->CacheMinorVersion
; }
157 bool NeedCacheCompatibility(int major
, int minor
);
159 /** Define and document CACHE entry properties. */
160 static void DefineProperties(cmake
*cm
);
163 ///! Add an entry into the cache
164 void AddCacheEntry(const char* key
, const char* value
,
165 const char* helpString
, CacheEntryType type
);
167 ///! Get a cache entry object for a key
168 CacheEntry
*GetCacheEntry(const char *key
);
169 ///! Clean out the CMakeFiles directory if no CMakeCache.txt
170 void CleanCMakeFiles(const char* path
);
172 // Cache version info
173 unsigned int CacheMajorVersion
;
174 unsigned int CacheMinorVersion
;
176 cmake
* CMakeInstance
;
177 typedef std::map
<cmStdString
, CacheEntry
> CacheEntryMap
;
178 static void OutputHelpString(std::ostream
& fout
,
179 const std::string
& helpString
);
180 static void OutputKey(std::ostream
& fout
, std::string
const& key
);
181 static void OutputValue(std::ostream
& fout
, std::string
const& value
);
183 static const char* PersistentProperties
[];
184 bool ReadPropertyEntry(std::string
const& key
, CacheEntry
& e
);
185 void WritePropertyEntries(std::ostream
& os
, CacheIterator
const& i
);
188 // Only cmake and cmMakefile should be able to add cache values
189 // the commands should never use the cmCacheManager directly
190 friend class cmMakefile
; // allow access to add cache values
191 friend class cmake
; // allow access to add cache values
192 friend class cmakewizard
; // allow access to add cache values
193 friend class cmMarkAsAdvancedCommand
; // allow access to add cache values