cmState.cxx 51 KB

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