cmState.cxx 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2015 Stephen Kelly <[email protected]>
  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 "cmState.h"
  11. #include "cmAlgorithms.h"
  12. #include "cmCacheManager.h"
  13. #include "cmCommand.h"
  14. #include "cmDefinitions.h"
  15. #include "cmVersion.h"
  16. #include "cmake.h"
  17. #include <assert.h>
  18. struct cmState::SnapshotDataType
  19. {
  20. cmState::PositionType ScopeParent;
  21. cmState::PositionType DirectoryParent;
  22. cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
  23. cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
  24. cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
  25. cmState::SnapshotType SnapshotType;
  26. bool Keep;
  27. cmLinkedTree<std::string>::iterator ExecutionListFile;
  28. cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
  29. BuildSystemDirectory;
  30. cmLinkedTree<cmDefinitions>::iterator Vars;
  31. cmLinkedTree<cmDefinitions>::iterator Root;
  32. cmLinkedTree<cmDefinitions>::iterator Parent;
  33. std::vector<std::string>::size_type IncludeDirectoryPosition;
  34. std::vector<std::string>::size_type CompileDefinitionsPosition;
  35. std::vector<std::string>::size_type CompileOptionsPosition;
  36. };
  37. struct cmState::PolicyStackEntry : public cmPolicies::PolicyMap
  38. {
  39. typedef cmPolicies::PolicyMap derived;
  40. PolicyStackEntry(bool w = false)
  41. : derived()
  42. , Weak(w)
  43. {
  44. }
  45. PolicyStackEntry(derived const& d, bool w)
  46. : derived(d)
  47. , Weak(w)
  48. {
  49. }
  50. PolicyStackEntry(PolicyStackEntry const& r)
  51. : derived(r)
  52. , Weak(r.Weak)
  53. {
  54. }
  55. bool Weak;
  56. };
  57. struct cmState::BuildsystemDirectoryStateType
  58. {
  59. cmState::PositionType DirectoryEnd;
  60. std::string Location;
  61. std::string OutputLocation;
  62. std::vector<std::string> CurrentSourceDirectoryComponents;
  63. std::vector<std::string> CurrentBinaryDirectoryComponents;
  64. // The top-most directories for relative path conversion. Both the
  65. // source and destination location of a relative path conversion
  66. // must be underneath one of these directories (both under source or
  67. // both under binary) in order for the relative path to be evaluated
  68. // safely by the build tools.
  69. std::string RelativePathTopSource;
  70. std::string RelativePathTopBinary;
  71. std::vector<std::string> IncludeDirectories;
  72. std::vector<cmListFileBacktrace> IncludeDirectoryBacktraces;
  73. std::vector<std::string> CompileDefinitions;
  74. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  75. std::vector<std::string> CompileOptions;
  76. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  77. std::string ProjectName;
  78. cmPropertyMap Properties;
  79. std::vector<cmState::Snapshot> Children;
  80. };
  81. cmState::cmState()
  82. : IsInTryCompile(false)
  83. , WindowsShell(false)
  84. , WindowsVSIDE(false)
  85. , WatcomWMake(false)
  86. , MinGWMake(false)
  87. , NMake(false)
  88. , MSYSShell(false)
  89. {
  90. this->CacheManager = new cmCacheManager;
  91. }
  92. cmState::~cmState()
  93. {
  94. delete this->CacheManager;
  95. cmDeleteAll(this->Commands);
  96. }
  97. const char* cmState::GetTargetTypeName(cmState::TargetType targetType)
  98. {
  99. switch (targetType) {
  100. case cmState::STATIC_LIBRARY:
  101. return "STATIC_LIBRARY";
  102. case cmState::MODULE_LIBRARY:
  103. return "MODULE_LIBRARY";
  104. case cmState::SHARED_LIBRARY:
  105. return "SHARED_LIBRARY";
  106. case cmState::OBJECT_LIBRARY:
  107. return "OBJECT_LIBRARY";
  108. case cmState::EXECUTABLE:
  109. return "EXECUTABLE";
  110. case cmState::UTILITY:
  111. return "UTILITY";
  112. case cmState::GLOBAL_TARGET:
  113. return "GLOBAL_TARGET";
  114. case cmState::INTERFACE_LIBRARY:
  115. return "INTERFACE_LIBRARY";
  116. case cmState::UNKNOWN_LIBRARY:
  117. return "UNKNOWN_LIBRARY";
  118. }
  119. assert(0 && "Unexpected target type");
  120. return 0;
  121. }
  122. const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH",
  123. "STRING", "INTERNAL", "STATIC",
  124. "UNINITIALIZED", 0 };
  125. const char* cmState::CacheEntryTypeToString(cmState::CacheEntryType type)
  126. {
  127. if (type > 6) {
  128. return cmCacheEntryTypes[6];
  129. }
  130. return cmCacheEntryTypes[type];
  131. }
  132. cmState::CacheEntryType cmState::StringToCacheEntryType(const char* s)
  133. {
  134. int i = 0;
  135. while (cmCacheEntryTypes[i]) {
  136. if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
  137. return static_cast<cmState::CacheEntryType>(i);
  138. }
  139. ++i;
  140. }
  141. return STRING;
  142. }
  143. bool cmState::IsCacheEntryType(std::string const& key)
  144. {
  145. for (int i = 0; cmCacheEntryTypes[i]; ++i) {
  146. if (strcmp(key.c_str(), cmCacheEntryTypes[i]) == 0) {
  147. return true;
  148. }
  149. }
  150. return false;
  151. }
  152. bool cmState::LoadCache(const std::string& path, bool internal,
  153. std::set<std::string>& excludes,
  154. std::set<std::string>& includes)
  155. {
  156. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  157. }
  158. bool cmState::SaveCache(const std::string& path)
  159. {
  160. return this->CacheManager->SaveCache(path);
  161. }
  162. bool cmState::DeleteCache(const std::string& path)
  163. {
  164. return this->CacheManager->DeleteCache(path);
  165. }
  166. std::vector<std::string> cmState::GetCacheEntryKeys() const
  167. {
  168. std::vector<std::string> definitions;
  169. definitions.reserve(this->CacheManager->GetSize());
  170. cmCacheManager::CacheIterator cit = this->CacheManager->GetCacheIterator();
  171. for (cit.Begin(); !cit.IsAtEnd(); cit.Next()) {
  172. definitions.push_back(cit.GetName());
  173. }
  174. return definitions;
  175. }
  176. const char* cmState::GetCacheEntryValue(std::string const& key) const
  177. {
  178. cmCacheManager::CacheEntry* e = this->CacheManager->GetCacheEntry(key);
  179. if (!e) {
  180. return 0;
  181. }
  182. return e->Value.c_str();
  183. }
  184. const char* cmState::GetInitializedCacheValue(std::string const& key) const
  185. {
  186. return this->CacheManager->GetInitializedCacheValue(key);
  187. }
  188. cmState::CacheEntryType cmState::GetCacheEntryType(
  189. std::string const& key) const
  190. {
  191. cmCacheManager::CacheIterator it =
  192. this->CacheManager->GetCacheIterator(key.c_str());
  193. return it.GetType();
  194. }
  195. void cmState::SetCacheEntryValue(std::string const& key,
  196. std::string const& value)
  197. {
  198. this->CacheManager->SetCacheEntryValue(key, value);
  199. }
  200. void cmState::SetCacheEntryProperty(std::string const& key,
  201. std::string const& propertyName,
  202. std::string const& value)
  203. {
  204. cmCacheManager::CacheIterator it =
  205. this->CacheManager->GetCacheIterator(key.c_str());
  206. it.SetProperty(propertyName, value.c_str());
  207. }
  208. void cmState::SetCacheEntryBoolProperty(std::string const& key,
  209. std::string const& propertyName,
  210. bool value)
  211. {
  212. cmCacheManager::CacheIterator it =
  213. this->CacheManager->GetCacheIterator(key.c_str());
  214. it.SetProperty(propertyName, value);
  215. }
  216. const char* cmState::GetCacheEntryProperty(std::string const& key,
  217. std::string const& propertyName)
  218. {
  219. cmCacheManager::CacheIterator it =
  220. this->CacheManager->GetCacheIterator(key.c_str());
  221. if (!it.PropertyExists(propertyName)) {
  222. return 0;
  223. }
  224. return it.GetProperty(propertyName);
  225. }
  226. bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
  227. std::string const& propertyName)
  228. {
  229. return this->CacheManager->GetCacheIterator(key.c_str())
  230. .GetPropertyAsBool(propertyName);
  231. }
  232. void cmState::AddCacheEntry(const std::string& key, const char* value,
  233. const char* helpString,
  234. cmState::CacheEntryType type)
  235. {
  236. this->CacheManager->AddCacheEntry(key, value, helpString, type);
  237. }
  238. void cmState::RemoveCacheEntry(std::string const& key)
  239. {
  240. this->CacheManager->RemoveCacheEntry(key);
  241. }
  242. void cmState::AppendCacheEntryProperty(const std::string& key,
  243. const std::string& property,
  244. const std::string& value, bool asString)
  245. {
  246. this->CacheManager->GetCacheIterator(key.c_str())
  247. .AppendProperty(property, value.c_str(), asString);
  248. }
  249. void cmState::RemoveCacheEntryProperty(std::string const& key,
  250. std::string const& propertyName)
  251. {
  252. this->CacheManager->GetCacheIterator(key.c_str())
  253. .SetProperty(propertyName, (void*)0);
  254. }
  255. cmState::Snapshot cmState::Reset()
  256. {
  257. this->GlobalProperties.clear();
  258. this->PropertyDefinitions.clear();
  259. PositionType pos = this->SnapshotData.Truncate();
  260. this->ExecutionListFiles.Truncate();
  261. {
  262. cmLinkedTree<BuildsystemDirectoryStateType>::iterator it =
  263. this->BuildsystemDirectory.Truncate();
  264. it->IncludeDirectories.clear();
  265. it->IncludeDirectoryBacktraces.clear();
  266. it->CompileDefinitions.clear();
  267. it->CompileDefinitionsBacktraces.clear();
  268. it->CompileOptions.clear();
  269. it->CompileOptionsBacktraces.clear();
  270. it->DirectoryEnd = pos;
  271. it->Properties.clear();
  272. it->Children.clear();
  273. }
  274. this->PolicyStack.Clear();
  275. pos->Policies = this->PolicyStack.Root();
  276. pos->PolicyRoot = this->PolicyStack.Root();
  277. pos->PolicyScope = this->PolicyStack.Root();
  278. assert(pos->Policies.IsValid());
  279. assert(pos->PolicyRoot.IsValid());
  280. {
  281. std::string srcDir =
  282. cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
  283. std::string binDir =
  284. cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
  285. this->VarTree.Clear();
  286. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  287. pos->Parent = this->VarTree.Root();
  288. pos->Root = this->VarTree.Root();
  289. pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str());
  290. pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str());
  291. }
  292. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
  293. true);
  294. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
  295. true);
  296. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
  297. true);
  298. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
  299. true);
  300. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
  301. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
  302. return Snapshot(this, pos);
  303. }
  304. void cmState::DefineProperty(const std::string& name,
  305. cmProperty::ScopeType scope,
  306. const char* ShortDescription,
  307. const char* FullDescription, bool chained)
  308. {
  309. this->PropertyDefinitions[scope].DefineProperty(
  310. name, scope, ShortDescription, FullDescription, chained);
  311. }
  312. cmPropertyDefinition const* cmState::GetPropertyDefinition(
  313. const std::string& name, cmProperty::ScopeType scope) const
  314. {
  315. if (this->IsPropertyDefined(name, scope)) {
  316. cmPropertyDefinitionMap const& defs =
  317. this->PropertyDefinitions.find(scope)->second;
  318. return &defs.find(name)->second;
  319. }
  320. return 0;
  321. }
  322. bool cmState::IsPropertyDefined(const std::string& name,
  323. cmProperty::ScopeType scope) const
  324. {
  325. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  326. this->PropertyDefinitions.find(scope);
  327. if (it == this->PropertyDefinitions.end()) {
  328. return false;
  329. }
  330. return it->second.IsPropertyDefined(name);
  331. }
  332. bool cmState::IsPropertyChained(const std::string& name,
  333. cmProperty::ScopeType scope) const
  334. {
  335. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  336. this->PropertyDefinitions.find(scope);
  337. if (it == this->PropertyDefinitions.end()) {
  338. return false;
  339. }
  340. return it->second.IsPropertyChained(name);
  341. }
  342. void cmState::SetLanguageEnabled(std::string const& l)
  343. {
  344. std::vector<std::string>::iterator it = std::lower_bound(
  345. this->EnabledLanguages.begin(), this->EnabledLanguages.end(), l);
  346. if (it == this->EnabledLanguages.end() || *it != l) {
  347. this->EnabledLanguages.insert(it, l);
  348. }
  349. }
  350. bool cmState::GetLanguageEnabled(std::string const& l) const
  351. {
  352. return std::binary_search(this->EnabledLanguages.begin(),
  353. this->EnabledLanguages.end(), l);
  354. }
  355. std::vector<std::string> cmState::GetEnabledLanguages() const
  356. {
  357. return this->EnabledLanguages;
  358. }
  359. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  360. {
  361. this->EnabledLanguages = langs;
  362. }
  363. void cmState::ClearEnabledLanguages()
  364. {
  365. this->EnabledLanguages.clear();
  366. }
  367. bool cmState::GetIsInTryCompile() const
  368. {
  369. return this->IsInTryCompile;
  370. }
  371. void cmState::SetIsInTryCompile(bool b)
  372. {
  373. this->IsInTryCompile = b;
  374. }
  375. void cmState::RenameCommand(std::string const& oldName,
  376. std::string const& newName)
  377. {
  378. // if the command already exists, free the old one
  379. std::string sOldName = cmSystemTools::LowerCase(oldName);
  380. std::string sNewName = cmSystemTools::LowerCase(newName);
  381. std::map<std::string, cmCommand*>::iterator pos =
  382. this->Commands.find(sOldName);
  383. if (pos == this->Commands.end()) {
  384. return;
  385. }
  386. cmCommand* cmd = pos->second;
  387. pos = this->Commands.find(sNewName);
  388. if (pos != this->Commands.end()) {
  389. delete pos->second;
  390. this->Commands.erase(pos);
  391. }
  392. this->Commands.insert(std::make_pair(sNewName, cmd));
  393. pos = this->Commands.find(sOldName);
  394. this->Commands.erase(pos);
  395. }
  396. void cmState::AddCommand(cmCommand* command)
  397. {
  398. std::string name = cmSystemTools::LowerCase(command->GetName());
  399. // if the command already exists, free the old one
  400. std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name);
  401. if (pos != this->Commands.end()) {
  402. delete pos->second;
  403. this->Commands.erase(pos);
  404. }
  405. this->Commands.insert(std::make_pair(name, command));
  406. }
  407. void cmState::RemoveUnscriptableCommands()
  408. {
  409. std::vector<std::string> unscriptableCommands;
  410. for (std::map<std::string, cmCommand*>::iterator pos =
  411. this->Commands.begin();
  412. pos != this->Commands.end();) {
  413. if (!pos->second->IsScriptable()) {
  414. delete pos->second;
  415. this->Commands.erase(pos++);
  416. } else {
  417. ++pos;
  418. }
  419. }
  420. }
  421. cmCommand* cmState::GetCommand(std::string const& name) const
  422. {
  423. cmCommand* command = 0;
  424. std::string sName = cmSystemTools::LowerCase(name);
  425. std::map<std::string, cmCommand*>::const_iterator pos =
  426. this->Commands.find(sName);
  427. if (pos != this->Commands.end()) {
  428. command = (*pos).second;
  429. }
  430. return command;
  431. }
  432. std::vector<std::string> cmState::GetCommandNames() const
  433. {
  434. std::vector<std::string> commandNames;
  435. commandNames.reserve(this->Commands.size());
  436. std::map<std::string, cmCommand*>::const_iterator cmds =
  437. this->Commands.begin();
  438. for (; cmds != this->Commands.end(); ++cmds) {
  439. commandNames.push_back(cmds->first);
  440. }
  441. return commandNames;
  442. }
  443. void cmState::RemoveUserDefinedCommands()
  444. {
  445. std::vector<cmCommand*> renamedCommands;
  446. for (std::map<std::string, cmCommand*>::iterator j = this->Commands.begin();
  447. j != this->Commands.end();) {
  448. if (j->second->IsA("cmMacroHelperCommand") ||
  449. j->second->IsA("cmFunctionHelperCommand")) {
  450. delete j->second;
  451. this->Commands.erase(j++);
  452. } else if (j->first != j->second->GetName()) {
  453. renamedCommands.push_back(j->second);
  454. this->Commands.erase(j++);
  455. } else {
  456. ++j;
  457. }
  458. }
  459. for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin();
  460. it != renamedCommands.end(); ++it) {
  461. this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  462. }
  463. }
  464. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  465. {
  466. this->GlobalProperties.SetProperty(prop, value);
  467. }
  468. void cmState::AppendGlobalProperty(const std::string& prop, const char* value,
  469. bool asString)
  470. {
  471. this->GlobalProperties.AppendProperty(prop, value, asString);
  472. }
  473. const char* cmState::GetGlobalProperty(const std::string& prop)
  474. {
  475. if (prop == "CACHE_VARIABLES") {
  476. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  477. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  478. } else if (prop == "COMMANDS") {
  479. std::vector<std::string> commands = this->GetCommandNames();
  480. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  481. } else if (prop == "IN_TRY_COMPILE") {
  482. this->SetGlobalProperty("IN_TRY_COMPILE",
  483. this->IsInTryCompile ? "1" : "0");
  484. } else if (prop == "ENABLED_LANGUAGES") {
  485. std::string langs;
  486. langs = cmJoin(this->EnabledLanguages, ";");
  487. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  488. }
  489. #define STRING_LIST_ELEMENT(F) ";" #F
  490. if (prop == "CMAKE_C_KNOWN_FEATURES") {
  491. return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
  492. }
  493. if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
  494. return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
  495. }
  496. #undef STRING_LIST_ELEMENT
  497. return this->GlobalProperties.GetPropertyValue(prop);
  498. }
  499. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  500. {
  501. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  502. }
  503. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  504. {
  505. this->SourceDirectory = sourceDirectory;
  506. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  507. cmSystemTools::SplitPath(
  508. cmSystemTools::CollapseFullPath(this->SourceDirectory),
  509. this->SourceDirectoryComponents);
  510. }
  511. const char* cmState::GetSourceDirectory() const
  512. {
  513. return this->SourceDirectory.c_str();
  514. }
  515. std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
  516. {
  517. return this->SourceDirectoryComponents;
  518. }
  519. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  520. {
  521. this->BinaryDirectory = binaryDirectory;
  522. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  523. cmSystemTools::SplitPath(
  524. cmSystemTools::CollapseFullPath(this->BinaryDirectory),
  525. this->BinaryDirectoryComponents);
  526. }
  527. void cmState::SetWindowsShell(bool windowsShell)
  528. {
  529. this->WindowsShell = windowsShell;
  530. }
  531. bool cmState::UseWindowsShell() const
  532. {
  533. return this->WindowsShell;
  534. }
  535. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  536. {
  537. this->WindowsVSIDE = windowsVSIDE;
  538. }
  539. bool cmState::UseWindowsVSIDE() const
  540. {
  541. return this->WindowsVSIDE;
  542. }
  543. void cmState::SetWatcomWMake(bool watcomWMake)
  544. {
  545. this->WatcomWMake = watcomWMake;
  546. }
  547. bool cmState::UseWatcomWMake() const
  548. {
  549. return this->WatcomWMake;
  550. }
  551. void cmState::SetMinGWMake(bool minGWMake)
  552. {
  553. this->MinGWMake = minGWMake;
  554. }
  555. bool cmState::UseMinGWMake() const
  556. {
  557. return this->MinGWMake;
  558. }
  559. void cmState::SetNMake(bool nMake)
  560. {
  561. this->NMake = nMake;
  562. }
  563. bool cmState::UseNMake() const
  564. {
  565. return this->NMake;
  566. }
  567. void cmState::SetMSYSShell(bool mSYSShell)
  568. {
  569. this->MSYSShell = mSYSShell;
  570. }
  571. bool cmState::UseMSYSShell() const
  572. {
  573. return this->MSYSShell;
  574. }
  575. unsigned int cmState::GetCacheMajorVersion() const
  576. {
  577. return this->CacheManager->GetCacheMajorVersion();
  578. }
  579. unsigned int cmState::GetCacheMinorVersion() const
  580. {
  581. return this->CacheManager->GetCacheMinorVersion();
  582. }
  583. const char* cmState::GetBinaryDirectory() const
  584. {
  585. return this->BinaryDirectory.c_str();
  586. }
  587. std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
  588. {
  589. return this->BinaryDirectoryComponents;
  590. }
  591. void cmState::Directory::ComputeRelativePathTopSource()
  592. {
  593. // Relative path conversion inside the source tree is not used to
  594. // construct relative paths passed to build tools so it is safe to use
  595. // even when the source is a network path.
  596. cmState::Snapshot snapshot = this->Snapshot_;
  597. std::vector<cmState::Snapshot> snapshots;
  598. snapshots.push_back(snapshot);
  599. while (true) {
  600. snapshot = snapshot.GetBuildsystemDirectoryParent();
  601. if (snapshot.IsValid()) {
  602. snapshots.push_back(snapshot);
  603. } else {
  604. break;
  605. }
  606. }
  607. std::string result = snapshots.front().GetDirectory().GetCurrentSource();
  608. for (std::vector<cmState::Snapshot>::const_iterator it =
  609. snapshots.begin() + 1;
  610. it != snapshots.end(); ++it) {
  611. std::string currentSource = it->GetDirectory().GetCurrentSource();
  612. if (cmSystemTools::IsSubDirectory(result, currentSource)) {
  613. result = currentSource;
  614. }
  615. }
  616. this->DirectoryState->RelativePathTopSource = result;
  617. }
  618. void cmState::Directory::ComputeRelativePathTopBinary()
  619. {
  620. cmState::Snapshot snapshot = this->Snapshot_;
  621. std::vector<cmState::Snapshot> snapshots;
  622. snapshots.push_back(snapshot);
  623. while (true) {
  624. snapshot = snapshot.GetBuildsystemDirectoryParent();
  625. if (snapshot.IsValid()) {
  626. snapshots.push_back(snapshot);
  627. } else {
  628. break;
  629. }
  630. }
  631. std::string result = snapshots.front().GetDirectory().GetCurrentBinary();
  632. for (std::vector<cmState::Snapshot>::const_iterator it =
  633. snapshots.begin() + 1;
  634. it != snapshots.end(); ++it) {
  635. std::string currentBinary = it->GetDirectory().GetCurrentBinary();
  636. if (cmSystemTools::IsSubDirectory(result, currentBinary)) {
  637. result = currentBinary;
  638. }
  639. }
  640. // The current working directory on Windows cannot be a network
  641. // path. Therefore relative paths cannot work when the binary tree
  642. // is a network path.
  643. if (result.size() < 2 || result.substr(0, 2) != "//") {
  644. this->DirectoryState->RelativePathTopBinary = result;
  645. } else {
  646. this->DirectoryState->RelativePathTopBinary = "";
  647. }
  648. }
  649. cmState::Snapshot cmState::CreateBaseSnapshot()
  650. {
  651. PositionType pos = this->SnapshotData.Push(this->SnapshotData.Root());
  652. pos->DirectoryParent = this->SnapshotData.Root();
  653. pos->ScopeParent = this->SnapshotData.Root();
  654. pos->SnapshotType = BaseType;
  655. pos->Keep = true;
  656. pos->BuildSystemDirectory =
  657. this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
  658. pos->ExecutionListFile =
  659. this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
  660. pos->IncludeDirectoryPosition = 0;
  661. pos->CompileDefinitionsPosition = 0;
  662. pos->CompileOptionsPosition = 0;
  663. pos->BuildSystemDirectory->DirectoryEnd = pos;
  664. pos->Policies = this->PolicyStack.Root();
  665. pos->PolicyRoot = this->PolicyStack.Root();
  666. pos->PolicyScope = this->PolicyStack.Root();
  667. assert(pos->Policies.IsValid());
  668. assert(pos->PolicyRoot.IsValid());
  669. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  670. assert(pos->Vars.IsValid());
  671. pos->Parent = this->VarTree.Root();
  672. pos->Root = this->VarTree.Root();
  673. return cmState::Snapshot(this, pos);
  674. }
  675. cmState::Snapshot cmState::CreateBuildsystemDirectorySnapshot(
  676. Snapshot originSnapshot)
  677. {
  678. assert(originSnapshot.IsValid());
  679. PositionType pos = this->SnapshotData.Push(originSnapshot.Position);
  680. pos->DirectoryParent = originSnapshot.Position;
  681. pos->ScopeParent = originSnapshot.Position;
  682. pos->SnapshotType = BuildsystemDirectoryType;
  683. pos->Keep = true;
  684. pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
  685. originSnapshot.Position->BuildSystemDirectory);
  686. pos->ExecutionListFile =
  687. this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
  688. pos->BuildSystemDirectory->DirectoryEnd = pos;
  689. pos->Policies = originSnapshot.Position->Policies;
  690. pos->PolicyRoot = originSnapshot.Position->Policies;
  691. pos->PolicyScope = originSnapshot.Position->Policies;
  692. assert(pos->Policies.IsValid());
  693. assert(pos->PolicyRoot.IsValid());
  694. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  695. pos->Parent = origin;
  696. pos->Root = origin;
  697. pos->Vars = this->VarTree.Push(origin);
  698. cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
  699. originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
  700. snapshot.SetDefaultDefinitions();
  701. snapshot.InitializeFromParent();
  702. snapshot.SetDirectoryDefinitions();
  703. return snapshot;
  704. }
  705. cmState::Snapshot cmState::CreateFunctionCallSnapshot(
  706. cmState::Snapshot originSnapshot, std::string const& fileName)
  707. {
  708. PositionType pos =
  709. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  710. pos->ScopeParent = originSnapshot.Position;
  711. pos->SnapshotType = FunctionCallType;
  712. pos->Keep = false;
  713. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  714. originSnapshot.Position->ExecutionListFile, fileName);
  715. pos->BuildSystemDirectory->DirectoryEnd = pos;
  716. pos->PolicyScope = originSnapshot.Position->Policies;
  717. assert(originSnapshot.Position->Vars.IsValid());
  718. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  719. pos->Parent = origin;
  720. pos->Vars = this->VarTree.Push(origin);
  721. return cmState::Snapshot(this, pos);
  722. }
  723. cmState::Snapshot cmState::CreateMacroCallSnapshot(
  724. cmState::Snapshot originSnapshot, std::string const& fileName)
  725. {
  726. PositionType pos =
  727. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  728. pos->SnapshotType = MacroCallType;
  729. pos->Keep = false;
  730. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  731. originSnapshot.Position->ExecutionListFile, fileName);
  732. assert(originSnapshot.Position->Vars.IsValid());
  733. pos->BuildSystemDirectory->DirectoryEnd = pos;
  734. pos->PolicyScope = originSnapshot.Position->Policies;
  735. return cmState::Snapshot(this, pos);
  736. }
  737. cmState::Snapshot cmState::CreateIncludeFileSnapshot(
  738. cmState::Snapshot originSnapshot, const std::string& fileName)
  739. {
  740. PositionType pos =
  741. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  742. pos->SnapshotType = IncludeFileType;
  743. pos->Keep = true;
  744. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  745. originSnapshot.Position->ExecutionListFile, fileName);
  746. assert(originSnapshot.Position->Vars.IsValid());
  747. pos->BuildSystemDirectory->DirectoryEnd = pos;
  748. pos->PolicyScope = originSnapshot.Position->Policies;
  749. return cmState::Snapshot(this, pos);
  750. }
  751. cmState::Snapshot cmState::CreateVariableScopeSnapshot(
  752. cmState::Snapshot originSnapshot)
  753. {
  754. PositionType pos =
  755. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  756. pos->ScopeParent = originSnapshot.Position;
  757. pos->SnapshotType = VariableScopeType;
  758. pos->Keep = false;
  759. pos->PolicyScope = originSnapshot.Position->Policies;
  760. assert(originSnapshot.Position->Vars.IsValid());
  761. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  762. pos->Parent = origin;
  763. pos->Vars = this->VarTree.Push(origin);
  764. assert(pos->Vars.IsValid());
  765. return cmState::Snapshot(this, pos);
  766. }
  767. cmState::Snapshot cmState::CreateInlineListFileSnapshot(
  768. cmState::Snapshot originSnapshot, const std::string& fileName)
  769. {
  770. PositionType pos =
  771. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  772. pos->SnapshotType = InlineListFileType;
  773. pos->Keep = true;
  774. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  775. originSnapshot.Position->ExecutionListFile, fileName);
  776. pos->BuildSystemDirectory->DirectoryEnd = pos;
  777. pos->PolicyScope = originSnapshot.Position->Policies;
  778. return cmState::Snapshot(this, pos);
  779. }
  780. cmState::Snapshot cmState::CreatePolicyScopeSnapshot(
  781. cmState::Snapshot originSnapshot)
  782. {
  783. PositionType pos =
  784. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  785. pos->SnapshotType = PolicyScopeType;
  786. pos->Keep = false;
  787. pos->BuildSystemDirectory->DirectoryEnd = pos;
  788. pos->PolicyScope = originSnapshot.Position->Policies;
  789. return cmState::Snapshot(this, pos);
  790. }
  791. cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
  792. {
  793. PositionType pos = originSnapshot.Position;
  794. PositionType prevPos = pos;
  795. ++prevPos;
  796. prevPos->IncludeDirectoryPosition =
  797. prevPos->BuildSystemDirectory->IncludeDirectories.size();
  798. prevPos->CompileDefinitionsPosition =
  799. prevPos->BuildSystemDirectory->CompileDefinitions.size();
  800. prevPos->CompileOptionsPosition =
  801. prevPos->BuildSystemDirectory->CompileOptions.size();
  802. prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
  803. if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
  804. if (pos->Vars != prevPos->Vars) {
  805. assert(this->VarTree.IsLast(pos->Vars));
  806. this->VarTree.Pop(pos->Vars);
  807. }
  808. if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
  809. assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
  810. this->ExecutionListFiles.Pop(pos->ExecutionListFile);
  811. }
  812. this->SnapshotData.Pop(pos);
  813. }
  814. return Snapshot(this, prevPos);
  815. }
  816. cmState::Snapshot::Snapshot(cmState* state)
  817. : State(state)
  818. , Position()
  819. {
  820. }
  821. std::vector<cmState::Snapshot> cmState::Snapshot::GetChildren()
  822. {
  823. return this->Position->BuildSystemDirectory->Children;
  824. }
  825. cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  826. : State(state)
  827. , Position(position)
  828. {
  829. }
  830. cmState::SnapshotType cmState::Snapshot::GetType() const
  831. {
  832. return this->Position->SnapshotType;
  833. }
  834. const char* cmState::Directory::GetCurrentSource() const
  835. {
  836. return this->DirectoryState->Location.c_str();
  837. }
  838. void cmState::Directory::SetCurrentSource(std::string const& dir)
  839. {
  840. std::string& loc = this->DirectoryState->Location;
  841. loc = dir;
  842. cmSystemTools::ConvertToUnixSlashes(loc);
  843. loc = cmSystemTools::CollapseFullPath(loc);
  844. cmSystemTools::SplitPath(
  845. loc, this->DirectoryState->CurrentSourceDirectoryComponents);
  846. this->ComputeRelativePathTopSource();
  847. this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc);
  848. }
  849. const char* cmState::Directory::GetCurrentBinary() const
  850. {
  851. return this->DirectoryState->OutputLocation.c_str();
  852. }
  853. void cmState::Directory::SetCurrentBinary(std::string const& dir)
  854. {
  855. std::string& loc = this->DirectoryState->OutputLocation;
  856. loc = dir;
  857. cmSystemTools::ConvertToUnixSlashes(loc);
  858. loc = cmSystemTools::CollapseFullPath(loc);
  859. cmSystemTools::SplitPath(
  860. loc, this->DirectoryState->CurrentBinaryDirectoryComponents);
  861. this->ComputeRelativePathTopBinary();
  862. this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc);
  863. }
  864. void cmState::Snapshot::SetListFile(const std::string& listfile)
  865. {
  866. *this->Position->ExecutionListFile = listfile;
  867. }
  868. std::vector<std::string> const&
  869. cmState::Directory::GetCurrentSourceComponents() const
  870. {
  871. return this->DirectoryState->CurrentSourceDirectoryComponents;
  872. }
  873. std::vector<std::string> const&
  874. cmState::Directory::GetCurrentBinaryComponents() const
  875. {
  876. return this->DirectoryState->CurrentBinaryDirectoryComponents;
  877. }
  878. const char* cmState::Directory::GetRelativePathTopSource() const
  879. {
  880. return this->DirectoryState->RelativePathTopSource.c_str();
  881. }
  882. const char* cmState::Directory::GetRelativePathTopBinary() const
  883. {
  884. return this->DirectoryState->RelativePathTopBinary.c_str();
  885. }
  886. void cmState::Directory::SetRelativePathTopSource(const char* dir)
  887. {
  888. this->DirectoryState->RelativePathTopSource = dir;
  889. }
  890. void cmState::Directory::SetRelativePathTopBinary(const char* dir)
  891. {
  892. this->DirectoryState->RelativePathTopBinary = dir;
  893. }
  894. std::string cmState::Snapshot::GetExecutionListFile() const
  895. {
  896. return *this->Position->ExecutionListFile;
  897. }
  898. bool cmState::Snapshot::IsValid() const
  899. {
  900. return this->State && this->Position.IsValid()
  901. ? this->Position != this->State->SnapshotData.Root()
  902. : false;
  903. }
  904. cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
  905. {
  906. Snapshot snapshot;
  907. if (!this->State || this->Position == this->State->SnapshotData.Root()) {
  908. return snapshot;
  909. }
  910. PositionType parentPos = this->Position->DirectoryParent;
  911. if (parentPos != this->State->SnapshotData.Root()) {
  912. snapshot =
  913. Snapshot(this->State, parentPos->BuildSystemDirectory->DirectoryEnd);
  914. }
  915. return snapshot;
  916. }
  917. cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
  918. {
  919. assert(this->State);
  920. assert(this->Position != this->State->SnapshotData.Root());
  921. Snapshot snapshot;
  922. PositionType parentPos = this->Position;
  923. while (parentPos->SnapshotType == cmState::PolicyScopeType ||
  924. parentPos->SnapshotType == cmState::VariableScopeType) {
  925. ++parentPos;
  926. }
  927. if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType ||
  928. parentPos->SnapshotType == cmState::BaseType) {
  929. return snapshot;
  930. }
  931. ++parentPos;
  932. while (parentPos->SnapshotType == cmState::PolicyScopeType ||
  933. parentPos->SnapshotType == cmState::VariableScopeType) {
  934. ++parentPos;
  935. }
  936. if (parentPos == this->State->SnapshotData.Root()) {
  937. return snapshot;
  938. }
  939. snapshot = Snapshot(this->State, parentPos);
  940. return snapshot;
  941. }
  942. cmState::Snapshot cmState::Snapshot::GetCallStackBottom() const
  943. {
  944. assert(this->State);
  945. assert(this->Position != this->State->SnapshotData.Root());
  946. PositionType pos = this->Position;
  947. while (pos->SnapshotType != cmState::BaseType &&
  948. pos->SnapshotType != cmState::BuildsystemDirectoryType &&
  949. pos != this->State->SnapshotData.Root()) {
  950. ++pos;
  951. }
  952. return Snapshot(this->State, pos);
  953. }
  954. void cmState::Snapshot::PushPolicy(cmPolicies::PolicyMap entry, bool weak)
  955. {
  956. PositionType pos = this->Position;
  957. pos->Policies = this->State->PolicyStack.Push(pos->Policies,
  958. PolicyStackEntry(entry, weak));
  959. }
  960. bool cmState::Snapshot::PopPolicy()
  961. {
  962. PositionType pos = this->Position;
  963. if (pos->Policies == pos->PolicyScope) {
  964. return false;
  965. }
  966. pos->Policies = this->State->PolicyStack.Pop(pos->Policies);
  967. return true;
  968. }
  969. bool cmState::Snapshot::CanPopPolicyScope()
  970. {
  971. return this->Position->Policies == this->Position->PolicyScope;
  972. }
  973. void cmState::Snapshot::SetPolicy(cmPolicies::PolicyID id,
  974. cmPolicies::PolicyStatus status)
  975. {
  976. // Update the policy stack from the top to the top-most strong entry.
  977. bool previous_was_weak = true;
  978. for (cmLinkedTree<PolicyStackEntry>::iterator psi = this->Position->Policies;
  979. previous_was_weak && psi != this->Position->PolicyRoot; ++psi) {
  980. psi->Set(id, status);
  981. previous_was_weak = psi->Weak;
  982. }
  983. }
  984. cmPolicies::PolicyStatus cmState::Snapshot::GetPolicy(
  985. cmPolicies::PolicyID id) const
  986. {
  987. cmPolicies::PolicyStatus status = cmPolicies::GetPolicyStatus(id);
  988. if (status == cmPolicies::REQUIRED_ALWAYS ||
  989. status == cmPolicies::REQUIRED_IF_USED) {
  990. return status;
  991. }
  992. cmLinkedTree<BuildsystemDirectoryStateType>::iterator dir =
  993. this->Position->BuildSystemDirectory;
  994. while (true) {
  995. assert(dir.IsValid());
  996. cmLinkedTree<PolicyStackEntry>::iterator leaf =
  997. dir->DirectoryEnd->Policies;
  998. cmLinkedTree<PolicyStackEntry>::iterator root =
  999. dir->DirectoryEnd->PolicyRoot;
  1000. for (; leaf != root; ++leaf) {
  1001. if (leaf->IsDefined(id)) {
  1002. status = leaf->Get(id);
  1003. return status;
  1004. }
  1005. }
  1006. cmState::PositionType e = dir->DirectoryEnd;
  1007. cmState::PositionType p = e->DirectoryParent;
  1008. if (p == this->State->SnapshotData.Root()) {
  1009. break;
  1010. }
  1011. dir = p->BuildSystemDirectory;
  1012. }
  1013. return status;
  1014. }
  1015. bool cmState::Snapshot::HasDefinedPolicyCMP0011()
  1016. {
  1017. return !this->Position->Policies->IsEmpty();
  1018. }
  1019. const char* cmState::Snapshot::GetDefinition(std::string const& name) const
  1020. {
  1021. assert(this->Position->Vars.IsValid());
  1022. return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
  1023. }
  1024. bool cmState::Snapshot::IsInitialized(std::string const& name) const
  1025. {
  1026. return cmDefinitions::HasKey(name, this->Position->Vars,
  1027. this->Position->Root);
  1028. }
  1029. void cmState::Snapshot::SetDefinition(std::string const& name,
  1030. std::string const& value)
  1031. {
  1032. this->Position->Vars->Set(name, value.c_str());
  1033. }
  1034. void cmState::Snapshot::RemoveDefinition(std::string const& name)
  1035. {
  1036. this->Position->Vars->Set(name, 0);
  1037. }
  1038. std::vector<std::string> cmState::Snapshot::UnusedKeys() const
  1039. {
  1040. return this->Position->Vars->UnusedKeys();
  1041. }
  1042. std::vector<std::string> cmState::Snapshot::ClosureKeys() const
  1043. {
  1044. return cmDefinitions::ClosureKeys(this->Position->Vars,
  1045. this->Position->Root);
  1046. }
  1047. bool cmState::Snapshot::RaiseScope(std::string const& var, const char* varDef)
  1048. {
  1049. if (this->Position->ScopeParent == this->Position->DirectoryParent) {
  1050. Snapshot parentDir = this->GetBuildsystemDirectoryParent();
  1051. if (!parentDir.IsValid()) {
  1052. return false;
  1053. }
  1054. // Update the definition in the parent directory top scope. This
  1055. // directory's scope was initialized by the closure of the parent
  1056. // scope, so we do not need to localize the definition first.
  1057. if (varDef) {
  1058. parentDir.SetDefinition(var, varDef);
  1059. } else {
  1060. parentDir.RemoveDefinition(var);
  1061. }
  1062. return true;
  1063. }
  1064. // First localize the definition in the current scope.
  1065. cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root);
  1066. // Now update the definition in the parent scope.
  1067. this->Position->Parent->Set(var, varDef);
  1068. return true;
  1069. }
  1070. static const std::string cmPropertySentinal = std::string();
  1071. template <typename T, typename U, typename V>
  1072. void InitializeContentFromParent(T& parentContent, T& thisContent,
  1073. U& parentBacktraces, U& thisBacktraces,
  1074. V& contentEndPosition)
  1075. {
  1076. std::vector<std::string>::const_iterator parentBegin = parentContent.begin();
  1077. std::vector<std::string>::const_iterator parentEnd = parentContent.end();
  1078. std::vector<std::string>::const_reverse_iterator parentRbegin =
  1079. cmMakeReverseIterator(parentEnd);
  1080. std::vector<std::string>::const_reverse_iterator parentRend =
  1081. parentContent.rend();
  1082. parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal);
  1083. std::vector<std::string>::const_iterator parentIt = parentRbegin.base();
  1084. thisContent = std::vector<std::string>(parentIt, parentEnd);
  1085. std::vector<cmListFileBacktrace>::const_iterator btIt =
  1086. parentBacktraces.begin() + std::distance(parentBegin, parentIt);
  1087. std::vector<cmListFileBacktrace>::const_iterator btEnd =
  1088. parentBacktraces.end();
  1089. thisBacktraces = std::vector<cmListFileBacktrace>(btIt, btEnd);
  1090. contentEndPosition = thisContent.size();
  1091. }
  1092. void cmState::Snapshot::SetDefaultDefinitions()
  1093. {
  1094. /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
  1095. With CMake must separate between target and host platform. In most cases
  1096. the tests for WIN32, UNIX and APPLE will be for the target system, so an
  1097. additional set of variables for the host system is required ->
  1098. CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
  1099. WIN32, UNIX and APPLE are now set in the platform files in
  1100. Modules/Platforms/.
  1101. To keep cmake scripts (-P) and custom language and compiler modules
  1102. working, these variables are still also set here in this place, but they
  1103. will be reset in CMakeSystemSpecificInformation.cmake before the platform
  1104. files are executed. */
  1105. #if defined(_WIN32)
  1106. this->SetDefinition("WIN32", "1");
  1107. this->SetDefinition("CMAKE_HOST_WIN32", "1");
  1108. #else
  1109. this->SetDefinition("UNIX", "1");
  1110. this->SetDefinition("CMAKE_HOST_UNIX", "1");
  1111. #endif
  1112. #if defined(__CYGWIN__)
  1113. if (cmSystemTools::IsOn(
  1114. cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32"))) {
  1115. this->SetDefinition("WIN32", "1");
  1116. this->SetDefinition("CMAKE_HOST_WIN32", "1");
  1117. }
  1118. #endif
  1119. #if defined(__APPLE__)
  1120. this->SetDefinition("APPLE", "1");
  1121. this->SetDefinition("CMAKE_HOST_APPLE", "1");
  1122. #endif
  1123. #if defined(__sun__)
  1124. this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
  1125. #endif
  1126. char temp[1024];
  1127. sprintf(temp, "%d", cmVersion::GetMinorVersion());
  1128. this->SetDefinition("CMAKE_MINOR_VERSION", temp);
  1129. sprintf(temp, "%d", cmVersion::GetMajorVersion());
  1130. this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
  1131. sprintf(temp, "%d", cmVersion::GetPatchVersion());
  1132. this->SetDefinition("CMAKE_PATCH_VERSION", temp);
  1133. sprintf(temp, "%d", cmVersion::GetTweakVersion());
  1134. this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
  1135. this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
  1136. this->SetDefinition("CMAKE_FILES_DIRECTORY",
  1137. cmake::GetCMakeFilesDirectory());
  1138. // Setup the default include file regular expression (match everything).
  1139. this->Position->BuildSystemDirectory->Properties.SetProperty(
  1140. "INCLUDE_REGULAR_EXPRESSION", "^.*$");
  1141. }
  1142. void cmState::Snapshot::SetDirectoryDefinitions()
  1143. {
  1144. this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
  1145. this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
  1146. this->State->GetSourceDirectory());
  1147. this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
  1148. this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
  1149. this->State->GetBinaryDirectory());
  1150. }
  1151. void cmState::Snapshot::InitializeFromParent()
  1152. {
  1153. PositionType parent = this->Position->DirectoryParent;
  1154. assert(this->Position->Vars.IsValid());
  1155. assert(parent->Vars.IsValid());
  1156. *this->Position->Vars =
  1157. cmDefinitions::MakeClosure(parent->Vars, parent->Root);
  1158. InitializeContentFromParent(
  1159. parent->BuildSystemDirectory->IncludeDirectories,
  1160. this->Position->BuildSystemDirectory->IncludeDirectories,
  1161. parent->BuildSystemDirectory->IncludeDirectoryBacktraces,
  1162. this->Position->BuildSystemDirectory->IncludeDirectoryBacktraces,
  1163. this->Position->IncludeDirectoryPosition);
  1164. InitializeContentFromParent(
  1165. parent->BuildSystemDirectory->CompileDefinitions,
  1166. this->Position->BuildSystemDirectory->CompileDefinitions,
  1167. parent->BuildSystemDirectory->CompileDefinitionsBacktraces,
  1168. this->Position->BuildSystemDirectory->CompileDefinitionsBacktraces,
  1169. this->Position->CompileDefinitionsPosition);
  1170. InitializeContentFromParent(
  1171. parent->BuildSystemDirectory->CompileOptions,
  1172. this->Position->BuildSystemDirectory->CompileOptions,
  1173. parent->BuildSystemDirectory->CompileOptionsBacktraces,
  1174. this->Position->BuildSystemDirectory->CompileOptionsBacktraces,
  1175. this->Position->CompileOptionsPosition);
  1176. }
  1177. cmState* cmState::Snapshot::GetState() const
  1178. {
  1179. return this->State;
  1180. }
  1181. cmState::Directory cmState::Snapshot::GetDirectory() const
  1182. {
  1183. return Directory(this->Position->BuildSystemDirectory, *this);
  1184. }
  1185. void cmState::Snapshot::SetProjectName(const std::string& name)
  1186. {
  1187. this->Position->BuildSystemDirectory->ProjectName = name;
  1188. }
  1189. std::string cmState::Snapshot::GetProjectName() const
  1190. {
  1191. return this->Position->BuildSystemDirectory->ProjectName;
  1192. }
  1193. void cmState::Snapshot::InitializeFromParent_ForSubdirsCommand()
  1194. {
  1195. std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
  1196. std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
  1197. this->InitializeFromParent();
  1198. this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
  1199. this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
  1200. this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir);
  1201. this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir);
  1202. }
  1203. cmState::Directory::Directory(
  1204. cmLinkedTree<BuildsystemDirectoryStateType>::iterator iter,
  1205. const cmState::Snapshot& snapshot)
  1206. : DirectoryState(iter)
  1207. , Snapshot_(snapshot)
  1208. {
  1209. }
  1210. template <typename T, typename U>
  1211. cmStringRange GetPropertyContent(T const& content, U contentEndPosition)
  1212. {
  1213. std::vector<std::string>::const_iterator end =
  1214. content.begin() + contentEndPosition;
  1215. std::vector<std::string>::const_reverse_iterator rbegin =
  1216. cmMakeReverseIterator(end);
  1217. rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
  1218. return cmMakeRange(rbegin.base(), end);
  1219. }
  1220. template <typename T, typename U, typename V>
  1221. cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces,
  1222. V contentEndPosition)
  1223. {
  1224. std::vector<std::string>::const_iterator entryEnd =
  1225. content.begin() + contentEndPosition;
  1226. std::vector<std::string>::const_reverse_iterator rbegin =
  1227. cmMakeReverseIterator(entryEnd);
  1228. rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
  1229. std::vector<cmListFileBacktrace>::const_iterator it =
  1230. backtraces.begin() + std::distance(content.begin(), rbegin.base());
  1231. std::vector<cmListFileBacktrace>::const_iterator end = backtraces.end();
  1232. return cmMakeRange(it, end);
  1233. }
  1234. template <typename T, typename U, typename V>
  1235. void AppendEntry(T& content, U& backtraces, V& endContentPosition,
  1236. const std::string& value, const cmListFileBacktrace& lfbt)
  1237. {
  1238. if (value.empty()) {
  1239. return;
  1240. }
  1241. assert(endContentPosition == content.size());
  1242. content.push_back(value);
  1243. backtraces.push_back(lfbt);
  1244. endContentPosition = content.size();
  1245. }
  1246. template <typename T, typename U, typename V>
  1247. void SetContent(T& content, U& backtraces, V& endContentPosition,
  1248. const std::string& vec, const cmListFileBacktrace& lfbt)
  1249. {
  1250. assert(endContentPosition == content.size());
  1251. content.resize(content.size() + 2);
  1252. backtraces.resize(backtraces.size() + 2);
  1253. content.back() = vec;
  1254. backtraces.back() = lfbt;
  1255. endContentPosition = content.size();
  1256. }
  1257. template <typename T, typename U, typename V>
  1258. void ClearContent(T& content, U& backtraces, V& endContentPosition)
  1259. {
  1260. assert(endContentPosition == content.size());
  1261. content.resize(content.size() + 1);
  1262. backtraces.resize(backtraces.size() + 1);
  1263. endContentPosition = content.size();
  1264. }
  1265. cmStringRange cmState::Directory::GetIncludeDirectoriesEntries() const
  1266. {
  1267. return GetPropertyContent(
  1268. this->DirectoryState->IncludeDirectories,
  1269. this->Snapshot_.Position->IncludeDirectoryPosition);
  1270. }
  1271. cmBacktraceRange cmState::Directory::GetIncludeDirectoriesEntryBacktraces()
  1272. const
  1273. {
  1274. return GetPropertyBacktraces(
  1275. this->DirectoryState->IncludeDirectories,
  1276. this->DirectoryState->IncludeDirectoryBacktraces,
  1277. this->Snapshot_.Position->IncludeDirectoryPosition);
  1278. }
  1279. void cmState::Directory::AppendIncludeDirectoriesEntry(
  1280. const std::string& vec, const cmListFileBacktrace& lfbt)
  1281. {
  1282. AppendEntry(this->DirectoryState->IncludeDirectories,
  1283. this->DirectoryState->IncludeDirectoryBacktraces,
  1284. this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
  1285. }
  1286. void cmState::Directory::PrependIncludeDirectoriesEntry(
  1287. const std::string& vec, const cmListFileBacktrace& lfbt)
  1288. {
  1289. std::vector<std::string>::iterator entryEnd =
  1290. this->DirectoryState->IncludeDirectories.begin() +
  1291. this->Snapshot_.Position->IncludeDirectoryPosition;
  1292. std::vector<std::string>::reverse_iterator rend =
  1293. this->DirectoryState->IncludeDirectories.rend();
  1294. std::vector<std::string>::reverse_iterator rbegin =
  1295. cmMakeReverseIterator(entryEnd);
  1296. rbegin = std::find(rbegin, rend, cmPropertySentinal);
  1297. std::vector<std::string>::iterator entryIt = rbegin.base();
  1298. std::vector<std::string>::iterator entryBegin =
  1299. this->DirectoryState->IncludeDirectories.begin();
  1300. std::vector<cmListFileBacktrace>::iterator btIt =
  1301. this->DirectoryState->IncludeDirectoryBacktraces.begin() +
  1302. std::distance(entryBegin, entryIt);
  1303. this->DirectoryState->IncludeDirectories.insert(entryIt, vec);
  1304. this->DirectoryState->IncludeDirectoryBacktraces.insert(btIt, lfbt);
  1305. this->Snapshot_.Position->IncludeDirectoryPosition =
  1306. this->DirectoryState->IncludeDirectories.size();
  1307. }
  1308. void cmState::Directory::SetIncludeDirectories(const std::string& vec,
  1309. const cmListFileBacktrace& lfbt)
  1310. {
  1311. SetContent(this->DirectoryState->IncludeDirectories,
  1312. this->DirectoryState->IncludeDirectoryBacktraces,
  1313. this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
  1314. }
  1315. void cmState::Directory::ClearIncludeDirectories()
  1316. {
  1317. ClearContent(this->DirectoryState->IncludeDirectories,
  1318. this->DirectoryState->IncludeDirectoryBacktraces,
  1319. this->Snapshot_.Position->IncludeDirectoryPosition);
  1320. }
  1321. cmStringRange cmState::Directory::GetCompileDefinitionsEntries() const
  1322. {
  1323. return GetPropertyContent(
  1324. this->DirectoryState->CompileDefinitions,
  1325. this->Snapshot_.Position->CompileDefinitionsPosition);
  1326. }
  1327. cmBacktraceRange cmState::Directory::GetCompileDefinitionsEntryBacktraces()
  1328. const
  1329. {
  1330. return GetPropertyBacktraces(
  1331. this->DirectoryState->CompileDefinitions,
  1332. this->DirectoryState->CompileDefinitionsBacktraces,
  1333. this->Snapshot_.Position->CompileDefinitionsPosition);
  1334. }
  1335. void cmState::Directory::AppendCompileDefinitionsEntry(
  1336. const std::string& vec, const cmListFileBacktrace& lfbt)
  1337. {
  1338. AppendEntry(this->DirectoryState->CompileDefinitions,
  1339. this->DirectoryState->CompileDefinitionsBacktraces,
  1340. this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
  1341. }
  1342. void cmState::Directory::SetCompileDefinitions(const std::string& vec,
  1343. const cmListFileBacktrace& lfbt)
  1344. {
  1345. SetContent(this->DirectoryState->CompileDefinitions,
  1346. this->DirectoryState->CompileDefinitionsBacktraces,
  1347. this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
  1348. }
  1349. void cmState::Directory::ClearCompileDefinitions()
  1350. {
  1351. ClearContent(this->DirectoryState->CompileDefinitions,
  1352. this->DirectoryState->CompileDefinitionsBacktraces,
  1353. this->Snapshot_.Position->CompileDefinitionsPosition);
  1354. }
  1355. cmStringRange cmState::Directory::GetCompileOptionsEntries() const
  1356. {
  1357. return GetPropertyContent(this->DirectoryState->CompileOptions,
  1358. this->Snapshot_.Position->CompileOptionsPosition);
  1359. }
  1360. cmBacktraceRange cmState::Directory::GetCompileOptionsEntryBacktraces() const
  1361. {
  1362. return GetPropertyBacktraces(
  1363. this->DirectoryState->CompileOptions,
  1364. this->DirectoryState->CompileOptionsBacktraces,
  1365. this->Snapshot_.Position->CompileOptionsPosition);
  1366. }
  1367. void cmState::Directory::AppendCompileOptionsEntry(
  1368. const std::string& vec, const cmListFileBacktrace& lfbt)
  1369. {
  1370. AppendEntry(this->DirectoryState->CompileOptions,
  1371. this->DirectoryState->CompileOptionsBacktraces,
  1372. this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt);
  1373. }
  1374. void cmState::Directory::SetCompileOptions(const std::string& vec,
  1375. const cmListFileBacktrace& lfbt)
  1376. {
  1377. SetContent(this->DirectoryState->CompileOptions,
  1378. this->DirectoryState->CompileOptionsBacktraces,
  1379. this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt);
  1380. }
  1381. void cmState::Directory::ClearCompileOptions()
  1382. {
  1383. ClearContent(this->DirectoryState->CompileOptions,
  1384. this->DirectoryState->CompileOptionsBacktraces,
  1385. this->Snapshot_.Position->CompileOptionsPosition);
  1386. }
  1387. bool cmState::Snapshot::StrictWeakOrder::operator()(
  1388. const cmState::Snapshot& lhs, const cmState::Snapshot& rhs) const
  1389. {
  1390. return lhs.Position.StrictWeakOrdered(rhs.Position);
  1391. }
  1392. void cmState::Directory::SetProperty(const std::string& prop,
  1393. const char* value,
  1394. cmListFileBacktrace lfbt)
  1395. {
  1396. if (prop == "INCLUDE_DIRECTORIES") {
  1397. if (!value) {
  1398. this->ClearIncludeDirectories();
  1399. return;
  1400. }
  1401. this->SetIncludeDirectories(value, lfbt);
  1402. return;
  1403. }
  1404. if (prop == "COMPILE_OPTIONS") {
  1405. if (!value) {
  1406. this->ClearCompileOptions();
  1407. return;
  1408. }
  1409. this->SetCompileOptions(value, lfbt);
  1410. return;
  1411. }
  1412. if (prop == "COMPILE_DEFINITIONS") {
  1413. if (!value) {
  1414. this->ClearCompileDefinitions();
  1415. return;
  1416. }
  1417. this->SetCompileDefinitions(value, lfbt);
  1418. return;
  1419. }
  1420. this->DirectoryState->Properties.SetProperty(prop, value);
  1421. }
  1422. void cmState::Directory::AppendProperty(const std::string& prop,
  1423. const char* value, bool asString,
  1424. cmListFileBacktrace lfbt)
  1425. {
  1426. if (prop == "INCLUDE_DIRECTORIES") {
  1427. this->AppendIncludeDirectoriesEntry(value, lfbt);
  1428. return;
  1429. }
  1430. if (prop == "COMPILE_OPTIONS") {
  1431. this->AppendCompileOptionsEntry(value, lfbt);
  1432. return;
  1433. }
  1434. if (prop == "COMPILE_DEFINITIONS") {
  1435. this->AppendCompileDefinitionsEntry(value, lfbt);
  1436. return;
  1437. }
  1438. this->DirectoryState->Properties.AppendProperty(prop, value, asString);
  1439. }
  1440. const char* cmState::Directory::GetProperty(const std::string& prop) const
  1441. {
  1442. const bool chain =
  1443. this->Snapshot_.State->IsPropertyChained(prop, cmProperty::DIRECTORY);
  1444. return this->GetProperty(prop, chain);
  1445. }
  1446. const char* cmState::Directory::GetProperty(const std::string& prop,
  1447. bool chain) const
  1448. {
  1449. static std::string output;
  1450. output = "";
  1451. if (prop == "PARENT_DIRECTORY") {
  1452. cmState::Snapshot parent = this->Snapshot_.GetBuildsystemDirectoryParent();
  1453. if (parent.IsValid()) {
  1454. return parent.GetDirectory().GetCurrentSource();
  1455. }
  1456. return "";
  1457. } else if (prop == "LISTFILE_STACK") {
  1458. std::vector<std::string> listFiles;
  1459. cmState::Snapshot snp = this->Snapshot_;
  1460. while (snp.IsValid()) {
  1461. listFiles.push_back(snp.GetExecutionListFile());
  1462. snp = snp.GetCallStackParent();
  1463. }
  1464. std::reverse(listFiles.begin(), listFiles.end());
  1465. output = cmJoin(listFiles, ";");
  1466. return output.c_str();
  1467. } else if (prop == "CACHE_VARIABLES") {
  1468. output = cmJoin(this->Snapshot_.State->GetCacheEntryKeys(), ";");
  1469. return output.c_str();
  1470. } else if (prop == "VARIABLES") {
  1471. std::vector<std::string> res = this->Snapshot_.ClosureKeys();
  1472. std::vector<std::string> cacheKeys =
  1473. this->Snapshot_.State->GetCacheEntryKeys();
  1474. res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
  1475. std::sort(res.begin(), res.end());
  1476. output = cmJoin(res, ";");
  1477. return output.c_str();
  1478. } else if (prop == "INCLUDE_DIRECTORIES") {
  1479. output = cmJoin(this->GetIncludeDirectoriesEntries(), ";");
  1480. return output.c_str();
  1481. } else if (prop == "COMPILE_OPTIONS") {
  1482. output = cmJoin(this->GetCompileOptionsEntries(), ";");
  1483. return output.c_str();
  1484. } else if (prop == "COMPILE_DEFINITIONS") {
  1485. output = cmJoin(this->GetCompileDefinitionsEntries(), ";");
  1486. return output.c_str();
  1487. }
  1488. const char* retVal = this->DirectoryState->Properties.GetPropertyValue(prop);
  1489. if (!retVal && chain) {
  1490. Snapshot parentSnapshot = this->Snapshot_.GetBuildsystemDirectoryParent();
  1491. if (parentSnapshot.IsValid()) {
  1492. return parentSnapshot.GetDirectory().GetProperty(prop, chain);
  1493. }
  1494. return this->Snapshot_.State->GetGlobalProperty(prop);
  1495. }
  1496. return retVal;
  1497. }
  1498. bool cmState::Directory::GetPropertyAsBool(const std::string& prop) const
  1499. {
  1500. return cmSystemTools::IsOn(this->GetProperty(prop));
  1501. }
  1502. std::vector<std::string> cmState::Directory::GetPropertyKeys() const
  1503. {
  1504. std::vector<std::string> keys;
  1505. keys.reserve(this->DirectoryState->Properties.size());
  1506. for (cmPropertyMap::const_iterator it =
  1507. this->DirectoryState->Properties.begin();
  1508. it != this->DirectoryState->Properties.end(); ++it) {
  1509. keys.push_back(it->first);
  1510. }
  1511. return keys;
  1512. }
  1513. bool operator==(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
  1514. {
  1515. return lhs.Position == rhs.Position;
  1516. }
  1517. bool operator!=(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
  1518. {
  1519. return lhs.Position != rhs.Position;
  1520. }
  1521. static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
  1522. std::string& value)
  1523. {
  1524. // input line is: key=value
  1525. static cmsys::RegularExpression reg(
  1526. "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1527. // input line is: "key"=value
  1528. static cmsys::RegularExpression regQuoted(
  1529. "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1530. bool flag = false;
  1531. if (regQuoted.find(entry)) {
  1532. var = regQuoted.match(1);
  1533. value = regQuoted.match(2);
  1534. flag = true;
  1535. } else if (reg.find(entry)) {
  1536. var = reg.match(1);
  1537. value = reg.match(2);
  1538. flag = true;
  1539. }
  1540. // if value is enclosed in single quotes ('foo') then remove them
  1541. // it is used to enclose trailing space or tab
  1542. if (flag && value.size() >= 2 && value[0] == '\'' &&
  1543. value[value.size() - 1] == '\'') {
  1544. value = value.substr(1, value.size() - 2);
  1545. }
  1546. return flag;
  1547. }
  1548. bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
  1549. std::string& value, CacheEntryType& type)
  1550. {
  1551. // input line is: key:type=value
  1552. static cmsys::RegularExpression reg(
  1553. "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1554. // input line is: "key":type=value
  1555. static cmsys::RegularExpression regQuoted(
  1556. "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1557. bool flag = false;
  1558. if (regQuoted.find(entry)) {
  1559. var = regQuoted.match(1);
  1560. type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
  1561. value = regQuoted.match(3);
  1562. flag = true;
  1563. } else if (reg.find(entry)) {
  1564. var = reg.match(1);
  1565. type = cmState::StringToCacheEntryType(reg.match(2).c_str());
  1566. value = reg.match(3);
  1567. flag = true;
  1568. }
  1569. // if value is enclosed in single quotes ('foo') then remove them
  1570. // it is used to enclose trailing space or tab
  1571. if (flag && value.size() >= 2 && value[0] == '\'' &&
  1572. value[value.size() - 1] == '\'') {
  1573. value = value.substr(1, value.size() - 2);
  1574. }
  1575. if (!flag) {
  1576. return ParseEntryWithoutType(entry, var, value);
  1577. }
  1578. return flag;
  1579. }