cmState.cxx 28 KB

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