cmState.cxx 28 KB

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