cmState.cxx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmState.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <utility>
  9. #include "cmAlgorithms.h"
  10. #include "cmCacheManager.h"
  11. #include "cmCommand.h"
  12. #include "cmDefinitions.h"
  13. #include "cmDisallowedCommand.h"
  14. #include "cmGlobVerificationManager.h"
  15. #include "cmListFileCache.h"
  16. #include "cmStatePrivate.h"
  17. #include "cmStateSnapshot.h"
  18. #include "cmSystemTools.h"
  19. #include "cmUnexpectedCommand.h"
  20. #include "cmake.h"
  21. cmState::cmState()
  22. : IsInTryCompile(false)
  23. , IsGeneratorMultiConfig(false)
  24. , WindowsShell(false)
  25. , WindowsVSIDE(false)
  26. , WatcomWMake(false)
  27. , MinGWMake(false)
  28. , NMake(false)
  29. , MSYSShell(false)
  30. {
  31. this->CacheManager = new cmCacheManager;
  32. this->GlobVerificationManager = new cmGlobVerificationManager;
  33. }
  34. cmState::~cmState()
  35. {
  36. delete this->CacheManager;
  37. delete this->GlobVerificationManager;
  38. cmDeleteAll(this->BuiltinCommands);
  39. cmDeleteAll(this->ScriptedCommands);
  40. }
  41. const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType)
  42. {
  43. switch (targetType) {
  44. case cmStateEnums::STATIC_LIBRARY:
  45. return "STATIC_LIBRARY";
  46. case cmStateEnums::MODULE_LIBRARY:
  47. return "MODULE_LIBRARY";
  48. case cmStateEnums::SHARED_LIBRARY:
  49. return "SHARED_LIBRARY";
  50. case cmStateEnums::OBJECT_LIBRARY:
  51. return "OBJECT_LIBRARY";
  52. case cmStateEnums::EXECUTABLE:
  53. return "EXECUTABLE";
  54. case cmStateEnums::UTILITY:
  55. return "UTILITY";
  56. case cmStateEnums::GLOBAL_TARGET:
  57. return "GLOBAL_TARGET";
  58. case cmStateEnums::INTERFACE_LIBRARY:
  59. return "INTERFACE_LIBRARY";
  60. case cmStateEnums::UNKNOWN_LIBRARY:
  61. return "UNKNOWN_LIBRARY";
  62. }
  63. assert(false && "Unexpected target type");
  64. return nullptr;
  65. }
  66. const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH",
  67. "STRING", "INTERNAL", "STATIC",
  68. "UNINITIALIZED", nullptr };
  69. const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type)
  70. {
  71. if (type > 6) {
  72. return cmCacheEntryTypes[6];
  73. }
  74. return cmCacheEntryTypes[type];
  75. }
  76. cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(const char* s)
  77. {
  78. int i = 0;
  79. while (cmCacheEntryTypes[i]) {
  80. if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
  81. return static_cast<cmStateEnums::CacheEntryType>(i);
  82. }
  83. ++i;
  84. }
  85. return cmStateEnums::STRING;
  86. }
  87. bool cmState::IsCacheEntryType(std::string const& key)
  88. {
  89. for (int i = 0; cmCacheEntryTypes[i]; ++i) {
  90. if (key == cmCacheEntryTypes[i]) {
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. bool cmState::LoadCache(const std::string& path, bool internal,
  97. std::set<std::string>& excludes,
  98. std::set<std::string>& includes)
  99. {
  100. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  101. }
  102. bool cmState::SaveCache(const std::string& path, cmMessenger* messenger)
  103. {
  104. return this->CacheManager->SaveCache(path, messenger);
  105. }
  106. bool cmState::DeleteCache(const std::string& path)
  107. {
  108. return this->CacheManager->DeleteCache(path);
  109. }
  110. std::vector<std::string> cmState::GetCacheEntryKeys() const
  111. {
  112. std::vector<std::string> definitions;
  113. definitions.reserve(this->CacheManager->GetSize());
  114. cmCacheManager::CacheIterator cit = this->CacheManager->GetCacheIterator();
  115. for (cit.Begin(); !cit.IsAtEnd(); cit.Next()) {
  116. definitions.push_back(cit.GetName());
  117. }
  118. return definitions;
  119. }
  120. const char* cmState::GetCacheEntryValue(std::string const& key) const
  121. {
  122. cmCacheManager::CacheEntry* e = this->CacheManager->GetCacheEntry(key);
  123. if (!e) {
  124. return nullptr;
  125. }
  126. return e->Value.c_str();
  127. }
  128. const char* cmState::GetInitializedCacheValue(std::string const& key) const
  129. {
  130. return this->CacheManager->GetInitializedCacheValue(key);
  131. }
  132. cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
  133. std::string const& key) const
  134. {
  135. cmCacheManager::CacheIterator it =
  136. this->CacheManager->GetCacheIterator(key.c_str());
  137. return it.GetType();
  138. }
  139. void cmState::SetCacheEntryValue(std::string const& key,
  140. std::string const& value)
  141. {
  142. this->CacheManager->SetCacheEntryValue(key, value);
  143. }
  144. void cmState::SetCacheEntryProperty(std::string const& key,
  145. std::string const& propertyName,
  146. std::string const& value)
  147. {
  148. cmCacheManager::CacheIterator it =
  149. this->CacheManager->GetCacheIterator(key.c_str());
  150. it.SetProperty(propertyName, value.c_str());
  151. }
  152. void cmState::SetCacheEntryBoolProperty(std::string const& key,
  153. std::string const& propertyName,
  154. bool value)
  155. {
  156. cmCacheManager::CacheIterator it =
  157. this->CacheManager->GetCacheIterator(key.c_str());
  158. it.SetProperty(propertyName, value);
  159. }
  160. std::vector<std::string> cmState::GetCacheEntryPropertyList(
  161. const std::string& key)
  162. {
  163. cmCacheManager::CacheIterator it =
  164. this->CacheManager->GetCacheIterator(key.c_str());
  165. return it.GetPropertyList();
  166. }
  167. const char* cmState::GetCacheEntryProperty(std::string const& key,
  168. std::string const& propertyName)
  169. {
  170. cmCacheManager::CacheIterator it =
  171. this->CacheManager->GetCacheIterator(key.c_str());
  172. if (!it.PropertyExists(propertyName)) {
  173. return nullptr;
  174. }
  175. return it.GetProperty(propertyName);
  176. }
  177. bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
  178. std::string const& propertyName)
  179. {
  180. return this->CacheManager->GetCacheIterator(key.c_str())
  181. .GetPropertyAsBool(propertyName);
  182. }
  183. void cmState::AddCacheEntry(const std::string& key, const char* value,
  184. const char* helpString,
  185. cmStateEnums::CacheEntryType type)
  186. {
  187. this->CacheManager->AddCacheEntry(key, value, helpString, type);
  188. }
  189. bool cmState::DoWriteGlobVerifyTarget() const
  190. {
  191. return this->GlobVerificationManager->DoWriteVerifyTarget();
  192. }
  193. std::string const& cmState::GetGlobVerifyScript() const
  194. {
  195. return this->GlobVerificationManager->GetVerifyScript();
  196. }
  197. std::string const& cmState::GetGlobVerifyStamp() const
  198. {
  199. return this->GlobVerificationManager->GetVerifyStamp();
  200. }
  201. bool cmState::SaveVerificationScript(const std::string& path)
  202. {
  203. return this->GlobVerificationManager->SaveVerificationScript(path);
  204. }
  205. void cmState::AddGlobCacheEntry(bool recurse, bool listDirectories,
  206. bool followSymlinks,
  207. const std::string& relative,
  208. const std::string& expression,
  209. const std::vector<std::string>& files,
  210. const std::string& variable,
  211. cmListFileBacktrace const& backtrace)
  212. {
  213. this->GlobVerificationManager->AddCacheEntry(
  214. recurse, listDirectories, followSymlinks, relative, expression, files,
  215. variable, backtrace);
  216. }
  217. void cmState::RemoveCacheEntry(std::string const& key)
  218. {
  219. this->CacheManager->RemoveCacheEntry(key);
  220. }
  221. void cmState::AppendCacheEntryProperty(const std::string& key,
  222. const std::string& property,
  223. const std::string& value, bool asString)
  224. {
  225. this->CacheManager->GetCacheIterator(key.c_str())
  226. .AppendProperty(property, value.c_str(), asString);
  227. }
  228. void cmState::RemoveCacheEntryProperty(std::string const& key,
  229. std::string const& propertyName)
  230. {
  231. this->CacheManager->GetCacheIterator(key.c_str())
  232. .SetProperty(propertyName, nullptr);
  233. }
  234. cmStateSnapshot cmState::Reset()
  235. {
  236. this->GlobalProperties.clear();
  237. this->PropertyDefinitions.clear();
  238. cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
  239. this->ExecutionListFiles.Truncate();
  240. {
  241. cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it =
  242. this->BuildsystemDirectory.Truncate();
  243. it->IncludeDirectories.clear();
  244. it->IncludeDirectoryBacktraces.clear();
  245. it->CompileDefinitions.clear();
  246. it->CompileDefinitionsBacktraces.clear();
  247. it->CompileOptions.clear();
  248. it->CompileOptionsBacktraces.clear();
  249. it->DirectoryEnd = pos;
  250. it->NormalTargetNames.clear();
  251. it->Properties.clear();
  252. it->Children.clear();
  253. }
  254. this->PolicyStack.Clear();
  255. pos->Policies = this->PolicyStack.Root();
  256. pos->PolicyRoot = this->PolicyStack.Root();
  257. pos->PolicyScope = this->PolicyStack.Root();
  258. assert(pos->Policies.IsValid());
  259. assert(pos->PolicyRoot.IsValid());
  260. {
  261. std::string srcDir =
  262. cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
  263. std::string binDir =
  264. cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
  265. this->VarTree.Clear();
  266. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  267. pos->Parent = this->VarTree.Root();
  268. pos->Root = this->VarTree.Root();
  269. pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str());
  270. pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str());
  271. }
  272. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
  273. true);
  274. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
  275. true);
  276. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
  277. true);
  278. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
  279. true);
  280. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
  281. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
  282. return cmStateSnapshot(this, pos);
  283. }
  284. void cmState::DefineProperty(const std::string& name,
  285. cmProperty::ScopeType scope,
  286. const char* ShortDescription,
  287. const char* FullDescription, bool chained)
  288. {
  289. this->PropertyDefinitions[scope].DefineProperty(
  290. name, scope, ShortDescription, FullDescription, chained);
  291. }
  292. cmPropertyDefinition const* cmState::GetPropertyDefinition(
  293. const std::string& name, cmProperty::ScopeType scope) const
  294. {
  295. if (this->IsPropertyDefined(name, scope)) {
  296. cmPropertyDefinitionMap const& defs =
  297. this->PropertyDefinitions.find(scope)->second;
  298. return &defs.find(name)->second;
  299. }
  300. return nullptr;
  301. }
  302. bool cmState::IsPropertyDefined(const std::string& name,
  303. cmProperty::ScopeType scope) const
  304. {
  305. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  306. this->PropertyDefinitions.find(scope);
  307. if (it == this->PropertyDefinitions.end()) {
  308. return false;
  309. }
  310. return it->second.IsPropertyDefined(name);
  311. }
  312. bool cmState::IsPropertyChained(const std::string& name,
  313. cmProperty::ScopeType scope) const
  314. {
  315. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  316. this->PropertyDefinitions.find(scope);
  317. if (it == this->PropertyDefinitions.end()) {
  318. return false;
  319. }
  320. return it->second.IsPropertyChained(name);
  321. }
  322. void cmState::SetLanguageEnabled(std::string const& l)
  323. {
  324. std::vector<std::string>::iterator it = std::lower_bound(
  325. this->EnabledLanguages.begin(), this->EnabledLanguages.end(), l);
  326. if (it == this->EnabledLanguages.end() || *it != l) {
  327. this->EnabledLanguages.insert(it, l);
  328. }
  329. }
  330. bool cmState::GetLanguageEnabled(std::string const& l) const
  331. {
  332. return std::binary_search(this->EnabledLanguages.begin(),
  333. this->EnabledLanguages.end(), l);
  334. }
  335. std::vector<std::string> cmState::GetEnabledLanguages() const
  336. {
  337. return this->EnabledLanguages;
  338. }
  339. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  340. {
  341. this->EnabledLanguages = langs;
  342. }
  343. void cmState::ClearEnabledLanguages()
  344. {
  345. this->EnabledLanguages.clear();
  346. }
  347. bool cmState::GetIsInTryCompile() const
  348. {
  349. return this->IsInTryCompile;
  350. }
  351. void cmState::SetIsInTryCompile(bool b)
  352. {
  353. this->IsInTryCompile = b;
  354. }
  355. bool cmState::GetIsGeneratorMultiConfig() const
  356. {
  357. return this->IsGeneratorMultiConfig;
  358. }
  359. void cmState::SetIsGeneratorMultiConfig(bool b)
  360. {
  361. this->IsGeneratorMultiConfig = b;
  362. }
  363. void cmState::AddBuiltinCommand(std::string const& name, cmCommand* command)
  364. {
  365. assert(name == cmSystemTools::LowerCase(name));
  366. assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
  367. this->BuiltinCommands.insert(std::make_pair(name, command));
  368. }
  369. void cmState::AddDisallowedCommand(std::string const& name, cmCommand* command,
  370. cmPolicies::PolicyID policy,
  371. const char* message)
  372. {
  373. this->AddBuiltinCommand(name,
  374. new cmDisallowedCommand(command, policy, message));
  375. }
  376. void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
  377. {
  378. this->AddBuiltinCommand(name, new cmUnexpectedCommand(name, error));
  379. }
  380. void cmState::AddScriptedCommand(std::string const& name, cmCommand* command)
  381. {
  382. std::string sName = cmSystemTools::LowerCase(name);
  383. // if the command already exists, give a new name to the old command.
  384. if (cmCommand* oldCmd = this->GetCommand(sName)) {
  385. std::string const newName = "_" + sName;
  386. std::map<std::string, cmCommand*>::iterator pos =
  387. this->ScriptedCommands.find(newName);
  388. if (pos != this->ScriptedCommands.end()) {
  389. delete pos->second;
  390. this->ScriptedCommands.erase(pos);
  391. }
  392. this->ScriptedCommands.insert(std::make_pair(newName, oldCmd->Clone()));
  393. }
  394. // if the command already exists, free the old one
  395. std::map<std::string, cmCommand*>::iterator pos =
  396. this->ScriptedCommands.find(sName);
  397. if (pos != this->ScriptedCommands.end()) {
  398. delete pos->second;
  399. this->ScriptedCommands.erase(pos);
  400. }
  401. this->ScriptedCommands.insert(std::make_pair(sName, command));
  402. }
  403. cmCommand* cmState::GetCommand(std::string const& name) const
  404. {
  405. return GetCommandByExactName(cmSystemTools::LowerCase(name));
  406. }
  407. cmCommand* cmState::GetCommandByExactName(std::string const& name) const
  408. {
  409. std::map<std::string, cmCommand*>::const_iterator pos;
  410. pos = this->ScriptedCommands.find(name);
  411. if (pos != this->ScriptedCommands.end()) {
  412. return pos->second;
  413. }
  414. pos = this->BuiltinCommands.find(name);
  415. if (pos != this->BuiltinCommands.end()) {
  416. return pos->second;
  417. }
  418. return nullptr;
  419. }
  420. std::vector<std::string> cmState::GetCommandNames() const
  421. {
  422. std::vector<std::string> commandNames;
  423. commandNames.reserve(this->BuiltinCommands.size() +
  424. this->ScriptedCommands.size());
  425. for (auto const& bc : this->BuiltinCommands) {
  426. commandNames.push_back(bc.first);
  427. }
  428. for (auto const& sc : this->ScriptedCommands) {
  429. commandNames.push_back(sc.first);
  430. }
  431. std::sort(commandNames.begin(), commandNames.end());
  432. commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
  433. commandNames.end());
  434. return commandNames;
  435. }
  436. void cmState::RemoveUserDefinedCommands()
  437. {
  438. cmDeleteAll(this->ScriptedCommands);
  439. this->ScriptedCommands.clear();
  440. }
  441. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  442. {
  443. this->GlobalProperties.SetProperty(prop, value);
  444. }
  445. void cmState::AppendGlobalProperty(const std::string& prop, const char* value,
  446. bool asString)
  447. {
  448. this->GlobalProperties.AppendProperty(prop, value, asString);
  449. }
  450. const char* cmState::GetGlobalProperty(const std::string& prop)
  451. {
  452. if (prop == "CACHE_VARIABLES") {
  453. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  454. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  455. } else if (prop == "COMMANDS") {
  456. std::vector<std::string> commands = this->GetCommandNames();
  457. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  458. } else if (prop == "IN_TRY_COMPILE") {
  459. this->SetGlobalProperty("IN_TRY_COMPILE",
  460. this->IsInTryCompile ? "1" : "0");
  461. } else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
  462. this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
  463. this->IsGeneratorMultiConfig ? "1" : "0");
  464. } else if (prop == "ENABLED_LANGUAGES") {
  465. std::string langs;
  466. langs = cmJoin(this->EnabledLanguages, ";");
  467. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  468. }
  469. #define STRING_LIST_ELEMENT(F) ";" #F
  470. if (prop == "CMAKE_C_KNOWN_FEATURES") {
  471. return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
  472. }
  473. if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
  474. return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
  475. }
  476. #undef STRING_LIST_ELEMENT
  477. return this->GlobalProperties.GetPropertyValue(prop);
  478. }
  479. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  480. {
  481. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  482. }
  483. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  484. {
  485. this->SourceDirectory = sourceDirectory;
  486. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  487. }
  488. std::string const& cmState::GetSourceDirectory() const
  489. {
  490. return this->SourceDirectory;
  491. }
  492. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  493. {
  494. this->BinaryDirectory = binaryDirectory;
  495. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  496. }
  497. void cmState::SetWindowsShell(bool windowsShell)
  498. {
  499. this->WindowsShell = windowsShell;
  500. }
  501. bool cmState::UseWindowsShell() const
  502. {
  503. return this->WindowsShell;
  504. }
  505. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  506. {
  507. this->WindowsVSIDE = windowsVSIDE;
  508. }
  509. bool cmState::UseWindowsVSIDE() const
  510. {
  511. return this->WindowsVSIDE;
  512. }
  513. void cmState::SetWatcomWMake(bool watcomWMake)
  514. {
  515. this->WatcomWMake = watcomWMake;
  516. }
  517. bool cmState::UseWatcomWMake() const
  518. {
  519. return this->WatcomWMake;
  520. }
  521. void cmState::SetMinGWMake(bool minGWMake)
  522. {
  523. this->MinGWMake = minGWMake;
  524. }
  525. bool cmState::UseMinGWMake() const
  526. {
  527. return this->MinGWMake;
  528. }
  529. void cmState::SetNMake(bool nMake)
  530. {
  531. this->NMake = nMake;
  532. }
  533. bool cmState::UseNMake() const
  534. {
  535. return this->NMake;
  536. }
  537. void cmState::SetMSYSShell(bool mSYSShell)
  538. {
  539. this->MSYSShell = mSYSShell;
  540. }
  541. bool cmState::UseMSYSShell() const
  542. {
  543. return this->MSYSShell;
  544. }
  545. unsigned int cmState::GetCacheMajorVersion() const
  546. {
  547. return this->CacheManager->GetCacheMajorVersion();
  548. }
  549. unsigned int cmState::GetCacheMinorVersion() const
  550. {
  551. return this->CacheManager->GetCacheMinorVersion();
  552. }
  553. std::string const& cmState::GetBinaryDirectory() const
  554. {
  555. return this->BinaryDirectory;
  556. }
  557. cmStateSnapshot cmState::CreateBaseSnapshot()
  558. {
  559. cmStateDetail::PositionType pos =
  560. this->SnapshotData.Push(this->SnapshotData.Root());
  561. pos->DirectoryParent = this->SnapshotData.Root();
  562. pos->ScopeParent = this->SnapshotData.Root();
  563. pos->SnapshotType = cmStateEnums::BaseType;
  564. pos->Keep = true;
  565. pos->BuildSystemDirectory =
  566. this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
  567. pos->ExecutionListFile =
  568. this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
  569. pos->IncludeDirectoryPosition = 0;
  570. pos->CompileDefinitionsPosition = 0;
  571. pos->CompileOptionsPosition = 0;
  572. pos->BuildSystemDirectory->DirectoryEnd = pos;
  573. pos->Policies = this->PolicyStack.Root();
  574. pos->PolicyRoot = this->PolicyStack.Root();
  575. pos->PolicyScope = this->PolicyStack.Root();
  576. assert(pos->Policies.IsValid());
  577. assert(pos->PolicyRoot.IsValid());
  578. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  579. assert(pos->Vars.IsValid());
  580. pos->Parent = this->VarTree.Root();
  581. pos->Root = this->VarTree.Root();
  582. return cmStateSnapshot(this, pos);
  583. }
  584. cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
  585. cmStateSnapshot const& originSnapshot)
  586. {
  587. assert(originSnapshot.IsValid());
  588. cmStateDetail::PositionType pos =
  589. this->SnapshotData.Push(originSnapshot.Position);
  590. pos->DirectoryParent = originSnapshot.Position;
  591. pos->ScopeParent = originSnapshot.Position;
  592. pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
  593. pos->Keep = true;
  594. pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
  595. originSnapshot.Position->BuildSystemDirectory);
  596. pos->ExecutionListFile =
  597. this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
  598. pos->BuildSystemDirectory->DirectoryEnd = pos;
  599. pos->Policies = originSnapshot.Position->Policies;
  600. pos->PolicyRoot = originSnapshot.Position->Policies;
  601. pos->PolicyScope = originSnapshot.Position->Policies;
  602. assert(pos->Policies.IsValid());
  603. assert(pos->PolicyRoot.IsValid());
  604. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  605. pos->Parent = origin;
  606. pos->Root = origin;
  607. pos->Vars = this->VarTree.Push(origin);
  608. cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
  609. originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
  610. snapshot.SetDefaultDefinitions();
  611. snapshot.InitializeFromParent();
  612. snapshot.SetDirectoryDefinitions();
  613. return snapshot;
  614. }
  615. cmStateSnapshot cmState::CreateFunctionCallSnapshot(
  616. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  617. {
  618. cmStateDetail::PositionType pos =
  619. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  620. pos->ScopeParent = originSnapshot.Position;
  621. pos->SnapshotType = cmStateEnums::FunctionCallType;
  622. pos->Keep = false;
  623. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  624. originSnapshot.Position->ExecutionListFile, fileName);
  625. pos->BuildSystemDirectory->DirectoryEnd = pos;
  626. pos->PolicyScope = originSnapshot.Position->Policies;
  627. assert(originSnapshot.Position->Vars.IsValid());
  628. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  629. pos->Parent = origin;
  630. pos->Vars = this->VarTree.Push(origin);
  631. return cmStateSnapshot(this, pos);
  632. }
  633. cmStateSnapshot cmState::CreateMacroCallSnapshot(
  634. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  635. {
  636. cmStateDetail::PositionType pos =
  637. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  638. pos->SnapshotType = cmStateEnums::MacroCallType;
  639. pos->Keep = false;
  640. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  641. originSnapshot.Position->ExecutionListFile, fileName);
  642. assert(originSnapshot.Position->Vars.IsValid());
  643. pos->BuildSystemDirectory->DirectoryEnd = pos;
  644. pos->PolicyScope = originSnapshot.Position->Policies;
  645. return cmStateSnapshot(this, pos);
  646. }
  647. cmStateSnapshot cmState::CreateIncludeFileSnapshot(
  648. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  649. {
  650. cmStateDetail::PositionType pos =
  651. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  652. pos->SnapshotType = cmStateEnums::IncludeFileType;
  653. pos->Keep = true;
  654. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  655. originSnapshot.Position->ExecutionListFile, fileName);
  656. assert(originSnapshot.Position->Vars.IsValid());
  657. pos->BuildSystemDirectory->DirectoryEnd = pos;
  658. pos->PolicyScope = originSnapshot.Position->Policies;
  659. return cmStateSnapshot(this, pos);
  660. }
  661. cmStateSnapshot cmState::CreateVariableScopeSnapshot(
  662. cmStateSnapshot const& originSnapshot)
  663. {
  664. cmStateDetail::PositionType pos =
  665. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  666. pos->ScopeParent = originSnapshot.Position;
  667. pos->SnapshotType = cmStateEnums::VariableScopeType;
  668. pos->Keep = false;
  669. pos->PolicyScope = originSnapshot.Position->Policies;
  670. assert(originSnapshot.Position->Vars.IsValid());
  671. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  672. pos->Parent = origin;
  673. pos->Vars = this->VarTree.Push(origin);
  674. assert(pos->Vars.IsValid());
  675. return cmStateSnapshot(this, pos);
  676. }
  677. cmStateSnapshot cmState::CreateInlineListFileSnapshot(
  678. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  679. {
  680. cmStateDetail::PositionType pos =
  681. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  682. pos->SnapshotType = cmStateEnums::InlineListFileType;
  683. pos->Keep = true;
  684. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  685. originSnapshot.Position->ExecutionListFile, fileName);
  686. pos->BuildSystemDirectory->DirectoryEnd = pos;
  687. pos->PolicyScope = originSnapshot.Position->Policies;
  688. return cmStateSnapshot(this, pos);
  689. }
  690. cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
  691. cmStateSnapshot const& originSnapshot)
  692. {
  693. cmStateDetail::PositionType pos =
  694. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  695. pos->SnapshotType = cmStateEnums::PolicyScopeType;
  696. pos->Keep = false;
  697. pos->BuildSystemDirectory->DirectoryEnd = pos;
  698. pos->PolicyScope = originSnapshot.Position->Policies;
  699. return cmStateSnapshot(this, pos);
  700. }
  701. cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
  702. {
  703. cmStateDetail::PositionType pos = originSnapshot.Position;
  704. cmStateDetail::PositionType prevPos = pos;
  705. ++prevPos;
  706. prevPos->IncludeDirectoryPosition =
  707. prevPos->BuildSystemDirectory->IncludeDirectories.size();
  708. prevPos->CompileDefinitionsPosition =
  709. prevPos->BuildSystemDirectory->CompileDefinitions.size();
  710. prevPos->CompileOptionsPosition =
  711. prevPos->BuildSystemDirectory->CompileOptions.size();
  712. prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
  713. if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
  714. if (pos->Vars != prevPos->Vars) {
  715. assert(this->VarTree.IsLast(pos->Vars));
  716. this->VarTree.Pop(pos->Vars);
  717. }
  718. if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
  719. assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
  720. this->ExecutionListFiles.Pop(pos->ExecutionListFile);
  721. }
  722. this->SnapshotData.Pop(pos);
  723. }
  724. return cmStateSnapshot(this, prevPos);
  725. }
  726. static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
  727. std::string& value)
  728. {
  729. // input line is: key=value
  730. static cmsys::RegularExpression reg(
  731. "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  732. // input line is: "key"=value
  733. static cmsys::RegularExpression regQuoted(
  734. "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  735. bool flag = false;
  736. if (regQuoted.find(entry)) {
  737. var = regQuoted.match(1);
  738. value = regQuoted.match(2);
  739. flag = true;
  740. } else if (reg.find(entry)) {
  741. var = reg.match(1);
  742. value = reg.match(2);
  743. flag = true;
  744. }
  745. // if value is enclosed in single quotes ('foo') then remove them
  746. // it is used to enclose trailing space or tab
  747. if (flag && value.size() >= 2 && value[0] == '\'' &&
  748. value[value.size() - 1] == '\'') {
  749. value = value.substr(1, value.size() - 2);
  750. }
  751. return flag;
  752. }
  753. bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
  754. std::string& value,
  755. cmStateEnums::CacheEntryType& type)
  756. {
  757. // input line is: key:type=value
  758. static cmsys::RegularExpression reg(
  759. "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  760. // input line is: "key":type=value
  761. static cmsys::RegularExpression regQuoted(
  762. "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  763. bool flag = false;
  764. if (regQuoted.find(entry)) {
  765. var = regQuoted.match(1);
  766. type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
  767. value = regQuoted.match(3);
  768. flag = true;
  769. } else if (reg.find(entry)) {
  770. var = reg.match(1);
  771. type = cmState::StringToCacheEntryType(reg.match(2).c_str());
  772. value = reg.match(3);
  773. flag = true;
  774. }
  775. // if value is enclosed in single quotes ('foo') then remove them
  776. // it is used to enclose trailing space or tab
  777. if (flag && value.size() >= 2 && value[0] == '\'' &&
  778. value[value.size() - 1] == '\'') {
  779. value = value.substr(1, value.size() - 2);
  780. }
  781. if (!flag) {
  782. return ParseEntryWithoutType(entry, var, value);
  783. }
  784. return flag;
  785. }