cmState.cxx 27 KB

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