cmCacheManager.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCacheManager.h"
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmSystemTools.h"
  13. #include "cmVersion.h"
  14. #include "cmake.h"
  15. #include <cmsys/Directory.hxx>
  16. #include <cmsys/FStream.hxx>
  17. #include <cmsys/Glob.hxx>
  18. #include <cmsys/RegularExpression.hxx>
  19. cmCacheManager::cmCacheManager()
  20. {
  21. this->CacheMajorVersion = 0;
  22. this->CacheMinorVersion = 0;
  23. }
  24. void cmCacheManager::CleanCMakeFiles(const std::string& path)
  25. {
  26. std::string glob = path;
  27. glob += cmake::GetCMakeFilesDirectory();
  28. glob += "/*.cmake";
  29. cmsys::Glob globIt;
  30. globIt.FindFiles(glob);
  31. std::vector<std::string> files = globIt.GetFiles();
  32. std::for_each(files.begin(), files.end(), cmSystemTools::RemoveFile);
  33. }
  34. bool cmCacheManager::LoadCache(const std::string& path,
  35. bool internal,
  36. std::set<std::string>& excludes,
  37. std::set<std::string>& includes)
  38. {
  39. std::string cacheFile = path;
  40. cacheFile += "/CMakeCache.txt";
  41. // clear the old cache, if we are reading in internal values
  42. if ( internal )
  43. {
  44. this->Cache.clear();
  45. }
  46. if(!cmSystemTools::FileExists(cacheFile.c_str()))
  47. {
  48. this->CleanCMakeFiles(path);
  49. return false;
  50. }
  51. cmsys::ifstream fin(cacheFile.c_str());
  52. if(!fin)
  53. {
  54. return false;
  55. }
  56. const char *realbuffer;
  57. std::string buffer;
  58. std::string entryKey;
  59. unsigned int lineno = 0;
  60. while(fin)
  61. {
  62. // Format is key:type=value
  63. std::string helpString;
  64. CacheEntry e;
  65. cmSystemTools::GetLineFromStream(fin, buffer);
  66. lineno++;
  67. realbuffer = buffer.c_str();
  68. while(*realbuffer != '0' &&
  69. (*realbuffer == ' ' ||
  70. *realbuffer == '\t' ||
  71. *realbuffer == '\r' ||
  72. *realbuffer == '\n'))
  73. {
  74. if (*realbuffer == '\n') lineno++;
  75. realbuffer++;
  76. }
  77. // skip blank lines and comment lines
  78. if(realbuffer[0] == '#' || realbuffer[0] == 0)
  79. {
  80. continue;
  81. }
  82. while(realbuffer[0] == '/' && realbuffer[1] == '/')
  83. {
  84. if ((realbuffer[2] == '\\') && (realbuffer[3]=='n'))
  85. {
  86. helpString += "\n";
  87. helpString += &realbuffer[4];
  88. }
  89. else
  90. {
  91. helpString += &realbuffer[2];
  92. }
  93. cmSystemTools::GetLineFromStream(fin, buffer);
  94. lineno++;
  95. realbuffer = buffer.c_str();
  96. if(!fin)
  97. {
  98. continue;
  99. }
  100. }
  101. e.SetProperty("HELPSTRING", helpString.c_str());
  102. if(cmState::ParseCacheEntry(realbuffer, entryKey, e.Value, e.Type))
  103. {
  104. if ( excludes.find(entryKey) == excludes.end() )
  105. {
  106. // Load internal values if internal is set.
  107. // If the entry is not internal to the cache being loaded
  108. // or if it is in the list of internal entries to be
  109. // imported, load it.
  110. if ( internal || (e.Type != cmState::INTERNAL) ||
  111. (includes.find(entryKey) != includes.end()) )
  112. {
  113. // If we are loading the cache from another project,
  114. // make all loaded entries internal so that it is
  115. // not visible in the gui
  116. if (!internal)
  117. {
  118. e.Type = cmState::INTERNAL;
  119. helpString = "DO NOT EDIT, ";
  120. helpString += entryKey;
  121. helpString += " loaded from external file. "
  122. "To change this value edit this file: ";
  123. helpString += path;
  124. helpString += "/CMakeCache.txt" ;
  125. e.SetProperty("HELPSTRING", helpString.c_str());
  126. }
  127. if(!this->ReadPropertyEntry(entryKey, e))
  128. {
  129. e.Initialized = true;
  130. this->Cache[entryKey] = e;
  131. }
  132. }
  133. }
  134. }
  135. else
  136. {
  137. std::ostringstream error;
  138. error << "Parse error in cache file " << cacheFile;
  139. error << " on line " << lineno << ". Offending entry: " << realbuffer;
  140. cmSystemTools::Error(error.str().c_str());
  141. }
  142. }
  143. this->CacheMajorVersion = 0;
  144. this->CacheMinorVersion = 0;
  145. if(const char* cmajor =
  146. this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION"))
  147. {
  148. unsigned int v=0;
  149. if(sscanf(cmajor, "%u", &v) == 1)
  150. {
  151. this->CacheMajorVersion = v;
  152. }
  153. if(const char* cminor =
  154. this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION"))
  155. {
  156. if(sscanf(cminor, "%u", &v) == 1)
  157. {
  158. this->CacheMinorVersion = v;
  159. }
  160. }
  161. }
  162. else
  163. {
  164. // CMake version not found in the list file.
  165. // Set as version 0.0
  166. this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", "0",
  167. "Minor version of cmake used to create the "
  168. "current loaded cache", cmState::INTERNAL);
  169. this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
  170. "Major version of cmake used to create the "
  171. "current loaded cache", cmState::INTERNAL);
  172. }
  173. // check to make sure the cache directory has not
  174. // been moved
  175. const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
  176. if (internal && oldDir)
  177. {
  178. std::string currentcwd = path;
  179. std::string oldcwd = oldDir;
  180. cmSystemTools::ConvertToUnixSlashes(currentcwd);
  181. currentcwd += "/CMakeCache.txt";
  182. oldcwd += "/CMakeCache.txt";
  183. if(!cmSystemTools::SameFile(oldcwd, currentcwd))
  184. {
  185. std::string message =
  186. std::string("The current CMakeCache.txt directory ") +
  187. currentcwd + std::string(" is different than the directory ") +
  188. std::string(this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR")) +
  189. std::string(" where CMakeCache.txt was created. This may result "
  190. "in binaries being created in the wrong place. If you "
  191. "are not sure, reedit the CMakeCache.txt");
  192. cmSystemTools::Error(message.c_str());
  193. }
  194. }
  195. return true;
  196. }
  197. const char* cmCacheManager::PersistentProperties[] =
  198. {
  199. "ADVANCED",
  200. "MODIFIED",
  201. "STRINGS",
  202. 0
  203. };
  204. bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
  205. CacheEntry& e)
  206. {
  207. // All property entries are internal.
  208. if(e.Type != cmState::INTERNAL)
  209. {
  210. return false;
  211. }
  212. const char* end = entryKey.c_str() + entryKey.size();
  213. for(const char** p = this->PersistentProperties; *p; ++p)
  214. {
  215. std::string::size_type plen = strlen(*p) + 1;
  216. if(entryKey.size() > plen && *(end-plen) == '-' &&
  217. strcmp(end-plen+1, *p) == 0)
  218. {
  219. std::string key = entryKey.substr(0, entryKey.size() - plen);
  220. cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str());
  221. if(it.IsAtEnd())
  222. {
  223. // Create an entry and store the property.
  224. CacheEntry& ne = this->Cache[key];
  225. ne.Type = cmState::UNINITIALIZED;
  226. ne.SetProperty(*p, e.Value.c_str());
  227. }
  228. else
  229. {
  230. // Store this property on its entry.
  231. it.SetProperty(*p, e.Value.c_str());
  232. }
  233. return true;
  234. }
  235. }
  236. return false;
  237. }
  238. void cmCacheManager::WritePropertyEntries(std::ostream& os,
  239. CacheIterator const& i)
  240. {
  241. for(const char** p = this->PersistentProperties; *p; ++p)
  242. {
  243. if(const char* value = i.GetProperty(*p))
  244. {
  245. std::string helpstring = *p;
  246. helpstring += " property for variable: ";
  247. helpstring += i.GetName();
  248. cmCacheManager::OutputHelpString(os, helpstring);
  249. std::string key = i.GetName();
  250. key += "-";
  251. key += *p;
  252. this->OutputKey(os, key);
  253. os << ":INTERNAL=";
  254. this->OutputValue(os, value);
  255. os << "\n";
  256. }
  257. }
  258. }
  259. bool cmCacheManager::SaveCache(const std::string& path)
  260. {
  261. std::string cacheFile = path;
  262. cacheFile += "/CMakeCache.txt";
  263. cmGeneratedFileStream fout(cacheFile.c_str());
  264. fout.SetCopyIfDifferent(true);
  265. if(!fout)
  266. {
  267. cmSystemTools::Error("Unable to open cache file for save. ",
  268. cacheFile.c_str());
  269. cmSystemTools::ReportLastSystemError("");
  270. return false;
  271. }
  272. // before writing the cache, update the version numbers
  273. // to the
  274. char temp[1024];
  275. sprintf(temp, "%d", cmVersion::GetMinorVersion());
  276. this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
  277. "Minor version of cmake used to create the "
  278. "current loaded cache", cmState::INTERNAL);
  279. sprintf(temp, "%d", cmVersion::GetMajorVersion());
  280. this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
  281. "Major version of cmake used to create the "
  282. "current loaded cache", cmState::INTERNAL);
  283. sprintf(temp, "%d", cmVersion::GetPatchVersion());
  284. this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
  285. "Patch version of cmake used to create the "
  286. "current loaded cache", cmState::INTERNAL);
  287. // Let us store the current working directory so that if somebody
  288. // Copies it, he will not be surprised
  289. std::string currentcwd = path;
  290. if ( currentcwd[0] >= 'A' && currentcwd[0] <= 'Z' &&
  291. currentcwd[1] == ':' )
  292. {
  293. // Cast added to avoid compiler warning. Cast is ok because
  294. // value is guaranteed to fit in char by the above if...
  295. currentcwd[0] = static_cast<char>(currentcwd[0] - 'A' + 'a');
  296. }
  297. cmSystemTools::ConvertToUnixSlashes(currentcwd);
  298. this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
  299. "This is the directory where this CMakeCache.txt"
  300. " was created", cmState::INTERNAL);
  301. /* clang-format off */
  302. fout << "# This is the CMakeCache file.\n"
  303. << "# For build in directory: " << currentcwd << "\n"
  304. << "# It was generated by CMake: "
  305. << cmSystemTools::GetCMakeCommand() << std::endl;
  306. /* clang-format on */
  307. /* clang-format off */
  308. fout << "# You can edit this file to change values found and used by cmake."
  309. << std::endl
  310. << "# If you do not want to change any of the values, simply exit the "
  311. "editor." << std::endl
  312. << "# If you do want to change a value, simply edit, save, and exit "
  313. "the editor." << std::endl
  314. << "# The syntax for the file is as follows:\n"
  315. << "# KEY:TYPE=VALUE\n"
  316. << "# KEY is the name of a variable in the cache.\n"
  317. << "# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT "
  318. "TYPE!." << std::endl
  319. << "# VALUE is the current value for the KEY.\n\n";
  320. /* clang-format on */
  321. fout << "########################\n";
  322. fout << "# EXTERNAL cache entries\n";
  323. fout << "########################\n";
  324. fout << "\n";
  325. for( std::map<std::string, CacheEntry>::const_iterator i =
  326. this->Cache.begin(); i != this->Cache.end(); ++i)
  327. {
  328. const CacheEntry& ce = (*i).second;
  329. cmState::CacheEntryType t = ce.Type;
  330. if(!ce.Initialized)
  331. {
  332. /*
  333. // This should be added in, but is not for now.
  334. cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
  335. "\" is uninitialized");
  336. */
  337. }
  338. else if(t != cmState::INTERNAL)
  339. {
  340. // Format is key:type=value
  341. if(const char* help = ce.GetProperty("HELPSTRING"))
  342. {
  343. cmCacheManager::OutputHelpString(fout, help);
  344. }
  345. else
  346. {
  347. cmCacheManager::OutputHelpString(fout, "Missing description");
  348. }
  349. this->OutputKey(fout, i->first);
  350. fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
  351. this->OutputValue(fout, ce.Value);
  352. fout << "\n\n";
  353. }
  354. }
  355. fout << "\n";
  356. fout << "########################\n";
  357. fout << "# INTERNAL cache entries\n";
  358. fout << "########################\n";
  359. fout << "\n";
  360. for( cmCacheManager::CacheIterator i = this->NewIterator();
  361. !i.IsAtEnd(); i.Next())
  362. {
  363. if ( !i.Initialized() )
  364. {
  365. continue;
  366. }
  367. cmState::CacheEntryType t = i.GetType();
  368. this->WritePropertyEntries(fout, i);
  369. if(t == cmState::INTERNAL)
  370. {
  371. // Format is key:type=value
  372. if(const char* help = i.GetProperty("HELPSTRING"))
  373. {
  374. this->OutputHelpString(fout, help);
  375. }
  376. this->OutputKey(fout, i.GetName());
  377. fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
  378. this->OutputValue(fout, i.GetValue());
  379. fout << "\n";
  380. }
  381. }
  382. fout << "\n";
  383. fout.Close();
  384. std::string checkCacheFile = path;
  385. checkCacheFile += cmake::GetCMakeFilesDirectory();
  386. cmSystemTools::MakeDirectory(checkCacheFile.c_str());
  387. checkCacheFile += "/cmake.check_cache";
  388. cmsys::ofstream checkCache(checkCacheFile.c_str());
  389. if(!checkCache)
  390. {
  391. cmSystemTools::Error("Unable to open check cache file for write. ",
  392. checkCacheFile.c_str());
  393. return false;
  394. }
  395. checkCache << "# This file is generated by cmake for dependency checking "
  396. "of the CMakeCache.txt file\n";
  397. return true;
  398. }
  399. bool cmCacheManager::DeleteCache(const std::string& path)
  400. {
  401. std::string cacheFile = path;
  402. cmSystemTools::ConvertToUnixSlashes(cacheFile);
  403. std::string cmakeFiles = cacheFile;
  404. cacheFile += "/CMakeCache.txt";
  405. if(cmSystemTools::FileExists(cacheFile.c_str()))
  406. {
  407. cmSystemTools::RemoveFile(cacheFile);
  408. // now remove the files in the CMakeFiles directory
  409. // this cleans up language cache files
  410. cmakeFiles += cmake::GetCMakeFilesDirectory();
  411. if(cmSystemTools::FileIsDirectory(cmakeFiles))
  412. {
  413. cmSystemTools::RemoveADirectory(cmakeFiles);
  414. }
  415. }
  416. return true;
  417. }
  418. void cmCacheManager::OutputKey(std::ostream& fout, std::string const& key)
  419. {
  420. // support : in key name by double quoting
  421. const char* q = (key.find(':') != key.npos ||
  422. key.find("//") == 0)? "\"" : "";
  423. fout << q << key << q;
  424. }
  425. void cmCacheManager::OutputValue(std::ostream& fout, std::string const& value)
  426. {
  427. // if value has trailing space or tab, enclose it in single quotes
  428. if (!value.empty() &&
  429. (value[value.size() - 1] == ' ' ||
  430. value[value.size() - 1] == '\t'))
  431. {
  432. fout << '\'' << value << '\'';
  433. }
  434. else
  435. {
  436. fout << value;
  437. }
  438. }
  439. void cmCacheManager::OutputHelpString(std::ostream& fout,
  440. const std::string& helpString)
  441. {
  442. std::string::size_type end = helpString.size();
  443. if(end == 0)
  444. {
  445. return;
  446. }
  447. std::string oneLine;
  448. std::string::size_type pos = 0;
  449. for (std::string::size_type i=0; i<=end; i++)
  450. {
  451. if ((i==end)
  452. || (helpString[i]=='\n')
  453. || ((i-pos >= 60) && (helpString[i]==' ')))
  454. {
  455. fout << "//";
  456. if (helpString[pos] == '\n')
  457. {
  458. pos++;
  459. fout << "\\n";
  460. }
  461. oneLine = helpString.substr(pos, i - pos);
  462. fout << oneLine << "\n";
  463. pos = i;
  464. }
  465. }
  466. }
  467. void cmCacheManager::RemoveCacheEntry(const std::string& key)
  468. {
  469. CacheEntryMap::iterator i = this->Cache.find(key);
  470. if(i != this->Cache.end())
  471. {
  472. this->Cache.erase(i);
  473. }
  474. }
  475. cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(
  476. const std::string& key)
  477. {
  478. CacheEntryMap::iterator i = this->Cache.find(key);
  479. if(i != this->Cache.end())
  480. {
  481. return &i->second;
  482. }
  483. return 0;
  484. }
  485. cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
  486. const char *key)
  487. {
  488. return CacheIterator(*this, key);
  489. }
  490. const char*
  491. cmCacheManager::GetInitializedCacheValue(const std::string& key) const
  492. {
  493. CacheEntryMap::const_iterator i = this->Cache.find(key);
  494. if(i != this->Cache.end() &&
  495. i->second.Initialized)
  496. {
  497. return i->second.Value.c_str();
  498. }
  499. return 0;
  500. }
  501. void cmCacheManager::PrintCache(std::ostream& out) const
  502. {
  503. out << "=================================================" << std::endl;
  504. out << "CMakeCache Contents:" << std::endl;
  505. for(std::map<std::string, CacheEntry>::const_iterator i =
  506. this->Cache.begin(); i != this->Cache.end(); ++i)
  507. {
  508. if((*i).second.Type != cmState::INTERNAL)
  509. {
  510. out << (*i).first << " = " << (*i).second.Value
  511. << std::endl;
  512. }
  513. }
  514. out << "\n\n";
  515. out << "To change values in the CMakeCache, "
  516. << std::endl << "edit CMakeCache.txt in your output directory.\n";
  517. out << "=================================================" << std::endl;
  518. }
  519. void cmCacheManager::AddCacheEntry(const std::string& key,
  520. const char* value,
  521. const char* helpString,
  522. cmState::CacheEntryType type)
  523. {
  524. CacheEntry& e = this->Cache[key];
  525. if ( value )
  526. {
  527. e.Value = value;
  528. e.Initialized = true;
  529. }
  530. else
  531. {
  532. e.Value = "";
  533. }
  534. e.Type = type;
  535. // make sure we only use unix style paths
  536. if(type == cmState::FILEPATH || type == cmState::PATH)
  537. {
  538. if(e.Value.find(';') != e.Value.npos)
  539. {
  540. std::vector<std::string> paths;
  541. cmSystemTools::ExpandListArgument(e.Value, paths);
  542. const char* sep = "";
  543. e.Value = "";
  544. for(std::vector<std::string>::iterator i = paths.begin();
  545. i != paths.end(); ++i)
  546. {
  547. cmSystemTools::ConvertToUnixSlashes(*i);
  548. e.Value += sep;
  549. e.Value += *i;
  550. sep = ";";
  551. }
  552. }
  553. else
  554. {
  555. cmSystemTools::ConvertToUnixSlashes(e.Value);
  556. }
  557. }
  558. e.SetProperty("HELPSTRING", helpString? helpString :
  559. "(This variable does not exist and should not be used)");
  560. }
  561. bool cmCacheManager::CacheIterator::IsAtEnd() const
  562. {
  563. return this->Position == this->Container.Cache.end();
  564. }
  565. void cmCacheManager::CacheIterator::Begin()
  566. {
  567. this->Position = this->Container.Cache.begin();
  568. }
  569. bool cmCacheManager::CacheIterator::Find(const std::string& key)
  570. {
  571. this->Position = this->Container.Cache.find(key);
  572. return !this->IsAtEnd();
  573. }
  574. void cmCacheManager::CacheIterator::Next()
  575. {
  576. if (!this->IsAtEnd())
  577. {
  578. ++this->Position;
  579. }
  580. }
  581. void cmCacheManager::CacheIterator::SetValue(const char* value)
  582. {
  583. if (this->IsAtEnd())
  584. {
  585. return;
  586. }
  587. CacheEntry* entry = &this->GetEntry();
  588. if ( value )
  589. {
  590. entry->Value = value;
  591. entry->Initialized = true;
  592. }
  593. else
  594. {
  595. entry->Value = "";
  596. }
  597. }
  598. bool cmCacheManager::CacheIterator::GetValueAsBool() const
  599. {
  600. return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
  601. }
  602. const char*
  603. cmCacheManager::CacheEntry::GetProperty(const std::string& prop) const
  604. {
  605. if(prop == "TYPE")
  606. {
  607. return cmState::CacheEntryTypeToString(this->Type);
  608. }
  609. else if(prop == "VALUE")
  610. {
  611. return this->Value.c_str();
  612. }
  613. return this->Properties.GetPropertyValue(prop);
  614. }
  615. void cmCacheManager::CacheEntry::SetProperty(const std::string& prop,
  616. const char* value)
  617. {
  618. if(prop == "TYPE")
  619. {
  620. this->Type = cmState::StringToCacheEntryType(value? value : "STRING");
  621. }
  622. else if(prop == "VALUE")
  623. {
  624. this->Value = value? value : "";
  625. }
  626. else
  627. {
  628. this->Properties.SetProperty(prop, value);
  629. }
  630. }
  631. void cmCacheManager::CacheEntry::AppendProperty(const std::string& prop,
  632. const char* value,
  633. bool asString)
  634. {
  635. if(prop == "TYPE")
  636. {
  637. this->Type = cmState::StringToCacheEntryType(value? value : "STRING");
  638. }
  639. else if(prop == "VALUE")
  640. {
  641. if(value)
  642. {
  643. if(!this->Value.empty() && *value && !asString)
  644. {
  645. this->Value += ";";
  646. }
  647. this->Value += value;
  648. }
  649. }
  650. else
  651. {
  652. this->Properties.AppendProperty(prop, value, asString);
  653. }
  654. }
  655. const char* cmCacheManager::CacheIterator::GetProperty(
  656. const std::string& prop) const
  657. {
  658. if(!this->IsAtEnd())
  659. {
  660. return this->GetEntry().GetProperty(prop);
  661. }
  662. return 0;
  663. }
  664. void cmCacheManager::CacheIterator::SetProperty(const std::string& p,
  665. const char* v)
  666. {
  667. if(!this->IsAtEnd())
  668. {
  669. this->GetEntry().SetProperty(p, v);
  670. }
  671. }
  672. void cmCacheManager::CacheIterator::AppendProperty(const std::string& p,
  673. const char* v,
  674. bool asString)
  675. {
  676. if(!this->IsAtEnd())
  677. {
  678. this->GetEntry().AppendProperty(p, v, asString);
  679. }
  680. }
  681. bool cmCacheManager::CacheIterator::GetPropertyAsBool(
  682. const std::string& prop) const
  683. {
  684. if(const char* value = this->GetProperty(prop))
  685. {
  686. return cmSystemTools::IsOn(value);
  687. }
  688. return false;
  689. }
  690. void cmCacheManager::CacheIterator::SetProperty(const std::string& p, bool v)
  691. {
  692. this->SetProperty(p, v ? "ON" : "OFF");
  693. }
  694. bool cmCacheManager::CacheIterator::PropertyExists(
  695. const std::string& prop) const
  696. {
  697. return this->GetProperty(prop)? true:false;
  698. }