cmState.cxx 27 KB

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