cmState.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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. cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
  21. BuildSystemDirectory;
  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. this->BuildsystemDirectory.Truncate();
  200. this->SnapshotData.Truncate();
  201. this->DefineProperty
  202. ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
  203. "", "", true);
  204. this->DefineProperty
  205. ("RULE_LAUNCH_LINK", cmProperty::DIRECTORY,
  206. "", "", true);
  207. this->DefineProperty
  208. ("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY,
  209. "", "", true);
  210. this->DefineProperty
  211. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  212. "", "", true);
  213. this->DefineProperty
  214. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  215. "", "", true);
  216. this->DefineProperty
  217. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  218. "", "", true);
  219. }
  220. void cmState::DefineProperty(const std::string& name,
  221. cmProperty::ScopeType scope,
  222. const char *ShortDescription,
  223. const char *FullDescription,
  224. bool chained)
  225. {
  226. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  227. FullDescription,
  228. chained);
  229. }
  230. cmPropertyDefinition *cmState
  231. ::GetPropertyDefinition(const std::string& name,
  232. cmProperty::ScopeType scope)
  233. {
  234. if (this->IsPropertyDefined(name,scope))
  235. {
  236. return &(this->PropertyDefinitions[scope][name]);
  237. }
  238. return 0;
  239. }
  240. bool cmState::IsPropertyDefined(const std::string& name,
  241. cmProperty::ScopeType scope)
  242. {
  243. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  244. }
  245. bool cmState::IsPropertyChained(const std::string& name,
  246. cmProperty::ScopeType scope)
  247. {
  248. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  249. }
  250. void cmState::SetLanguageEnabled(std::string const& l)
  251. {
  252. std::vector<std::string>::iterator it =
  253. std::lower_bound(this->EnabledLanguages.begin(),
  254. this->EnabledLanguages.end(), l);
  255. if (it == this->EnabledLanguages.end() || *it != l)
  256. {
  257. this->EnabledLanguages.insert(it, l);
  258. }
  259. }
  260. bool cmState::GetLanguageEnabled(std::string const& l) const
  261. {
  262. return std::binary_search(this->EnabledLanguages.begin(),
  263. this->EnabledLanguages.end(), l);
  264. }
  265. std::vector<std::string> cmState::GetEnabledLanguages() const
  266. {
  267. return this->EnabledLanguages;
  268. }
  269. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  270. {
  271. this->EnabledLanguages = langs;
  272. }
  273. void cmState::ClearEnabledLanguages()
  274. {
  275. this->EnabledLanguages.clear();
  276. }
  277. bool cmState::GetIsInTryCompile() const
  278. {
  279. return this->IsInTryCompile;
  280. }
  281. void cmState::SetIsInTryCompile(bool b)
  282. {
  283. this->IsInTryCompile = b;
  284. }
  285. void cmState::RenameCommand(std::string const& oldName,
  286. std::string const& newName)
  287. {
  288. // if the command already exists, free the old one
  289. std::string sOldName = cmSystemTools::LowerCase(oldName);
  290. std::string sNewName = cmSystemTools::LowerCase(newName);
  291. std::map<std::string, cmCommand*>::iterator pos =
  292. this->Commands.find(sOldName);
  293. if ( pos == this->Commands.end() )
  294. {
  295. return;
  296. }
  297. cmCommand* cmd = pos->second;
  298. pos = this->Commands.find(sNewName);
  299. if (pos != this->Commands.end())
  300. {
  301. delete pos->second;
  302. this->Commands.erase(pos);
  303. }
  304. this->Commands.insert(std::make_pair(sNewName, cmd));
  305. pos = this->Commands.find(sOldName);
  306. this->Commands.erase(pos);
  307. }
  308. void cmState::AddCommand(cmCommand* command)
  309. {
  310. std::string name = cmSystemTools::LowerCase(command->GetName());
  311. // if the command already exists, free the old one
  312. std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name);
  313. if (pos != this->Commands.end())
  314. {
  315. delete pos->second;
  316. this->Commands.erase(pos);
  317. }
  318. this->Commands.insert(std::make_pair(name, command));
  319. }
  320. void cmState::RemoveUnscriptableCommands()
  321. {
  322. std::vector<std::string> unscriptableCommands;
  323. for (std::map<std::string, cmCommand*>::iterator
  324. pos = this->Commands.begin();
  325. pos != this->Commands.end(); )
  326. {
  327. if (!pos->second->IsScriptable())
  328. {
  329. delete pos->second;
  330. this->Commands.erase(pos++);
  331. }
  332. else
  333. {
  334. ++pos;
  335. }
  336. }
  337. }
  338. cmCommand* cmState::GetCommand(std::string const& name) const
  339. {
  340. cmCommand* command = 0;
  341. std::string sName = cmSystemTools::LowerCase(name);
  342. std::map<std::string, cmCommand*>::const_iterator pos =
  343. this->Commands.find(sName);
  344. if (pos != this->Commands.end())
  345. {
  346. command = (*pos).second;
  347. }
  348. return command;
  349. }
  350. std::vector<std::string> cmState::GetCommandNames() const
  351. {
  352. std::vector<std::string> commandNames;
  353. commandNames.reserve(this->Commands.size());
  354. std::map<std::string, cmCommand*>::const_iterator cmds
  355. = this->Commands.begin();
  356. for ( ; cmds != this->Commands.end(); ++ cmds )
  357. {
  358. commandNames.push_back(cmds->first);
  359. }
  360. return commandNames;
  361. }
  362. void cmState::RemoveUserDefinedCommands()
  363. {
  364. for(std::map<std::string, cmCommand*>::iterator j = this->Commands.begin();
  365. j != this->Commands.end(); )
  366. {
  367. if (j->second->IsA("cmMacroHelperCommand") ||
  368. j->second->IsA("cmFunctionHelperCommand"))
  369. {
  370. delete j->second;
  371. this->Commands.erase(j++);
  372. }
  373. else
  374. {
  375. ++j;
  376. }
  377. }
  378. }
  379. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  380. {
  381. this->GlobalProperties.SetProperty(prop, value, cmProperty::GLOBAL);
  382. }
  383. void cmState::AppendGlobalProperty(const std::string& prop,
  384. const char* value, bool asString)
  385. {
  386. this->GlobalProperties.AppendProperty(prop, value,
  387. cmProperty::GLOBAL, asString);
  388. }
  389. const char *cmState::GetGlobalProperty(const std::string& prop)
  390. {
  391. // watch for special properties
  392. std::string output = "";
  393. if ( prop == "CACHE_VARIABLES" )
  394. {
  395. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  396. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  397. }
  398. else if ( prop == "COMMANDS" )
  399. {
  400. std::vector<std::string> commands = this->GetCommandNames();
  401. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  402. }
  403. else if ( prop == "IN_TRY_COMPILE" )
  404. {
  405. this->SetGlobalProperty("IN_TRY_COMPILE",
  406. this->IsInTryCompile ? "1" : "0");
  407. }
  408. else if ( prop == "ENABLED_LANGUAGES" )
  409. {
  410. std::string langs;
  411. langs = cmJoin(this->EnabledLanguages, ";");
  412. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  413. }
  414. #define STRING_LIST_ELEMENT(F) ";" #F
  415. if (prop == "CMAKE_C_KNOWN_FEATURES")
  416. {
  417. return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
  418. }
  419. if (prop == "CMAKE_CXX_KNOWN_FEATURES")
  420. {
  421. return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
  422. }
  423. #undef STRING_LIST_ELEMENT
  424. bool dummy = false;
  425. return this->GlobalProperties.GetPropertyValue(prop, cmProperty::GLOBAL,
  426. dummy);
  427. }
  428. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  429. {
  430. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  431. }
  432. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  433. {
  434. this->SourceDirectory = sourceDirectory;
  435. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  436. cmSystemTools::SplitPath(
  437. cmSystemTools::CollapseFullPath(this->SourceDirectory),
  438. this->SourceDirectoryComponents);
  439. }
  440. const char* cmState::GetSourceDirectory() const
  441. {
  442. return this->SourceDirectory.c_str();
  443. }
  444. std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
  445. {
  446. return this->SourceDirectoryComponents;
  447. }
  448. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  449. {
  450. this->BinaryDirectory = binaryDirectory;
  451. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  452. cmSystemTools::SplitPath(
  453. cmSystemTools::CollapseFullPath(this->BinaryDirectory),
  454. this->BinaryDirectoryComponents);
  455. }
  456. void cmState::SetWindowsShell(bool windowsShell)
  457. {
  458. this->WindowsShell = windowsShell;
  459. }
  460. bool cmState::UseWindowsShell() const
  461. {
  462. return this->WindowsShell;
  463. }
  464. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  465. {
  466. this->WindowsVSIDE = windowsVSIDE;
  467. }
  468. bool cmState::UseWindowsVSIDE() const
  469. {
  470. return this->WindowsVSIDE;
  471. }
  472. void cmState::SetWatcomWMake(bool watcomWMake)
  473. {
  474. this->WatcomWMake = watcomWMake;
  475. }
  476. bool cmState::UseWatcomWMake() const
  477. {
  478. return this->WatcomWMake;
  479. }
  480. void cmState::SetMinGWMake(bool minGWMake)
  481. {
  482. this->MinGWMake = minGWMake;
  483. }
  484. bool cmState::UseMinGWMake() const
  485. {
  486. return this->MinGWMake;
  487. }
  488. void cmState::SetNMake(bool nMake)
  489. {
  490. this->NMake = nMake;
  491. }
  492. bool cmState::UseNMake() const
  493. {
  494. return this->NMake;
  495. }
  496. void cmState::SetMSYSShell(bool mSYSShell)
  497. {
  498. this->MSYSShell = mSYSShell;
  499. }
  500. bool cmState::UseMSYSShell() const
  501. {
  502. return this->MSYSShell;
  503. }
  504. const char* cmState::GetBinaryDirectory() const
  505. {
  506. return this->BinaryDirectory.c_str();
  507. }
  508. std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
  509. {
  510. return this->BinaryDirectoryComponents;
  511. }
  512. void cmState::Snapshot::ComputeRelativePathTopSource()
  513. {
  514. // Relative path conversion inside the source tree is not used to
  515. // construct relative paths passed to build tools so it is safe to use
  516. // even when the source is a network path.
  517. cmState::Snapshot snapshot = *this;
  518. std::vector<cmState::Snapshot> snapshots;
  519. snapshots.push_back(snapshot);
  520. while (true)
  521. {
  522. snapshot = snapshot.GetBuildsystemDirectoryParent();
  523. if (snapshot.IsValid())
  524. {
  525. snapshots.push_back(snapshot);
  526. }
  527. else
  528. {
  529. break;
  530. }
  531. }
  532. std::string result = snapshots.front().GetCurrentSourceDirectory();
  533. for (std::vector<cmState::Snapshot>::const_iterator it =
  534. snapshots.begin() + 1; it != snapshots.end(); ++it)
  535. {
  536. std::string currentSource = it->GetCurrentSourceDirectory();
  537. if(cmSystemTools::IsSubDirectory(result, currentSource))
  538. {
  539. result = currentSource;
  540. }
  541. }
  542. this->Position->BuildSystemDirectory->RelativePathTopSource = result;
  543. }
  544. void cmState::Snapshot::ComputeRelativePathTopBinary()
  545. {
  546. cmState::Snapshot snapshot = *this;
  547. std::vector<cmState::Snapshot> snapshots;
  548. snapshots.push_back(snapshot);
  549. while (true)
  550. {
  551. snapshot = snapshot.GetBuildsystemDirectoryParent();
  552. if (snapshot.IsValid())
  553. {
  554. snapshots.push_back(snapshot);
  555. }
  556. else
  557. {
  558. break;
  559. }
  560. }
  561. std::string result =
  562. snapshots.front().GetCurrentBinaryDirectory();
  563. for (std::vector<cmState::Snapshot>::const_iterator it =
  564. snapshots.begin() + 1; it != snapshots.end(); ++it)
  565. {
  566. std::string currentBinary = it->GetCurrentBinaryDirectory();
  567. if(cmSystemTools::IsSubDirectory(result, currentBinary))
  568. {
  569. result = currentBinary;
  570. }
  571. }
  572. // The current working directory on Windows cannot be a network
  573. // path. Therefore relative paths cannot work when the binary tree
  574. // is a network path.
  575. if(result.size() < 2 || result.substr(0, 2) != "//")
  576. {
  577. this->Position->BuildSystemDirectory->RelativePathTopBinary = result;
  578. }
  579. else
  580. {
  581. this->Position->BuildSystemDirectory->RelativePathTopBinary = "";
  582. }
  583. }
  584. cmState::Snapshot cmState::CreateBaseSnapshot()
  585. {
  586. PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
  587. pos->DirectoryParent = this->SnapshotData.Root();
  588. pos->SnapshotType = BuildsystemDirectoryType;
  589. pos->BuildSystemDirectory =
  590. this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
  591. return cmState::Snapshot(this, pos);
  592. }
  593. cmState::Snapshot
  594. cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot)
  595. {
  596. assert(originSnapshot.IsValid());
  597. PositionType pos = this->SnapshotData.Extend(originSnapshot.Position);
  598. pos->DirectoryParent = originSnapshot.Position;
  599. pos->SnapshotType = BuildsystemDirectoryType;
  600. pos->BuildSystemDirectory =
  601. this->BuildsystemDirectory.Extend(
  602. originSnapshot.Position->BuildSystemDirectory);
  603. return cmState::Snapshot(this, pos);
  604. }
  605. cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  606. : State(state),
  607. Position(position)
  608. {
  609. }
  610. const char* cmState::Snapshot::GetCurrentSourceDirectory() const
  611. {
  612. return this->Position->BuildSystemDirectory->Location.c_str();
  613. }
  614. void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir)
  615. {
  616. assert(this->State);
  617. std::string& loc = this->Position->BuildSystemDirectory->Location;
  618. loc = dir;
  619. cmSystemTools::ConvertToUnixSlashes(loc);
  620. loc = cmSystemTools::CollapseFullPath(loc);
  621. cmSystemTools::SplitPath(
  622. loc,
  623. this->Position->BuildSystemDirectory->CurrentSourceDirectoryComponents);
  624. this->ComputeRelativePathTopSource();
  625. }
  626. const char* cmState::Snapshot::GetCurrentBinaryDirectory() const
  627. {
  628. return this->Position->BuildSystemDirectory->OutputLocation.c_str();
  629. }
  630. void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
  631. {
  632. std::string& loc = this->Position->BuildSystemDirectory->OutputLocation;
  633. loc = dir;
  634. cmSystemTools::ConvertToUnixSlashes(loc);
  635. loc = cmSystemTools::CollapseFullPath(loc);
  636. cmSystemTools::SplitPath(
  637. loc,
  638. this->Position->BuildSystemDirectory->CurrentBinaryDirectoryComponents);
  639. this->ComputeRelativePathTopBinary();
  640. }
  641. std::vector<std::string> const&
  642. cmState::Snapshot::GetCurrentSourceDirectoryComponents()
  643. {
  644. return this->Position->BuildSystemDirectory
  645. ->CurrentSourceDirectoryComponents;
  646. }
  647. std::vector<std::string> const&
  648. cmState::Snapshot::GetCurrentBinaryDirectoryComponents()
  649. {
  650. return this->Position->BuildSystemDirectory
  651. ->CurrentBinaryDirectoryComponents;
  652. }
  653. const char* cmState::Snapshot::GetRelativePathTopSource() const
  654. {
  655. return this->Position->BuildSystemDirectory->RelativePathTopSource.c_str();
  656. }
  657. const char* cmState::Snapshot::GetRelativePathTopBinary() const
  658. {
  659. return this->Position->BuildSystemDirectory->RelativePathTopBinary.c_str();
  660. }
  661. void cmState::Snapshot::SetRelativePathTopSource(const char* dir)
  662. {
  663. this->Position->BuildSystemDirectory->RelativePathTopSource = dir;
  664. }
  665. void cmState::Snapshot::SetRelativePathTopBinary(const char* dir)
  666. {
  667. this->Position->BuildSystemDirectory->RelativePathTopBinary = dir;
  668. }
  669. bool cmState::Snapshot::IsValid() const
  670. {
  671. return this->State && this->Position.IsValid()
  672. ? this->Position != this->State->SnapshotData.Root()
  673. : false;
  674. }
  675. cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
  676. {
  677. Snapshot snapshot;
  678. if (!this->State || this->Position == this->State->SnapshotData.Root())
  679. {
  680. return snapshot;
  681. }
  682. PositionType parentPos = this->Position->DirectoryParent;
  683. if (parentPos != this->State->SnapshotData.Root())
  684. {
  685. snapshot = Snapshot(this->State, parentPos);
  686. }
  687. return snapshot;
  688. }
  689. cmState* cmState::Snapshot::GetState() const
  690. {
  691. return this->State;
  692. }