1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.h,v $
6 Date: $Date: 2008-03-07 16:43:47 $
7 Version: $Revision: 1.49 $
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"
22 class cmMarkAsAdvancedCommand
;
24 /** \class cmCacheManager
25 * \brief Control class for cmake's cache
27 * Load and Save CMake cache files.
35 friend class cmCacheManager::CacheIterator
;
36 enum CacheEntryType
{ BOOL
=0, PATH
, FILEPATH
, STRING
, INTERNAL
,STATIC
,
44 std::map
<cmStdString
,cmStdString
> Properties
;
46 CacheEntry() : Value(""), Type(UNINITIALIZED
), Initialized(false)
55 bool Find(const char*);
58 const char *GetName() const {
59 return this->Position
->first
.c_str(); }
60 const char* GetProperty(const char*) const ;
61 bool GetPropertyAsBool(const char*) const ;
62 bool PropertyExists(const char*) const;
63 void SetProperty(const char* property
, const char* value
);
64 void SetProperty(const char* property
, bool value
);
65 const char* GetValue() const { return this->GetEntry().Value
.c_str(); }
66 bool GetValueAsBool() const;
67 void SetValue(const char*);
68 CacheEntryType
GetType() const { return this->GetEntry().Type
; }
69 void SetType(CacheEntryType ty
) { this->GetEntry().Type
= ty
; }
70 bool Initialized() { return this->GetEntry().Initialized
; }
71 cmCacheManager
&Container
;
72 std::map
<cmStdString
, CacheEntry
>::iterator Position
;
73 CacheIterator(cmCacheManager
&cm
) : Container(cm
) {
76 CacheIterator(cmCacheManager
&cm
, const char* key
) : Container(cm
)
84 CacheEntry
const& GetEntry() const { return this->Position
->second
; }
85 CacheEntry
& GetEntry() { return this->Position
->second
; }
88 ///! return an iterator to iterate through the cache map
89 cmCacheManager::CacheIterator
NewIterator()
91 return CacheIterator(*this);
95 * Types for the cache entries. These are useful as
96 * hints for a cache editor program. Path should bring
97 * up a file chooser, BOOL a check box, and STRING a
98 * text entry box, FILEPATH is a full path to a file which
99 * can be different than just a path input
101 static CacheEntryType
StringToType(const char*);
102 static const char* TypeToString(CacheEntryType
);
104 ///! Load a cache for given makefile. Loads from ouput home.
105 bool LoadCache(cmMakefile
*);
106 ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
107 bool LoadCache(const char* path
);
108 bool LoadCache(const char* path
, bool internal
);
109 bool LoadCache(const char* path
, bool internal
,
110 std::set
<cmStdString
>& excludes
,
111 std::set
<cmStdString
>& includes
);
113 ///! Save cache for given makefile. Saves to ouput home CMakeCache.txt.
114 bool SaveCache(cmMakefile
*) ;
115 ///! Save cache for given makefile. Saves to ouput path/CMakeCache.txt
116 bool SaveCache(const char* path
) ;
118 ///! Delete the cache given
119 bool DeleteCache(const char* path
);
121 ///! Print the cache to a stream
122 void PrintCache(std::ostream
&) const;
124 ///! Get the iterator for an entry with a given key.
125 cmCacheManager::CacheIterator
GetCacheIterator(const char *key
=0);
127 ///! Remove an entry from the cache
128 void RemoveCacheEntry(const char* key
);
130 ///! Get the number of entries in the cache
132 return static_cast<int>(this->Cache
.size()); }
134 ///! Break up a line like VAR:type="value" into var, type and value
135 static bool ParseEntry(const char* entry
,
138 CacheEntryType
& type
);
140 static bool ParseEntry(const char* entry
,
144 ///! Get a value from the cache given a key
145 const char* GetCacheValue(const char* key
) const;
147 /** Get the version of CMake that wrote the cache. */
148 unsigned int GetCacheMajorVersion() { return this->CacheMajorVersion
; }
149 unsigned int GetCacheMinorVersion() { return this->CacheMinorVersion
; }
150 bool NeedCacheCompatibility(int major
, int minor
);
153 ///! Add an entry into the cache
154 void AddCacheEntry(const char* key
, const char* value
,
155 const char* helpString
, CacheEntryType type
);
157 ///! Add a BOOL entry into the cache
158 void AddCacheEntry(const char* key
, bool, const char* helpString
);
160 ///! Get a cache entry object for a key
161 CacheEntry
*GetCacheEntry(const char *key
);
162 ///! Clean out the CMakeFiles directory if no CMakeCache.txt
163 void CleanCMakeFiles(const char* path
);
165 // Cache version info
166 unsigned int CacheMajorVersion
;
167 unsigned int CacheMinorVersion
;
169 typedef std::map
<cmStdString
, CacheEntry
> CacheEntryMap
;
170 static void OutputHelpString(std::ofstream
& fout
,
171 const std::string
& helpString
);
173 // Only cmake and cmMakefile should be able to add cache values
174 // the commands should never use the cmCacheManager directly
175 friend class cmMakefile
; // allow access to add cache values
176 friend class cmake
; // allow access to add cache values
177 friend class cmakewizard
; // allow access to add cache values
178 friend class cmMarkAsAdvancedCommand
; // allow access to add cache values