cmState.cxx 22 KB

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