1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCacheManager.cxx,v $
6 Date: $Date: 2008-08-25 14:31:28 $
7 Version: $Revision: 1.101 $
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 =========================================================================*/
18 #include "cmCacheManager.h"
19 #include "cmSystemTools.h"
20 #include "cmCacheManager.h"
21 #include "cmMakefile.h"
23 #include "cmVersion.h"
25 #include <cmsys/Directory.hxx>
26 #include <cmsys/Glob.hxx>
28 #include <cmsys/RegularExpression.hxx>
30 #if defined(_WIN32) || defined(__CYGWIN__)
34 const char* cmCacheManagerTypes
[] =
45 cmCacheManager::cmCacheManager()
47 this->CacheMajorVersion
= 0;
48 this->CacheMinorVersion
= 0;
51 const char* cmCacheManager::TypeToString(cmCacheManager::CacheEntryType type
)
55 return cmCacheManagerTypes
[6];
57 return cmCacheManagerTypes
[type
];
60 cmCacheManager::CacheEntryType
cmCacheManager::StringToType(const char* s
)
63 while(cmCacheManagerTypes
[i
])
65 if(strcmp(s
, cmCacheManagerTypes
[i
]) == 0)
67 return static_cast<CacheEntryType
>(i
);
74 bool cmCacheManager::LoadCache(cmMakefile
* mf
)
76 return this->LoadCache(mf
->GetHomeOutputDirectory());
80 bool cmCacheManager::LoadCache(const char* path
)
82 return this->LoadCache(path
,true);
85 bool cmCacheManager::LoadCache(const char* path
,
88 std::set
<cmStdString
> emptySet
;
89 return this->LoadCache(path
, internal
, emptySet
, emptySet
);
92 bool cmCacheManager::ParseEntry(const char* entry
,
96 // input line is: key:type=value
97 static cmsys::RegularExpression
reg(
98 "^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
99 // input line is: "key":type=value
100 static cmsys::RegularExpression
regQuoted(
101 "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
103 if(regQuoted
.find(entry
))
105 var
= regQuoted
.match(1);
106 value
= regQuoted
.match(2);
109 else if (reg
.find(entry
))
112 value
= reg
.match(2);
116 // if value is enclosed in single quotes ('foo') then remove them
117 // it is used to enclose trailing space or tab
121 value
[value
.size() - 1] == '\'')
123 value
= value
.substr(1,
130 bool cmCacheManager::ParseEntry(const char* entry
,
133 CacheEntryType
& type
)
135 // input line is: key:type=value
136 static cmsys::RegularExpression
reg(
137 "^([^:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
138 // input line is: "key":type=value
139 static cmsys::RegularExpression
regQuoted(
140 "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
142 if(regQuoted
.find(entry
))
144 var
= regQuoted
.match(1);
145 type
= cmCacheManager::StringToType(regQuoted
.match(2).c_str());
146 value
= regQuoted
.match(3);
149 else if (reg
.find(entry
))
152 type
= cmCacheManager::StringToType(reg
.match(2).c_str());
153 value
= reg
.match(3);
157 // if value is enclosed in single quotes ('foo') then remove them
158 // it is used to enclose trailing space or tab
162 value
[value
.size() - 1] == '\'')
164 value
= value
.substr(1,
171 void cmCacheManager::CleanCMakeFiles(const char* path
)
173 std::string glob
= path
;
174 glob
+= cmake::GetCMakeFilesDirectory();
177 globIt
.FindFiles(glob
);
178 std::vector
<std::string
> files
= globIt
.GetFiles();
179 for(std::vector
<std::string
>::iterator i
= files
.begin();
180 i
!= files
.end(); ++i
)
182 cmSystemTools::RemoveFile(i
->c_str());
186 bool cmCacheManager::LoadCache(const char* path
,
188 std::set
<cmStdString
>& excludes
,
189 std::set
<cmStdString
>& includes
)
191 std::string cacheFile
= path
;
192 cacheFile
+= "/CMakeCache.txt";
193 // clear the old cache, if we are reading in internal values
198 if(!cmSystemTools::FileExists(cacheFile
.c_str()))
200 this->CleanCMakeFiles(path
);
204 std::ifstream
fin(cacheFile
.c_str());
209 const char *realbuffer
;
211 std::string entryKey
;
214 // Format is key:type=value
216 cmSystemTools::GetLineFromStream(fin
, buffer
);
217 realbuffer
= buffer
.c_str();
218 while(*realbuffer
!= '0' &&
219 (*realbuffer
== ' ' ||
220 *realbuffer
== '\t' ||
221 *realbuffer
== '\r' ||
222 *realbuffer
== '\n'))
226 // skip blank lines and comment lines
227 if(realbuffer
[0] == '#' || realbuffer
[0] == 0)
231 while(realbuffer
[0] == '/' && realbuffer
[1] == '/')
233 if ((realbuffer
[2] == '\\') && (realbuffer
[3]=='n'))
235 e
.Properties
["HELPSTRING"] += "\n";
236 e
.Properties
["HELPSTRING"] += &realbuffer
[4];
240 e
.Properties
["HELPSTRING"] += &realbuffer
[2];
242 cmSystemTools::GetLineFromStream(fin
, buffer
);
243 realbuffer
= buffer
.c_str();
249 if(cmCacheManager::ParseEntry(realbuffer
, entryKey
, e
.Value
, e
.Type
))
251 if ( excludes
.find(entryKey
) == excludes
.end() )
253 // Load internal values if internal is set.
254 // If the entry is not internal to the cache being loaded
255 // or if it is in the list of internal entries to be
256 // imported, load it.
257 if ( internal
|| (e
.Type
!= INTERNAL
) ||
258 (includes
.find(entryKey
) != includes
.end()) )
260 // If we are loading the cache from another project,
261 // make all loaded entries internal so that it is
262 // not visible in the gui
266 e
.Properties
["HELPSTRING"] = "DO NOT EDIT, ";
267 e
.Properties
["HELPSTRING"] += entryKey
;
268 e
.Properties
["HELPSTRING"] += " loaded from external file. "
269 "To change this value edit this file: ";
270 e
.Properties
["HELPSTRING"] += path
;
271 e
.Properties
["HELPSTRING"] += "/CMakeCache.txt" ;
273 if ( e
.Type
== cmCacheManager::INTERNAL
&&
274 (entryKey
.size() > strlen("-ADVANCED")) &&
275 strcmp(entryKey
.c_str() + (entryKey
.size() -
276 strlen("-ADVANCED")), "-ADVANCED") == 0 )
278 std::string value
= e
.Value
;
280 entryKey
.substr(0, (entryKey
.size() - strlen("-ADVANCED")));
281 cmCacheManager::CacheIterator it
=
282 this->GetCacheIterator(akey
.c_str());
285 e
.Type
= cmCacheManager::UNINITIALIZED
;
286 this->Cache
[akey
] = e
;
288 if (!it
.Find(akey
.c_str()))
290 cmSystemTools::Error("Internal CMake error when reading cache");
292 it
.SetProperty("ADVANCED", value
.c_str());
294 else if ( e
.Type
== cmCacheManager::INTERNAL
&&
295 (entryKey
.size() > strlen("-MODIFIED")) &&
296 strcmp(entryKey
.c_str() + (entryKey
.size() -
297 strlen("-MODIFIED")), "-MODIFIED") == 0 )
299 std::string value
= e
.Value
;
301 entryKey
.substr(0, (entryKey
.size() - strlen("-MODIFIED")));
302 cmCacheManager::CacheIterator it
=
303 this->GetCacheIterator(akey
.c_str());
306 e
.Type
= cmCacheManager::UNINITIALIZED
;
307 this->Cache
[akey
] = e
;
309 if (!it
.Find(akey
.c_str()))
311 cmSystemTools::Error("Internal CMake error when reading cache");
313 it
.SetProperty("MODIFIED", value
.c_str());
317 e
.Initialized
= true;
318 this->Cache
[entryKey
] = e
;
325 cmSystemTools::Error("Parse error in cache file ", cacheFile
.c_str(),
326 ". Offending entry: ", realbuffer
);
329 this->CacheMajorVersion
= 0;
330 this->CacheMinorVersion
= 0;
331 if(const char* cmajor
= this->GetCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
334 if(sscanf(cmajor
, "%u", &v
) == 1)
336 this->CacheMajorVersion
= v
;
338 if(const char* cminor
= this->GetCacheValue("CMAKE_CACHE_MINOR_VERSION"))
340 if(sscanf(cminor
, "%u", &v
) == 1)
342 this->CacheMinorVersion
= v
;
348 // CMake version not found in the list file.
349 // Set as version 0.0
350 this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
351 "Minor version of cmake used to create the "
352 "current loaded cache", cmCacheManager::INTERNAL
);
353 this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
354 "Major version of cmake used to create the "
355 "current loaded cache", cmCacheManager::INTERNAL
);
358 // check to make sure the cache directory has not
360 if ( internal
&& this->GetCacheValue("CMAKE_CACHEFILE_DIR") )
362 std::string currentcwd
= path
;
363 std::string oldcwd
= this->GetCacheValue("CMAKE_CACHEFILE_DIR");
364 cmSystemTools::ConvertToUnixSlashes(currentcwd
);
365 currentcwd
+= "/CMakeCache.txt";
366 oldcwd
+= "/CMakeCache.txt";
367 if(!cmSystemTools::SameFile(oldcwd
.c_str(), currentcwd
.c_str()))
369 std::string message
=
370 std::string("The current CMakeCache.txt directory ") +
371 currentcwd
+ std::string(" is different than the directory ") +
372 std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) +
373 std::string(" where CMackeCache.txt was created. This may result "
374 "in binaries being created in the wrong place. If you "
375 "are not sure, reedit the CMakeCache.txt");
376 cmSystemTools::Error(message
.c_str());
382 bool cmCacheManager::SaveCache(cmMakefile
* mf
)
384 return this->SaveCache(mf
->GetHomeOutputDirectory());
388 bool cmCacheManager::SaveCache(const char* path
)
390 std::string cacheFile
= path
;
391 cacheFile
+= "/CMakeCache.txt";
392 std::string tempFile
= cacheFile
;
394 std::ofstream
fout(tempFile
.c_str());
397 cmSystemTools::Error("Unable to open cache file for save. ",
399 cmSystemTools::ReportLastSystemError("");
402 // before writing the cache, update the version numbers
405 sprintf(temp
, "%d", cmVersion::GetMinorVersion());
406 this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp
,
407 "Minor version of cmake used to create the "
408 "current loaded cache", cmCacheManager::INTERNAL
);
409 sprintf(temp
, "%d", cmVersion::GetMajorVersion());
410 this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp
,
411 "Major version of cmake used to create the "
412 "current loaded cache", cmCacheManager::INTERNAL
);
414 this->AddCacheEntry("CMAKE_CACHE_RELEASE_VERSION",
415 cmVersion::GetReleaseVersion().c_str(),
416 "Major version of cmake used to create the "
417 "current loaded cache", cmCacheManager::INTERNAL
);
419 // Let us store the current working directory so that if somebody
420 // Copies it, he will not be surprised
421 std::string currentcwd
= path
;
422 if ( currentcwd
[0] >= 'A' && currentcwd
[0] <= 'Z' &&
423 currentcwd
[1] == ':' )
425 currentcwd
[0] = currentcwd
[0] - 'A' + 'a';
427 cmSystemTools::ConvertToUnixSlashes(currentcwd
);
428 this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd
.c_str(),
429 "This is the directory where this CMakeCahe.txt"
430 " was created", cmCacheManager::INTERNAL
);
432 fout
<< "# This is the CMakeCache file.\n"
433 << "# For build in directory: " << currentcwd
<< "\n";
434 cmCacheManager::CacheEntry
* cmakeCacheEntry
435 = this->GetCacheEntry("CMAKE_COMMAND");
436 if ( cmakeCacheEntry
)
438 fout
<< "# It was generated by CMake: " <<
439 cmakeCacheEntry
->Value
<< std::endl
;
442 fout
<< "# You can edit this file to change values found and used by cmake."
444 << "# If you do not want to change any of the values, simply exit the "
445 "editor." << std::endl
446 << "# If you do want to change a value, simply edit, save, and exit "
447 "the editor." << std::endl
448 << "# The syntax for the file is as follows:\n"
449 << "# KEY:TYPE=VALUE\n"
450 << "# KEY is the name of a variable in the cache.\n"
451 << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT "
452 "TYPE!." << std::endl
453 << "# VALUE is the current value for the KEY.\n\n";
455 fout
<< "########################\n";
456 fout
<< "# EXTERNAL cache entries\n";
457 fout
<< "########################\n";
460 for( std::map
<cmStdString
, CacheEntry
>::const_iterator i
=
461 this->Cache
.begin(); i
!= this->Cache
.end(); ++i
)
463 const CacheEntry
& ce
= (*i
).second
;
464 CacheEntryType t
= ce
.Type
;
468 // This should be added in, but is not for now.
469 cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
470 "\" is uninitialized");
473 else if(t
!= INTERNAL
)
475 // Format is key:type=value
476 std::map
<cmStdString
,cmStdString
>::const_iterator it
=
477 ce
.Properties
.find("HELPSTRING");
478 if ( it
== ce
.Properties
.end() )
480 cmCacheManager::OutputHelpString(fout
, "Missing description");
484 cmCacheManager::OutputHelpString(fout
, it
->second
);
487 // support : in key name by double quoting
488 if((*i
).first
.find(':') != std::string::npos
||
489 (*i
).first
.find("//") == 0)
499 fout
<< key
.c_str() << ":"
500 << cmCacheManagerTypes
[t
] << "=";
501 // if value has trailing space or tab, enclose it in single quotes
502 if (ce
.Value
.size() &&
503 (ce
.Value
[ce
.Value
.size() - 1] == ' ' ||
504 ce
.Value
[ce
.Value
.size() - 1] == '\t'))
506 fout
<< '\'' << ce
.Value
<< '\'';
517 fout
<< "########################\n";
518 fout
<< "# INTERNAL cache entries\n";
519 fout
<< "########################\n";
522 for( cmCacheManager::CacheIterator i
= this->NewIterator();
523 !i
.IsAtEnd(); i
.Next())
525 if ( !i
.Initialized() )
530 CacheEntryType t
= i
.GetType();
531 bool advanced
= i
.PropertyExists("ADVANCED");
534 // Format is key:type=value
536 std::string rkey
= i
.GetName();
537 std::string helpstring
;
538 // If this is advanced variable, we have to do some magic for
539 // backward compatibility
540 helpstring
= "Advanced flag for variable: ";
541 helpstring
+= i
.GetName();
543 cmCacheManager::OutputHelpString(fout
, helpstring
.c_str());
544 // support : in key name by double quoting
545 if(rkey
.find(':') != std::string::npos
||
546 rkey
.find("//") == 0)
556 fout
<< key
.c_str() << ":INTERNAL="
557 << (i
.GetPropertyAsBool("ADVANCED") ? "1" : "0") << "\n";
559 bool modified
= i
.PropertyExists("MODIFIED");
562 // Format is key:type=value
564 std::string rkey
= i
.GetName();
565 std::string helpstring
;
566 // If this is advanced variable, we have to do some magic for
567 // backward compatibility
568 helpstring
= "Modified flag for variable: ";
569 helpstring
+= i
.GetName();
571 cmCacheManager::OutputHelpString(fout
, helpstring
.c_str());
572 // support : in key name by double quoting
573 if(rkey
.find(':') != std::string::npos
||
574 rkey
.find("//") == 0)
584 fout
<< key
.c_str() << ":INTERNAL="
585 << (i
.GetPropertyAsBool("MODIFIED") ? "1" : "0") << "\n";
587 if(t
== cmCacheManager::INTERNAL
)
589 // Format is key:type=value
591 std::string rkey
= i
.GetName();
592 std::string helpstring
;
593 const char* hs
= i
.GetProperty("HELPSTRING");
596 helpstring
= i
.GetProperty("HELPSTRING");
602 cmCacheManager::OutputHelpString(fout
, helpstring
.c_str());
603 // support : in key name by double quoting
604 if(rkey
.find(':') != std::string::npos
||
605 rkey
.find("//") == 0)
615 fout
<< key
.c_str() << ":"
616 << cmCacheManagerTypes
[t
] << "=";
617 // if value has trailing space or tab, enclose it in single quotes
618 std::string value
= i
.GetValue();
620 (value
[value
.size() - 1] == ' ' ||
621 value
[value
.size() - 1] == '\t'))
623 fout
<< '\'' << value
<< '\'';
634 cmSystemTools::CopyFileIfDifferent(tempFile
.c_str(),
636 cmSystemTools::RemoveFile(tempFile
.c_str());
637 std::string checkCacheFile
= path
;
638 checkCacheFile
+= cmake::GetCMakeFilesDirectory();
639 cmSystemTools::MakeDirectory(checkCacheFile
.c_str());
640 checkCacheFile
+= "/cmake.check_cache";
641 std::ofstream
checkCache(checkCacheFile
.c_str());
644 cmSystemTools::Error("Unable to open check cache file for write. ",
645 checkCacheFile
.c_str());
648 checkCache
<< "# This file is generated by cmake for dependency checking "
649 "of the CMakeCache.txt file\n";
653 bool cmCacheManager::DeleteCache(const char* path
)
655 std::string cacheFile
= path
;
656 cmSystemTools::ConvertToUnixSlashes(cacheFile
);
657 std::string cmakeFiles
= cacheFile
;
658 cacheFile
+= "/CMakeCache.txt";
659 cmSystemTools::RemoveFile(cacheFile
.c_str());
660 // now remove the files in the CMakeFiles directory
661 // this cleans up language cache files
662 cmsys::Directory dir
;
663 cmakeFiles
+= cmake::GetCMakeFilesDirectory();
664 dir
.Load(cmakeFiles
.c_str());
665 for (unsigned long fileNum
= 0;
666 fileNum
< dir
.GetNumberOfFiles();
670 FileIsDirectory(dir
.GetFile(fileNum
)))
672 std::string fullPath
= cmakeFiles
;
674 fullPath
+= dir
.GetFile(fileNum
);
675 cmSystemTools::RemoveFile(fullPath
.c_str());
681 void cmCacheManager::OutputHelpString(std::ofstream
& fout
,
682 const std::string
& helpString
)
684 std::string::size_type end
= helpString
.size();
690 std::string::size_type pos
= 0;
691 for (std::string::size_type i
=0; i
<=end
; i
++)
694 || (helpString
[i
]=='\n')
695 || ((i
-pos
>= 60) && (helpString
[i
]==' ')))
698 if (helpString
[pos
] == '\n')
703 oneLine
= helpString
.substr(pos
, i
- pos
);
704 fout
<< oneLine
.c_str() << "\n";
710 void cmCacheManager::RemoveCacheEntry(const char* key
)
712 CacheEntryMap::iterator i
= this->Cache
.find(key
);
713 if(i
!= this->Cache
.end())
715 this->Cache
.erase(i
);
720 cmCacheManager::CacheEntry
*cmCacheManager::GetCacheEntry(const char* key
)
722 CacheEntryMap::iterator i
= this->Cache
.find(key
);
723 if(i
!= this->Cache
.end())
730 cmCacheManager::CacheIterator
cmCacheManager::GetCacheIterator(
733 return CacheIterator(*this, key
);
736 const char* cmCacheManager::GetCacheValue(const char* key
) const
738 CacheEntryMap::const_iterator i
= this->Cache
.find(key
);
739 if(i
!= this->Cache
.end() &&
740 i
->second
.Initialized
)
742 return i
->second
.Value
.c_str();
748 void cmCacheManager::PrintCache(std::ostream
& out
) const
750 out
<< "=================================================" << std::endl
;
751 out
<< "CMakeCache Contents:" << std::endl
;
752 for(std::map
<cmStdString
, CacheEntry
>::const_iterator i
=
753 this->Cache
.begin(); i
!= this->Cache
.end(); ++i
)
755 if((*i
).second
.Type
!= INTERNAL
)
757 out
<< (*i
).first
.c_str() << " = " << (*i
).second
.Value
.c_str()
762 out
<< "To change values in the CMakeCache, "
763 << std::endl
<< "edit CMakeCache.txt in your output directory.\n";
764 out
<< "=================================================" << std::endl
;
768 void cmCacheManager::AddCacheEntry(const char* key
,
770 const char* helpString
,
773 CacheEntry
& e
= this->Cache
[key
];
777 e
.Initialized
= true;
784 // make sure we only use unix style paths
785 if(type
== FILEPATH
|| type
== PATH
)
787 cmSystemTools::ConvertToUnixSlashes(e
.Value
);
791 e
.Properties
["HELPSTRING"] = helpString
;
795 e
.Properties
["HELPSTRING"] =
796 "(This variable does not exist and should not be used)";
798 this->Cache
[key
] = e
;
801 void cmCacheManager::AddCacheEntry(const char* key
, bool v
,
802 const char* helpString
)
806 this->AddCacheEntry(key
, "ON", helpString
, cmCacheManager::BOOL
);
810 this->AddCacheEntry(key
, "OFF", helpString
, cmCacheManager::BOOL
);
814 bool cmCacheManager::CacheIterator::IsAtEnd() const
816 return this->Position
== this->Container
.Cache
.end();
819 void cmCacheManager::CacheIterator::Begin()
821 this->Position
= this->Container
.Cache
.begin();
824 bool cmCacheManager::CacheIterator::Find(const char* key
)
826 this->Position
= this->Container
.Cache
.find(key
);
827 return !this->IsAtEnd();
830 void cmCacheManager::CacheIterator::Next()
832 if (!this->IsAtEnd())
838 void cmCacheManager::CacheIterator::SetValue(const char* value
)
844 CacheEntry
* entry
= &this->GetEntry();
847 entry
->Value
= value
;
848 entry
->Initialized
= true;
856 const char* cmCacheManager::CacheIterator::GetProperty(
857 const char* property
) const
859 // make sure it is not at the end
865 if ( !strcmp(property
, "TYPE") || !strcmp(property
, "VALUE") )
867 cmSystemTools::Error("Property \"", property
,
868 "\" cannot be accessed through the GetProperty()");
871 const CacheEntry
* ent
= &this->GetEntry();
872 std::map
<cmStdString
,cmStdString
>::const_iterator it
=
873 ent
->Properties
.find(property
);
874 if ( it
== ent
->Properties
.end() )
878 return it
->second
.c_str();
881 void cmCacheManager::CacheIterator::SetProperty(const char* p
, const char* v
)
883 // make sure it is not at the end
889 if ( !strcmp(p
, "TYPE") || !strcmp(p
, "VALUE") )
891 cmSystemTools::Error("Property \"", p
,
892 "\" cannot be accessed through the SetProperty()");
895 CacheEntry
* ent
= &this->GetEntry();
896 ent
->Properties
[p
] = v
;
900 bool cmCacheManager::CacheIterator::GetValueAsBool() const
902 return cmSystemTools::IsOn(this->GetEntry().Value
.c_str());
905 bool cmCacheManager::CacheIterator::GetPropertyAsBool(
906 const char* property
) const
908 // make sure it is not at the end
914 if ( !strcmp(property
, "TYPE") || !strcmp(property
, "VALUE") )
916 cmSystemTools::Error("Property \"", property
,
917 "\" cannot be accessed through the GetPropertyAsBool()");
920 const CacheEntry
* ent
= &this->GetEntry();
921 std::map
<cmStdString
,cmStdString
>::const_iterator it
=
922 ent
->Properties
.find(property
);
923 if ( it
== ent
->Properties
.end() )
927 return cmSystemTools::IsOn(it
->second
.c_str());
931 void cmCacheManager::CacheIterator::SetProperty(const char* p
, bool v
)
933 // make sure it is not at the end
939 if ( !strcmp(p
, "TYPE") || !strcmp(p
, "VALUE") )
941 cmSystemTools::Error("Property \"", p
,
942 "\" cannot be accessed through the SetProperty()");
945 CacheEntry
* ent
= &this->GetEntry();
946 ent
->Properties
[p
] = v
? "ON" : "OFF";
949 bool cmCacheManager::CacheIterator::PropertyExists(const char* property
) const
951 // make sure it is not at the end
957 if ( !strcmp(property
, "TYPE") || !strcmp(property
, "VALUE") )
959 cmSystemTools::Error("Property \"", property
,
960 "\" cannot be accessed through the PropertyExists()");
963 const CacheEntry
* ent
= &this->GetEntry();
964 std::map
<cmStdString
,cmStdString
>::const_iterator it
=
965 ent
->Properties
.find(property
);
966 if ( it
== ent
->Properties
.end() )
973 //----------------------------------------------------------------------------
974 bool cmCacheManager::NeedCacheCompatibility(int major
, int minor
)
976 // Compatibility is not needed if the cache version is zero because
977 // the cache was created or modified by the user.
978 if(this->CacheMajorVersion
== 0)
983 // Compatibility is needed if the cache version is equal to or lower
984 // than the given version.
985 unsigned int actual_compat
=
986 CMake_VERSION_ENCODE(this->CacheMajorVersion
, this->CacheMinorVersion
, 0);
987 return (actual_compat
&&
988 actual_compat
<= CMake_VERSION_ENCODE(major
, minor
, 0));