cmCacheManager.cxx 22 KB

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