cmState.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. cmState::cmState(cmake* cm)
  17. : CMakeInstance(cm),
  18. IsInTryCompile(false),
  19. WindowsShell(false),
  20. WindowsVSIDE(false),
  21. WatcomWMake(false),
  22. MinGWMake(false),
  23. NMake(false),
  24. MSYSShell(false)
  25. {
  26. }
  27. cmState::~cmState()
  28. {
  29. cmDeleteAll(this->Commands);
  30. }
  31. const char* cmCacheEntryTypes[] =
  32. { "BOOL",
  33. "PATH",
  34. "FILEPATH",
  35. "STRING",
  36. "INTERNAL",
  37. "STATIC",
  38. "UNINITIALIZED",
  39. 0
  40. };
  41. const char*
  42. cmState::CacheEntryTypeToString(cmState::CacheEntryType type)
  43. {
  44. if ( type > 6 )
  45. {
  46. return cmCacheEntryTypes[6];
  47. }
  48. return cmCacheEntryTypes[type];
  49. }
  50. cmState::CacheEntryType
  51. cmState::StringToCacheEntryType(const char* s)
  52. {
  53. int i = 0;
  54. while(cmCacheEntryTypes[i])
  55. {
  56. if(strcmp(s, cmCacheEntryTypes[i]) == 0)
  57. {
  58. return static_cast<cmState::CacheEntryType>(i);
  59. }
  60. ++i;
  61. }
  62. return STRING;
  63. }
  64. bool cmState::IsCacheEntryType(std::string const& key)
  65. {
  66. for(int i=0; cmCacheEntryTypes[i]; ++i)
  67. {
  68. if(strcmp(key.c_str(), cmCacheEntryTypes[i]) == 0)
  69. {
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. std::vector<std::string> cmState::GetCacheEntryKeys() const
  76. {
  77. std::vector<std::string> definitions;
  78. definitions.reserve(this->CMakeInstance->GetCacheManager()->GetSize());
  79. cmCacheManager::CacheIterator cit =
  80. this->CMakeInstance->GetCacheManager()->GetCacheIterator();
  81. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  82. {
  83. definitions.push_back(cit.GetName());
  84. }
  85. return definitions;
  86. }
  87. const char* cmState::GetCacheEntryValue(std::string const& key) const
  88. {
  89. cmCacheManager::CacheEntry* e = this->CMakeInstance->GetCacheManager()
  90. ->GetCacheEntry(key);
  91. if (!e)
  92. {
  93. return 0;
  94. }
  95. return e->Value.c_str();
  96. }
  97. const char*
  98. cmState::GetInitializedCacheValue(std::string const& key) const
  99. {
  100. return this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue(key);
  101. }
  102. cmState::CacheEntryType
  103. cmState::GetCacheEntryType(std::string const& key) const
  104. {
  105. cmCacheManager::CacheIterator it =
  106. this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  107. return it.GetType();
  108. }
  109. void cmState::SetCacheEntryValue(std::string const& key,
  110. std::string const& value)
  111. {
  112. this->CMakeInstance->GetCacheManager()->SetCacheEntryValue(key, value);
  113. }
  114. void cmState::SetCacheEntryProperty(std::string const& key,
  115. std::string const& propertyName,
  116. std::string const& value)
  117. {
  118. cmCacheManager::CacheIterator it =
  119. this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  120. it.SetProperty(propertyName, value.c_str());
  121. }
  122. void cmState::SetCacheEntryBoolProperty(std::string const& key,
  123. std::string const& propertyName,
  124. bool value)
  125. {
  126. cmCacheManager::CacheIterator it =
  127. this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  128. it.SetProperty(propertyName, value);
  129. }
  130. const char* cmState::GetCacheEntryProperty(std::string const& key,
  131. std::string const& propertyName)
  132. {
  133. cmCacheManager::CacheIterator it = this->CMakeInstance->GetCacheManager()
  134. ->GetCacheIterator(key.c_str());
  135. if (!it.PropertyExists(propertyName))
  136. {
  137. return 0;
  138. }
  139. return it.GetProperty(propertyName);
  140. }
  141. bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
  142. std::string const& propertyName)
  143. {
  144. return this->CMakeInstance->GetCacheManager()
  145. ->GetCacheIterator(key.c_str()).GetPropertyAsBool(propertyName);
  146. }
  147. void cmState::AddCacheEntry(const std::string& key, const char* value,
  148. const char* helpString,
  149. cmState::CacheEntryType type)
  150. {
  151. this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
  152. helpString, type);
  153. }
  154. void cmState::RemoveCacheEntry(std::string const& key)
  155. {
  156. this->CMakeInstance->GetCacheManager()->RemoveCacheEntry(key);
  157. }
  158. void cmState::AppendCacheEntryProperty(const std::string& key,
  159. const std::string& property,
  160. const std::string& value,
  161. bool asString)
  162. {
  163. this->CMakeInstance->GetCacheManager()
  164. ->GetCacheIterator(key.c_str()).AppendProperty(property,
  165. value.c_str(),
  166. asString);
  167. }
  168. void cmState::RemoveCacheEntryProperty(std::string const& key,
  169. std::string const& propertyName)
  170. {
  171. this->CMakeInstance->GetCacheManager()
  172. ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
  173. }
  174. void cmState::Reset()
  175. {
  176. this->GlobalProperties.clear();
  177. this->PropertyDefinitions.clear();
  178. assert(this->Locations.size() > 0);
  179. assert(this->OutputLocations.size() > 0);
  180. assert(this->ParentPositions.size() > 0);
  181. assert(this->CurrentSourceDirectoryComponents.size() > 0);
  182. assert(this->CurrentBinaryDirectoryComponents.size() > 0);
  183. assert(this->RelativePathTopSource.size() > 0);
  184. assert(this->RelativePathTopBinary.size() > 0);
  185. this->Locations.erase(this->Locations.begin() + 1, this->Locations.end());
  186. this->OutputLocations.erase(this->OutputLocations.begin() + 1,
  187. this->OutputLocations.end());
  188. this->ParentPositions.erase(this->ParentPositions.begin() + 1,
  189. this->ParentPositions.end());
  190. this->CurrentSourceDirectoryComponents.erase(
  191. this->CurrentSourceDirectoryComponents.begin() + 1,
  192. this->CurrentSourceDirectoryComponents.end());
  193. this->CurrentBinaryDirectoryComponents.erase(
  194. this->CurrentBinaryDirectoryComponents.begin() + 1,
  195. this->CurrentBinaryDirectoryComponents.end());
  196. this->RelativePathTopSource.erase(this->RelativePathTopSource.begin() + 1,
  197. this->RelativePathTopSource.end());
  198. this->RelativePathTopBinary.erase(this->RelativePathTopBinary.begin() + 1,
  199. this->RelativePathTopBinary.end());
  200. this->DefineProperty
  201. ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
  202. "", "", true);
  203. this->DefineProperty
  204. ("RULE_LAUNCH_LINK", cmProperty::DIRECTORY,
  205. "", "", true);
  206. this->DefineProperty
  207. ("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY,
  208. "", "", true);
  209. this->DefineProperty
  210. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  211. "", "", true);
  212. this->DefineProperty
  213. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  214. "", "", true);
  215. this->DefineProperty
  216. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  217. "", "", true);
  218. }
  219. void cmState::DefineProperty(const std::string& name,
  220. cmProperty::ScopeType scope,
  221. const char *ShortDescription,
  222. const char *FullDescription,
  223. bool chained)
  224. {
  225. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  226. FullDescription,
  227. chained);
  228. }
  229. cmPropertyDefinition *cmState
  230. ::GetPropertyDefinition(const std::string& name,
  231. cmProperty::ScopeType scope)
  232. {
  233. if (this->IsPropertyDefined(name,scope))
  234. {
  235. return &(this->PropertyDefinitions[scope][name]);
  236. }
  237. return 0;
  238. }
  239. bool cmState::IsPropertyDefined(const std::string& name,
  240. cmProperty::ScopeType scope)
  241. {
  242. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  243. }
  244. bool cmState::IsPropertyChained(const std::string& name,
  245. cmProperty::ScopeType scope)
  246. {
  247. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  248. }
  249. void cmState::SetLanguageEnabled(std::string const& l)
  250. {
  251. std::vector<std::string>::iterator it =
  252. std::lower_bound(this->EnabledLanguages.begin(),
  253. this->EnabledLanguages.end(), l);
  254. if (it == this->EnabledLanguages.end() || *it != l)
  255. {
  256. this->EnabledLanguages.insert(it, l);
  257. }
  258. }
  259. bool cmState::GetLanguageEnabled(std::string const& l) const
  260. {
  261. return std::binary_search(this->EnabledLanguages.begin(),
  262. this->EnabledLanguages.end(), l);
  263. }
  264. std::vector<std::string> cmState::GetEnabledLanguages() const
  265. {
  266. return this->EnabledLanguages;
  267. }
  268. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  269. {
  270. this->EnabledLanguages = langs;
  271. }
  272. void cmState::ClearEnabledLanguages()
  273. {
  274. this->EnabledLanguages.clear();
  275. }
  276. bool cmState::GetIsInTryCompile() const
  277. {
  278. return this->IsInTryCompile;
  279. }
  280. void cmState::SetIsInTryCompile(bool b)
  281. {
  282. this->IsInTryCompile = b;
  283. }
  284. void cmState::RenameCommand(std::string const& oldName,
  285. std::string const& newName)
  286. {
  287. // if the command already exists, free the old one
  288. std::string sOldName = cmSystemTools::LowerCase(oldName);
  289. std::string sNewName = cmSystemTools::LowerCase(newName);
  290. std::map<std::string, cmCommand*>::iterator pos =
  291. this->Commands.find(sOldName);
  292. if ( pos == this->Commands.end() )
  293. {
  294. return;
  295. }
  296. cmCommand* cmd = pos->second;
  297. pos = this->Commands.find(sNewName);
  298. if (pos != this->Commands.end())
  299. {
  300. delete pos->second;
  301. this->Commands.erase(pos);
  302. }
  303. this->Commands.insert(std::make_pair(sNewName, cmd));
  304. pos = this->Commands.find(sOldName);
  305. this->Commands.erase(pos);
  306. }
  307. void cmState::AddCommand(cmCommand* command)
  308. {
  309. std::string name = cmSystemTools::LowerCase(command->GetName());
  310. // if the command already exists, free the old one
  311. std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name);
  312. if (pos != this->Commands.end())
  313. {
  314. delete pos->second;
  315. this->Commands.erase(pos);
  316. }
  317. this->Commands.insert(std::make_pair(name, command));
  318. }
  319. void cmState::RemoveUnscriptableCommands()
  320. {
  321. std::vector<std::string> unscriptableCommands;
  322. for (std::map<std::string, cmCommand*>::iterator
  323. pos = this->Commands.begin();
  324. pos != this->Commands.end(); )
  325. {
  326. if (!pos->second->IsScriptable())
  327. {
  328. delete pos->second;
  329. this->Commands.erase(pos++);
  330. }
  331. else
  332. {
  333. ++pos;
  334. }
  335. }
  336. }
  337. cmCommand* cmState::GetCommand(std::string const& name) const
  338. {
  339. cmCommand* command = 0;
  340. std::string sName = cmSystemTools::LowerCase(name);
  341. std::map<std::string, cmCommand*>::const_iterator pos =
  342. this->Commands.find(sName);
  343. if (pos != this->Commands.end())
  344. {
  345. command = (*pos).second;
  346. }
  347. return command;
  348. }
  349. std::vector<std::string> cmState::GetCommandNames() const
  350. {
  351. std::vector<std::string> commandNames;
  352. commandNames.reserve(this->Commands.size());
  353. std::map<std::string, cmCommand*>::const_iterator cmds
  354. = this->Commands.begin();
  355. for ( ; cmds != this->Commands.end(); ++ cmds )
  356. {
  357. commandNames.push_back(cmds->first);
  358. }
  359. return commandNames;
  360. }
  361. void cmState::RemoveUserDefinedCommands()
  362. {
  363. for(std::map<std::string, cmCommand*>::iterator j = this->Commands.begin();
  364. j != this->Commands.end(); )
  365. {
  366. if (j->second->IsA("cmMacroHelperCommand") ||
  367. j->second->IsA("cmFunctionHelperCommand"))
  368. {
  369. delete j->second;
  370. this->Commands.erase(j++);
  371. }
  372. else
  373. {
  374. ++j;
  375. }
  376. }
  377. }
  378. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  379. {
  380. this->GlobalProperties.SetProperty(prop, value, cmProperty::GLOBAL);
  381. }
  382. void cmState::AppendGlobalProperty(const std::string& prop,
  383. const char* value, bool asString)
  384. {
  385. this->GlobalProperties.AppendProperty(prop, value,
  386. cmProperty::GLOBAL, asString);
  387. }
  388. const char *cmState::GetGlobalProperty(const std::string& prop)
  389. {
  390. // watch for special properties
  391. std::string output = "";
  392. if ( prop == "CACHE_VARIABLES" )
  393. {
  394. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  395. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  396. }
  397. else if ( prop == "COMMANDS" )
  398. {
  399. std::vector<std::string> commands = this->GetCommandNames();
  400. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  401. }
  402. else if ( prop == "IN_TRY_COMPILE" )
  403. {
  404. this->SetGlobalProperty("IN_TRY_COMPILE",
  405. this->IsInTryCompile ? "1" : "0");
  406. }
  407. else if ( prop == "ENABLED_LANGUAGES" )
  408. {
  409. std::string langs;
  410. langs = cmJoin(this->EnabledLanguages, ";");
  411. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  412. }
  413. #define STRING_LIST_ELEMENT(F) ";" #F
  414. if (prop == "CMAKE_C_KNOWN_FEATURES")
  415. {
  416. return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
  417. }
  418. if (prop == "CMAKE_CXX_KNOWN_FEATURES")
  419. {
  420. return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
  421. }
  422. #undef STRING_LIST_ELEMENT
  423. bool dummy = false;
  424. return this->GlobalProperties.GetPropertyValue(prop, cmProperty::GLOBAL,
  425. dummy);
  426. }
  427. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  428. {
  429. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  430. }
  431. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  432. {
  433. this->SourceDirectory = sourceDirectory;
  434. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  435. cmSystemTools::SplitPath(
  436. cmSystemTools::CollapseFullPath(this->SourceDirectory),
  437. this->SourceDirectoryComponents);
  438. }
  439. const char* cmState::GetSourceDirectory() const
  440. {
  441. return this->SourceDirectory.c_str();
  442. }
  443. std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
  444. {
  445. return this->SourceDirectoryComponents;
  446. }
  447. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  448. {
  449. this->BinaryDirectory = binaryDirectory;
  450. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  451. cmSystemTools::SplitPath(
  452. cmSystemTools::CollapseFullPath(this->BinaryDirectory),
  453. this->BinaryDirectoryComponents);
  454. }
  455. void cmState::SetWindowsShell(bool windowsShell)
  456. {
  457. this->WindowsShell = windowsShell;
  458. }
  459. bool cmState::UseWindowsShell() const
  460. {
  461. return this->WindowsShell;
  462. }
  463. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  464. {
  465. this->WindowsVSIDE = windowsVSIDE;
  466. }
  467. bool cmState::UseWindowsVSIDE() const
  468. {
  469. return this->WindowsVSIDE;
  470. }
  471. void cmState::SetWatcomWMake(bool watcomWMake)
  472. {
  473. this->WatcomWMake = watcomWMake;
  474. }
  475. bool cmState::UseWatcomWMake() const
  476. {
  477. return this->WatcomWMake;
  478. }
  479. void cmState::SetMinGWMake(bool minGWMake)
  480. {
  481. this->MinGWMake = minGWMake;
  482. }
  483. bool cmState::UseMinGWMake() const
  484. {
  485. return this->MinGWMake;
  486. }
  487. void cmState::SetNMake(bool nMake)
  488. {
  489. this->NMake = nMake;
  490. }
  491. bool cmState::UseNMake() const
  492. {
  493. return this->NMake;
  494. }
  495. void cmState::SetMSYSShell(bool mSYSShell)
  496. {
  497. this->MSYSShell = mSYSShell;
  498. }
  499. bool cmState::UseMSYSShell() const
  500. {
  501. return this->MSYSShell;
  502. }
  503. const char* cmState::GetBinaryDirectory() const
  504. {
  505. return this->BinaryDirectory.c_str();
  506. }
  507. std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
  508. {
  509. return this->BinaryDirectoryComponents;
  510. }
  511. void cmState::Snapshot::ComputeRelativePathTopSource()
  512. {
  513. // Relative path conversion inside the source tree is not used to
  514. // construct relative paths passed to build tools so it is safe to use
  515. // even when the source is a network path.
  516. cmState::Snapshot snapshot = *this;
  517. std::vector<cmState::Snapshot> snapshots;
  518. snapshots.push_back(snapshot);
  519. while (true)
  520. {
  521. snapshot = snapshot.GetBuildsystemDirectoryParent();
  522. if (snapshot.IsValid())
  523. {
  524. snapshots.push_back(snapshot);
  525. }
  526. else
  527. {
  528. break;
  529. }
  530. }
  531. std::string result = snapshots.front().GetCurrentSourceDirectory();
  532. for (std::vector<cmState::Snapshot>::const_iterator it =
  533. snapshots.begin() + 1; it != snapshots.end(); ++it)
  534. {
  535. std::string currentSource = it->GetCurrentSourceDirectory();
  536. if(cmSystemTools::IsSubDirectory(result, currentSource))
  537. {
  538. result = currentSource;
  539. }
  540. }
  541. this->State->RelativePathTopSource[this->Position] = result;
  542. }
  543. void cmState::Snapshot::ComputeRelativePathTopBinary()
  544. {
  545. cmState::Snapshot snapshot = *this;
  546. std::vector<cmState::Snapshot> snapshots;
  547. snapshots.push_back(snapshot);
  548. while (true)
  549. {
  550. snapshot = snapshot.GetBuildsystemDirectoryParent();
  551. if (snapshot.IsValid())
  552. {
  553. snapshots.push_back(snapshot);
  554. }
  555. else
  556. {
  557. break;
  558. }
  559. }
  560. std::string result =
  561. snapshots.front().GetCurrentBinaryDirectory();
  562. for (std::vector<cmState::Snapshot>::const_iterator it =
  563. snapshots.begin() + 1; it != snapshots.end(); ++it)
  564. {
  565. std::string currentBinary = it->GetCurrentBinaryDirectory();
  566. if(cmSystemTools::IsSubDirectory(result, currentBinary))
  567. {
  568. result = currentBinary;
  569. }
  570. }
  571. // The current working directory on Windows cannot be a network
  572. // path. Therefore relative paths cannot work when the binary tree
  573. // is a network path.
  574. if(result.size() < 2 || result.substr(0, 2) != "//")
  575. {
  576. this->State->RelativePathTopBinary[this->Position] = result;
  577. }
  578. else
  579. {
  580. this->State->RelativePathTopBinary[this->Position] = "";
  581. }
  582. }
  583. cmState::Snapshot cmState::CreateBaseSnapshot()
  584. {
  585. PositionType pos = 0;
  586. this->ParentPositions.push_back(pos);
  587. this->Locations.resize(1);
  588. this->OutputLocations.resize(1);
  589. this->CurrentSourceDirectoryComponents.resize(1);
  590. this->CurrentBinaryDirectoryComponents.resize(1);
  591. this->RelativePathTopSource.resize(1);
  592. this->RelativePathTopBinary.resize(1);
  593. return cmState::Snapshot(this, pos);
  594. }
  595. cmState::Snapshot
  596. cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot)
  597. {
  598. assert(originSnapshot.IsValid());
  599. PositionType pos = this->ParentPositions.size();
  600. this->ParentPositions.push_back(originSnapshot.Position);
  601. this->Locations.resize(this->Locations.size() + 1);
  602. this->OutputLocations.resize(this->OutputLocations.size() + 1);
  603. this->CurrentSourceDirectoryComponents.resize(
  604. this->CurrentSourceDirectoryComponents.size() + 1);
  605. this->CurrentBinaryDirectoryComponents.resize(
  606. this->CurrentBinaryDirectoryComponents.size() + 1);
  607. this->RelativePathTopSource.resize(this->RelativePathTopSource.size() + 1);
  608. this->RelativePathTopBinary.resize(this->RelativePathTopBinary.size() + 1);
  609. return cmState::Snapshot(this, pos);
  610. }
  611. cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  612. : State(state),
  613. Position(position)
  614. {
  615. }
  616. const char* cmState::Snapshot::GetCurrentSourceDirectory() const
  617. {
  618. return this->State->Locations[this->Position].c_str();
  619. }
  620. void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir)
  621. {
  622. assert(this->State);
  623. assert(this->State->Locations.size() > this->Position);
  624. this->State->Locations[this->Position] = dir;
  625. cmSystemTools::ConvertToUnixSlashes(
  626. this->State->Locations[this->Position]);
  627. this->State->Locations[this->Position] =
  628. cmSystemTools::CollapseFullPath(this->State->Locations[this->Position]);
  629. cmSystemTools::SplitPath(
  630. this->State->Locations[this->Position],
  631. this->State->CurrentSourceDirectoryComponents[this->Position]);
  632. this->ComputeRelativePathTopSource();
  633. }
  634. const char* cmState::Snapshot::GetCurrentBinaryDirectory() const
  635. {
  636. return this->State->OutputLocations[this->Position].c_str();
  637. }
  638. void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
  639. {
  640. assert(this->State->OutputLocations.size() > this->Position);
  641. this->State->OutputLocations[this->Position] = dir;
  642. cmSystemTools::ConvertToUnixSlashes(
  643. this->State->OutputLocations[this->Position]);
  644. this->State->OutputLocations[this->Position] =
  645. cmSystemTools::CollapseFullPath(
  646. this->State->OutputLocations[this->Position]);
  647. cmSystemTools::SplitPath(
  648. this->State->OutputLocations[this->Position],
  649. this->State->CurrentBinaryDirectoryComponents[this->Position]);
  650. this->ComputeRelativePathTopBinary();
  651. }
  652. std::vector<std::string> const&
  653. cmState::Snapshot::GetCurrentSourceDirectoryComponents()
  654. {
  655. return this->State->CurrentSourceDirectoryComponents[this->Position];
  656. }
  657. std::vector<std::string> const&
  658. cmState::Snapshot::GetCurrentBinaryDirectoryComponents()
  659. {
  660. return this->State->CurrentBinaryDirectoryComponents[this->Position];
  661. }
  662. const char* cmState::Snapshot::GetRelativePathTopSource() const
  663. {
  664. return this->State->RelativePathTopSource[this->Position].c_str();
  665. }
  666. const char* cmState::Snapshot::GetRelativePathTopBinary() const
  667. {
  668. return this->State->RelativePathTopBinary[this->Position].c_str();
  669. }
  670. void cmState::Snapshot::SetRelativePathTopSource(const char* dir)
  671. {
  672. this->State->RelativePathTopSource[this->Position] = dir;
  673. }
  674. void cmState::Snapshot::SetRelativePathTopBinary(const char* dir)
  675. {
  676. this->State->RelativePathTopBinary[this->Position] = dir;
  677. }
  678. bool cmState::Snapshot::IsValid() const
  679. {
  680. return this->State ? true : false;
  681. }
  682. cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
  683. {
  684. Snapshot snapshot;
  685. if (!this->State || this->Position == 0)
  686. {
  687. return snapshot;
  688. }
  689. PositionType parentPos = this->State->ParentPositions[this->Position];
  690. snapshot = Snapshot(this->State, parentPos);
  691. return snapshot;
  692. }