cmState.cxx 22 KB

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