cmCacheManager.cxx 21 KB

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