cmState.cxx 59 KB

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