cmState.cxx 43 KB

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