cmCacheManager.cxx 21 KB

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