cmState.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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. bool dummy = false;
  437. return this->GlobalProperties.GetPropertyValue(prop, cmProperty::GLOBAL,
  438. dummy);
  439. }
  440. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  441. {
  442. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  443. }
  444. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  445. {
  446. this->SourceDirectory = sourceDirectory;
  447. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  448. cmSystemTools::SplitPath(
  449. cmSystemTools::CollapseFullPath(this->SourceDirectory),
  450. this->SourceDirectoryComponents);
  451. }
  452. const char* cmState::GetSourceDirectory() const
  453. {
  454. return this->SourceDirectory.c_str();
  455. }
  456. std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
  457. {
  458. return this->SourceDirectoryComponents;
  459. }
  460. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  461. {
  462. this->BinaryDirectory = binaryDirectory;
  463. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  464. cmSystemTools::SplitPath(
  465. cmSystemTools::CollapseFullPath(this->BinaryDirectory),
  466. this->BinaryDirectoryComponents);
  467. }
  468. void cmState::SetWindowsShell(bool windowsShell)
  469. {
  470. this->WindowsShell = windowsShell;
  471. }
  472. bool cmState::UseWindowsShell() const
  473. {
  474. return this->WindowsShell;
  475. }
  476. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  477. {
  478. this->WindowsVSIDE = windowsVSIDE;
  479. }
  480. bool cmState::UseWindowsVSIDE() const
  481. {
  482. return this->WindowsVSIDE;
  483. }
  484. void cmState::SetWatcomWMake(bool watcomWMake)
  485. {
  486. this->WatcomWMake = watcomWMake;
  487. }
  488. bool cmState::UseWatcomWMake() const
  489. {
  490. return this->WatcomWMake;
  491. }
  492. void cmState::SetMinGWMake(bool minGWMake)
  493. {
  494. this->MinGWMake = minGWMake;
  495. }
  496. bool cmState::UseMinGWMake() const
  497. {
  498. return this->MinGWMake;
  499. }
  500. void cmState::SetNMake(bool nMake)
  501. {
  502. this->NMake = nMake;
  503. }
  504. bool cmState::UseNMake() const
  505. {
  506. return this->NMake;
  507. }
  508. void cmState::SetMSYSShell(bool mSYSShell)
  509. {
  510. this->MSYSShell = mSYSShell;
  511. }
  512. bool cmState::UseMSYSShell() const
  513. {
  514. return this->MSYSShell;
  515. }
  516. const char* cmState::GetBinaryDirectory() const
  517. {
  518. return this->BinaryDirectory.c_str();
  519. }
  520. std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
  521. {
  522. return this->BinaryDirectoryComponents;
  523. }
  524. void cmState::Snapshot::ComputeRelativePathTopSource()
  525. {
  526. // Relative path conversion inside the source tree is not used to
  527. // construct relative paths passed to build tools so it is safe to use
  528. // even when the source is a network path.
  529. cmState::Snapshot snapshot = *this;
  530. std::vector<cmState::Snapshot> snapshots;
  531. snapshots.push_back(snapshot);
  532. while (true)
  533. {
  534. snapshot = snapshot.GetBuildsystemDirectoryParent();
  535. if (snapshot.IsValid())
  536. {
  537. snapshots.push_back(snapshot);
  538. }
  539. else
  540. {
  541. break;
  542. }
  543. }
  544. std::string result = snapshots.front().GetCurrentSourceDirectory();
  545. for (std::vector<cmState::Snapshot>::const_iterator it =
  546. snapshots.begin() + 1; it != snapshots.end(); ++it)
  547. {
  548. std::string currentSource = it->GetCurrentSourceDirectory();
  549. if(cmSystemTools::IsSubDirectory(result, currentSource))
  550. {
  551. result = currentSource;
  552. }
  553. }
  554. this->State->RelativePathTopSource[this->Position] = result;
  555. }
  556. void cmState::Snapshot::ComputeRelativePathTopBinary()
  557. {
  558. cmState::Snapshot snapshot = *this;
  559. std::vector<cmState::Snapshot> snapshots;
  560. snapshots.push_back(snapshot);
  561. while (true)
  562. {
  563. snapshot = snapshot.GetBuildsystemDirectoryParent();
  564. if (snapshot.IsValid())
  565. {
  566. snapshots.push_back(snapshot);
  567. }
  568. else
  569. {
  570. break;
  571. }
  572. }
  573. std::string result =
  574. snapshots.front().GetCurrentBinaryDirectory();
  575. for (std::vector<cmState::Snapshot>::const_iterator it =
  576. snapshots.begin() + 1; it != snapshots.end(); ++it)
  577. {
  578. std::string currentBinary = it->GetCurrentBinaryDirectory();
  579. if(cmSystemTools::IsSubDirectory(result, currentBinary))
  580. {
  581. result = currentBinary;
  582. }
  583. }
  584. // The current working directory on Windows cannot be a network
  585. // path. Therefore relative paths cannot work when the binary tree
  586. // is a network path.
  587. if(result.size() < 2 || result.substr(0, 2) != "//")
  588. {
  589. this->State->RelativePathTopBinary[this->Position] = result;
  590. }
  591. else
  592. {
  593. this->State->RelativePathTopBinary[this->Position] = "";
  594. }
  595. }
  596. cmState::Snapshot cmState::CreateBaseSnapshot()
  597. {
  598. PositionType pos = 0;
  599. this->ParentPositions.push_back(pos);
  600. this->Locations.resize(1);
  601. this->OutputLocations.resize(1);
  602. this->CurrentSourceDirectoryComponents.resize(1);
  603. this->CurrentBinaryDirectoryComponents.resize(1);
  604. this->RelativePathTopSource.resize(1);
  605. this->RelativePathTopBinary.resize(1);
  606. return cmState::Snapshot(this, pos);
  607. }
  608. cmState::Snapshot
  609. cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot)
  610. {
  611. assert(originSnapshot.IsValid());
  612. PositionType pos = this->ParentPositions.size();
  613. this->ParentPositions.push_back(originSnapshot.Position);
  614. this->Locations.resize(this->Locations.size() + 1);
  615. this->OutputLocations.resize(this->OutputLocations.size() + 1);
  616. this->CurrentSourceDirectoryComponents.resize(
  617. this->CurrentSourceDirectoryComponents.size() + 1);
  618. this->CurrentBinaryDirectoryComponents.resize(
  619. this->CurrentBinaryDirectoryComponents.size() + 1);
  620. this->RelativePathTopSource.resize(this->RelativePathTopSource.size() + 1);
  621. this->RelativePathTopBinary.resize(this->RelativePathTopBinary.size() + 1);
  622. return cmState::Snapshot(this, pos);
  623. }
  624. cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  625. : State(state),
  626. Position(position)
  627. {
  628. }
  629. const char* cmState::Snapshot::GetCurrentSourceDirectory() const
  630. {
  631. return this->State->Locations[this->Position].c_str();
  632. }
  633. void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir)
  634. {
  635. assert(this->State);
  636. assert(this->State->Locations.size() > this->Position);
  637. this->State->Locations[this->Position] = dir;
  638. cmSystemTools::ConvertToUnixSlashes(
  639. this->State->Locations[this->Position]);
  640. this->State->Locations[this->Position] =
  641. cmSystemTools::CollapseFullPath(this->State->Locations[this->Position]);
  642. cmSystemTools::SplitPath(
  643. this->State->Locations[this->Position],
  644. this->State->CurrentSourceDirectoryComponents[this->Position]);
  645. this->ComputeRelativePathTopSource();
  646. }
  647. const char* cmState::Snapshot::GetCurrentBinaryDirectory() const
  648. {
  649. return this->State->OutputLocations[this->Position].c_str();
  650. }
  651. void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir)
  652. {
  653. assert(this->State->OutputLocations.size() > this->Position);
  654. this->State->OutputLocations[this->Position] = dir;
  655. cmSystemTools::ConvertToUnixSlashes(
  656. this->State->OutputLocations[this->Position]);
  657. this->State->OutputLocations[this->Position] =
  658. cmSystemTools::CollapseFullPath(
  659. this->State->OutputLocations[this->Position]);
  660. cmSystemTools::SplitPath(
  661. this->State->OutputLocations[this->Position],
  662. this->State->CurrentBinaryDirectoryComponents[this->Position]);
  663. this->ComputeRelativePathTopBinary();
  664. }
  665. std::vector<std::string> const&
  666. cmState::Snapshot::GetCurrentSourceDirectoryComponents()
  667. {
  668. return this->State->CurrentSourceDirectoryComponents[this->Position];
  669. }
  670. std::vector<std::string> const&
  671. cmState::Snapshot::GetCurrentBinaryDirectoryComponents()
  672. {
  673. return this->State->CurrentBinaryDirectoryComponents[this->Position];
  674. }
  675. const char* cmState::Snapshot::GetRelativePathTopSource() const
  676. {
  677. return this->State->RelativePathTopSource[this->Position].c_str();
  678. }
  679. const char* cmState::Snapshot::GetRelativePathTopBinary() const
  680. {
  681. return this->State->RelativePathTopBinary[this->Position].c_str();
  682. }
  683. void cmState::Snapshot::SetRelativePathTopSource(const char* dir)
  684. {
  685. this->State->RelativePathTopSource[this->Position] = dir;
  686. }
  687. void cmState::Snapshot::SetRelativePathTopBinary(const char* dir)
  688. {
  689. this->State->RelativePathTopBinary[this->Position] = dir;
  690. }
  691. bool cmState::Snapshot::IsValid() const
  692. {
  693. return this->State ? true : false;
  694. }
  695. cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
  696. {
  697. Snapshot snapshot;
  698. if (!this->State || this->Position == 0)
  699. {
  700. return snapshot;
  701. }
  702. PositionType parentPos = this->State->ParentPositions[this->Position];
  703. snapshot = Snapshot(this->State, parentPos);
  704. return snapshot;
  705. }