1
0

cmCacheManager.cxx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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. // Let us store the current working directory so that if somebody
  262. // Copies it, he will not be surprised
  263. std::string currentcwd = path;
  264. if ( currentcwd[0] >= 'A' && currentcwd[0] <= 'Z' &&
  265. currentcwd[1] == ':' )
  266. {
  267. currentcwd[0] = currentcwd[0] - 'A' + 'a';
  268. }
  269. cmSystemTools::ConvertToUnixSlashes(currentcwd);
  270. this->AddCacheEntry("CMAKE_CACHEFILE_DIR", currentcwd.c_str(),
  271. "This is the directory where this CMakeCahe.txt"
  272. " was created", cmCacheManager::INTERNAL);
  273. fout << "# This is the CMakeCache file.\n"
  274. << "# For build in directory: " << currentcwd << "\n"
  275. << "# You can edit this file to change values found and used by cmake.\n"
  276. << "# If you do not want to change any of the values, simply exit the editor.\n"
  277. << "# If you do want to change a value, simply edit, save, and exit the editor.\n"
  278. << "# The syntax for the file is as follows:\n"
  279. << "# KEY:TYPE=VALUE\n"
  280. << "# KEY is the name of a varible in the cache.\n"
  281. << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.\n"
  282. << "# VALUE is the current value for the KEY.\n\n";
  283. fout << "########################\n";
  284. fout << "# EXTERNAL cache entries\n";
  285. fout << "########################\n";
  286. fout << "\n";
  287. for( std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin();
  288. i != m_Cache.end(); ++i)
  289. {
  290. const CacheEntry& ce = (*i).second;
  291. CacheEntryType t = ce.m_Type;
  292. if(t == cmCacheManager::UNINITIALIZED)
  293. {
  294. /*
  295. // This should be added in, but is not for now.
  296. cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
  297. "\" is uninitialized");
  298. */
  299. }
  300. else if(t != INTERNAL)
  301. {
  302. // Format is key:type=value
  303. std::map<cmStdString,cmStdString>::const_iterator it =
  304. ce.m_Properties.find("HELPSTRING");
  305. if ( it == ce.m_Properties.end() )
  306. {
  307. cmCacheManager::OutputHelpString(fout, "Missing description");
  308. }
  309. else
  310. {
  311. cmCacheManager::OutputHelpString(fout, it->second);
  312. }
  313. std::string key;
  314. // support : in key name by double quoting
  315. if((*i).first.find(':') != std::string::npos ||
  316. (*i).first.find("//") == 0)
  317. {
  318. key = "\"";
  319. key += i->first;
  320. key += "\"";
  321. }
  322. else
  323. {
  324. key = i->first;
  325. }
  326. fout << key.c_str() << ":"
  327. << cmCacheManagerTypes[t] << "=";
  328. // if value has trailing space or tab, enclose it in single quotes
  329. if (ce.m_Value.size() &&
  330. (ce.m_Value[ce.m_Value.size() - 1] == ' ' ||
  331. ce.m_Value[ce.m_Value.size() - 1] == '\t'))
  332. {
  333. fout << '\'' << ce.m_Value << '\'';
  334. }
  335. else
  336. {
  337. fout << ce.m_Value;
  338. }
  339. fout << "\n\n";
  340. }
  341. }
  342. fout << "\n";
  343. fout << "########################\n";
  344. fout << "# INTERNAL cache entries\n";
  345. fout << "########################\n";
  346. fout << "\n";
  347. for( cmCacheManager::CacheIterator i = this->NewIterator();
  348. !i.IsAtEnd(); i.Next())
  349. {
  350. CacheEntryType t = i.GetType();
  351. bool advanced = i.PropertyExists("ADVANCED");
  352. if ( advanced )
  353. {
  354. // Format is key:type=value
  355. std::string key;
  356. std::string rkey = i.GetName();
  357. std::string helpstring;
  358. // If this is advanced variable, we have to do some magic for
  359. // backward compatibility
  360. helpstring = "Advanced flag for variable: ";
  361. helpstring += i.GetName();
  362. rkey += "-ADVANCED";
  363. cmCacheManager::OutputHelpString(fout, helpstring.c_str());
  364. // support : in key name by double quoting
  365. if(rkey.find(':') != std::string::npos ||
  366. rkey.find("//") == 0)
  367. {
  368. key = "\"";
  369. key += rkey;
  370. key += "\"";
  371. }
  372. else
  373. {
  374. key = rkey;
  375. }
  376. fout << key.c_str() << ":INTERNAL="
  377. << (i.GetPropertyAsBool("ADVANCED") ? "1" : "0") << "\n";
  378. }
  379. if(t == cmCacheManager::INTERNAL)
  380. {
  381. // Format is key:type=value
  382. std::string key;
  383. std::string rkey = i.GetName();
  384. std::string helpstring;
  385. const char* hs = i.GetProperty("HELPSTRING");
  386. if ( hs )
  387. {
  388. helpstring = i.GetProperty("HELPSTRING");
  389. }
  390. else
  391. {
  392. helpstring = "";
  393. }
  394. cmCacheManager::OutputHelpString(fout, helpstring.c_str());
  395. // support : in key name by double quoting
  396. if(rkey.find(':') != std::string::npos ||
  397. rkey.find("//") == 0)
  398. {
  399. key = "\"";
  400. key += rkey;
  401. key += "\"";
  402. }
  403. else
  404. {
  405. key = rkey;
  406. }
  407. fout << key.c_str() << ":"
  408. << cmCacheManagerTypes[t] << "=";
  409. // if value has trailing space or tab, enclose it in single quotes
  410. std::string value = i.GetValue();
  411. if (value.size() &&
  412. (value[value.size() - 1] == ' ' ||
  413. value[value.size() - 1] == '\t'))
  414. {
  415. fout << '\'' << value << '\'';
  416. }
  417. else
  418. {
  419. fout << value;
  420. }
  421. fout << "\n";
  422. }
  423. }
  424. fout << "\n";
  425. fout.close();
  426. cmSystemTools::CopyFileIfDifferent(tempFile.c_str(),
  427. cacheFile.c_str());
  428. cmSystemTools::RemoveFile(tempFile.c_str());
  429. return true;
  430. }
  431. void cmCacheManager::OutputHelpString(std::ofstream& fout,
  432. const std::string& helpString)
  433. {
  434. std::string::size_type end = helpString.size();
  435. if(end == 0)
  436. {
  437. return;
  438. }
  439. std::string oneLine;
  440. std::string::size_type pos = 0;
  441. std::string::size_type nextBreak = 60;
  442. bool done = false;
  443. while(!done)
  444. {
  445. if(nextBreak >= end)
  446. {
  447. nextBreak = end;
  448. done = true;
  449. }
  450. else
  451. {
  452. while(nextBreak < end && helpString[nextBreak] != ' ')
  453. {
  454. nextBreak++;
  455. }
  456. }
  457. oneLine = helpString.substr(pos, nextBreak - pos);
  458. fout << "//" << oneLine.c_str() << "\n";
  459. pos = nextBreak;
  460. nextBreak += 60;
  461. }
  462. }
  463. void cmCacheManager::RemoveCacheEntry(const char* key)
  464. {
  465. CacheEntryMap::iterator i = m_Cache.find(key);
  466. if(i != m_Cache.end())
  467. {
  468. m_Cache.erase(i);
  469. }
  470. else
  471. {
  472. std::cerr << "Failed to remove entry:" << key << std::endl;
  473. }
  474. }
  475. cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(const char* key)
  476. {
  477. CacheEntryMap::iterator i = m_Cache.find(key);
  478. if(i != m_Cache.end())
  479. {
  480. return &i->second;
  481. }
  482. return 0;
  483. }
  484. cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char *key)
  485. {
  486. return CacheIterator(*this, key);
  487. }
  488. const char* cmCacheManager::GetCacheValue(const char* key) const
  489. {
  490. CacheEntryMap::const_iterator i = m_Cache.find(key);
  491. if(i != m_Cache.end() && i->second.m_Type != cmCacheManager::UNINITIALIZED)
  492. {
  493. return i->second.m_Value.c_str();
  494. }
  495. return 0;
  496. }
  497. void cmCacheManager::PrintCache(std::ostream& out) const
  498. {
  499. out << "=================================================" << std::endl;
  500. out << "CMakeCache Contents:" << std::endl;
  501. for(std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin();
  502. i != m_Cache.end(); ++i)
  503. {
  504. if((*i).second.m_Type != INTERNAL)
  505. {
  506. out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl;
  507. }
  508. }
  509. out << "\n\n";
  510. out << "To change values in the CMakeCache, \nedit CMakeCache.txt in your output directory.\n";
  511. out << "=================================================" << std::endl;
  512. }
  513. void cmCacheManager::AddCacheEntry(const char* key,
  514. const char* value,
  515. const char* helpString,
  516. CacheEntryType type)
  517. {
  518. CacheEntry& e = m_Cache[key];
  519. if ( value )
  520. {
  521. e.m_Value = value;
  522. }
  523. else
  524. {
  525. e.m_Value = "(none)";
  526. }
  527. e.m_Type = type;
  528. // make sure we only use unix style paths
  529. if(type == FILEPATH || type == PATH)
  530. {
  531. cmSystemTools::ConvertToUnixSlashes(e.m_Value);
  532. }
  533. if ( helpString )
  534. {
  535. e.m_Properties["HELPSTRING"] = helpString;
  536. }
  537. else
  538. {
  539. e.m_Properties["HELPSTRING"] = "(This variable does not exists and should not be used)";
  540. }
  541. m_Cache[key] = e;
  542. }
  543. void cmCacheManager::AddCacheEntry(const char* key, bool v,
  544. const char* helpString)
  545. {
  546. if(v)
  547. {
  548. this->AddCacheEntry(key, "ON", helpString, cmCacheManager::BOOL);
  549. }
  550. else
  551. {
  552. this->AddCacheEntry(key, "OFF", helpString, cmCacheManager::BOOL);
  553. }
  554. }
  555. bool cmCacheManager::CacheIterator::IsAtEnd()
  556. {
  557. return m_Position == m_Container.m_Cache.end();
  558. }
  559. void cmCacheManager::CacheIterator::Begin()
  560. {
  561. m_Position = m_Container.m_Cache.begin();
  562. }
  563. bool cmCacheManager::CacheIterator::Find(const char* key)
  564. {
  565. m_Position = m_Container.m_Cache.find(key);
  566. return !this->IsAtEnd();
  567. }
  568. void cmCacheManager::CacheIterator::Next()
  569. {
  570. ++m_Position;
  571. }
  572. void cmCacheManager::CacheIterator::SetValue(const char* value)
  573. {
  574. CacheEntry* entry = &this->GetEntry();
  575. entry->m_Value = value;
  576. }
  577. const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const
  578. {
  579. if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
  580. {
  581. cmSystemTools::Error("Property \"", property,
  582. "\" cannot be accessed through the GetProperty()");
  583. return 0;
  584. }
  585. const CacheEntry* ent = &this->GetEntry();
  586. std::map<cmStdString,cmStdString>::const_iterator it =
  587. ent->m_Properties.find(property);
  588. if ( it == ent->m_Properties.end() )
  589. {
  590. return 0;
  591. }
  592. return it->second.c_str();
  593. }
  594. void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
  595. {
  596. if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
  597. {
  598. cmSystemTools::Error("Property \"", p,
  599. "\" cannot be accessed through the SetProperty()");
  600. return;
  601. }
  602. CacheEntry* ent = &this->GetEntry();
  603. ent->m_Properties[p] = v;
  604. }
  605. bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) const
  606. {
  607. if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
  608. {
  609. cmSystemTools::Error("Property \"", property,
  610. "\" cannot be accessed through the GetPropertyAsBool()");
  611. return false;
  612. }
  613. const CacheEntry* ent = &this->GetEntry();
  614. std::map<cmStdString,cmStdString>::const_iterator it =
  615. ent->m_Properties.find(property);
  616. if ( it == ent->m_Properties.end() )
  617. {
  618. return false;
  619. }
  620. return cmSystemTools::IsOn(it->second.c_str());
  621. }
  622. void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
  623. {
  624. if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
  625. {
  626. cmSystemTools::Error("Property \"", p,
  627. "\" cannot be accessed through the SetProperty()");
  628. return;
  629. }
  630. CacheEntry* ent = &this->GetEntry();
  631. ent->m_Properties[p] = v ? "ON" : "OFF";
  632. }
  633. bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const
  634. {
  635. if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
  636. {
  637. cmSystemTools::Error("Property \"", property,
  638. "\" cannot be accessed through the PropertyExists()");
  639. return false;
  640. }
  641. const CacheEntry* ent = &this->GetEntry();
  642. std::map<cmStdString,cmStdString>::const_iterator it =
  643. ent->m_Properties.find(property);
  644. if ( it == ent->m_Properties.end() )
  645. {
  646. return false;
  647. }
  648. return true;
  649. }