cmState.cxx 56 KB

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