cmState.cxx 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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 <algorithm>
  5. #include <array>
  6. #include <cassert>
  7. #include <cstdlib>
  8. #include <utility>
  9. #include <cm/memory>
  10. #include "cmsys/RegularExpression.hxx"
  11. #include "cmCacheManager.h"
  12. #include "cmCommand.h"
  13. #include "cmDefinitions.h"
  14. #include "cmExecutionStatus.h"
  15. #include "cmGlobVerificationManager.h"
  16. #include "cmListFileCache.h"
  17. #include "cmMakefile.h"
  18. #include "cmMessageType.h"
  19. #include "cmStatePrivate.h"
  20. #include "cmStateSnapshot.h"
  21. #include "cmStringAlgorithms.h"
  22. #include "cmSystemTools.h"
  23. #include "cmake.h"
  24. cmState::cmState()
  25. {
  26. this->CacheManager = cm::make_unique<cmCacheManager>();
  27. this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
  28. }
  29. cmState::~cmState() = default;
  30. const std::string& cmState::GetTargetTypeName(
  31. cmStateEnums::TargetType targetType)
  32. {
  33. #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
  34. MAKE_STATIC_PROP(STATIC_LIBRARY);
  35. MAKE_STATIC_PROP(MODULE_LIBRARY);
  36. MAKE_STATIC_PROP(SHARED_LIBRARY);
  37. MAKE_STATIC_PROP(OBJECT_LIBRARY);
  38. MAKE_STATIC_PROP(EXECUTABLE);
  39. MAKE_STATIC_PROP(UTILITY);
  40. MAKE_STATIC_PROP(GLOBAL_TARGET);
  41. MAKE_STATIC_PROP(INTERFACE_LIBRARY);
  42. MAKE_STATIC_PROP(UNKNOWN_LIBRARY);
  43. static const std::string propEmpty;
  44. #undef MAKE_STATIC_PROP
  45. switch (targetType) {
  46. case cmStateEnums::STATIC_LIBRARY:
  47. return propSTATIC_LIBRARY;
  48. case cmStateEnums::MODULE_LIBRARY:
  49. return propMODULE_LIBRARY;
  50. case cmStateEnums::SHARED_LIBRARY:
  51. return propSHARED_LIBRARY;
  52. case cmStateEnums::OBJECT_LIBRARY:
  53. return propOBJECT_LIBRARY;
  54. case cmStateEnums::EXECUTABLE:
  55. return propEXECUTABLE;
  56. case cmStateEnums::UTILITY:
  57. return propUTILITY;
  58. case cmStateEnums::GLOBAL_TARGET:
  59. return propGLOBAL_TARGET;
  60. case cmStateEnums::INTERFACE_LIBRARY:
  61. return propINTERFACE_LIBRARY;
  62. case cmStateEnums::UNKNOWN_LIBRARY:
  63. return propUNKNOWN_LIBRARY;
  64. }
  65. assert(false && "Unexpected target type");
  66. return propEmpty;
  67. }
  68. static const std::array<std::string, 7> cmCacheEntryTypes = {
  69. { "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC",
  70. "UNINITIALIZED" }
  71. };
  72. const std::string& cmState::CacheEntryTypeToString(
  73. cmStateEnums::CacheEntryType type)
  74. {
  75. if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) {
  76. type = cmStateEnums::UNINITIALIZED;
  77. }
  78. return cmCacheEntryTypes[type];
  79. }
  80. cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
  81. const std::string& s)
  82. {
  83. cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
  84. StringToCacheEntryType(s, type);
  85. return type;
  86. }
  87. bool cmState::StringToCacheEntryType(const std::string& s,
  88. cmStateEnums::CacheEntryType& type)
  89. {
  90. for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
  91. if (s == cmCacheEntryTypes[i]) {
  92. type = static_cast<cmStateEnums::CacheEntryType>(i);
  93. return true;
  94. }
  95. }
  96. return false;
  97. }
  98. bool cmState::IsCacheEntryType(std::string const& key)
  99. {
  100. for (const std::string& i : cmCacheEntryTypes) {
  101. if (key == i) {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. bool cmState::LoadCache(const std::string& path, bool internal,
  108. std::set<std::string>& excludes,
  109. std::set<std::string>& includes)
  110. {
  111. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  112. }
  113. bool cmState::SaveCache(const std::string& path, cmMessenger* messenger)
  114. {
  115. return this->CacheManager->SaveCache(path, messenger);
  116. }
  117. bool cmState::DeleteCache(const std::string& path)
  118. {
  119. return this->CacheManager->DeleteCache(path);
  120. }
  121. bool cmState::IsCacheLoaded() const
  122. {
  123. return this->CacheManager->IsCacheLoaded();
  124. }
  125. std::vector<std::string> cmState::GetCacheEntryKeys() const
  126. {
  127. return this->CacheManager->GetCacheEntryKeys();
  128. }
  129. cmProp cmState::GetCacheEntryValue(std::string const& key) const
  130. {
  131. return this->CacheManager->GetCacheEntryValue(key);
  132. }
  133. std::string cmState::GetSafeCacheEntryValue(std::string const& key) const
  134. {
  135. if (cmProp val = this->GetCacheEntryValue(key)) {
  136. return *val;
  137. }
  138. return std::string();
  139. }
  140. cmProp cmState::GetInitializedCacheValue(std::string const& key) const
  141. {
  142. return this->CacheManager->GetInitializedCacheValue(key);
  143. }
  144. cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
  145. std::string const& key) const
  146. {
  147. return this->CacheManager->GetCacheEntryType(key);
  148. }
  149. void cmState::SetCacheEntryValue(std::string const& key,
  150. std::string const& value)
  151. {
  152. this->CacheManager->SetCacheEntryValue(key, value);
  153. }
  154. void cmState::SetCacheEntryProperty(std::string const& key,
  155. std::string const& propertyName,
  156. std::string const& value)
  157. {
  158. this->CacheManager->SetCacheEntryProperty(key, propertyName, value);
  159. }
  160. void cmState::SetCacheEntryBoolProperty(std::string const& key,
  161. std::string const& propertyName,
  162. bool value)
  163. {
  164. this->CacheManager->SetCacheEntryBoolProperty(key, propertyName, value);
  165. }
  166. std::vector<std::string> cmState::GetCacheEntryPropertyList(
  167. const std::string& key)
  168. {
  169. return this->CacheManager->GetCacheEntryPropertyList(key);
  170. }
  171. cmProp cmState::GetCacheEntryProperty(std::string const& key,
  172. std::string const& propertyName)
  173. {
  174. return this->CacheManager->GetCacheEntryProperty(key, propertyName);
  175. }
  176. bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
  177. std::string const& propertyName)
  178. {
  179. return this->CacheManager->GetCacheEntryPropertyAsBool(key, propertyName);
  180. }
  181. void cmState::AddCacheEntry(const std::string& key, const char* value,
  182. const char* helpString,
  183. cmStateEnums::CacheEntryType type)
  184. {
  185. this->CacheManager->AddCacheEntry(key, value, helpString, type);
  186. }
  187. bool cmState::DoWriteGlobVerifyTarget() const
  188. {
  189. return this->GlobVerificationManager->DoWriteVerifyTarget();
  190. }
  191. std::string const& cmState::GetGlobVerifyScript() const
  192. {
  193. return this->GlobVerificationManager->GetVerifyScript();
  194. }
  195. std::string const& cmState::GetGlobVerifyStamp() const
  196. {
  197. return this->GlobVerificationManager->GetVerifyStamp();
  198. }
  199. bool cmState::SaveVerificationScript(const std::string& path)
  200. {
  201. return this->GlobVerificationManager->SaveVerificationScript(path);
  202. }
  203. void cmState::AddGlobCacheEntry(bool recurse, bool listDirectories,
  204. bool followSymlinks,
  205. const std::string& relative,
  206. const std::string& expression,
  207. const std::vector<std::string>& files,
  208. const std::string& variable,
  209. cmListFileBacktrace const& backtrace)
  210. {
  211. this->GlobVerificationManager->AddCacheEntry(
  212. recurse, listDirectories, followSymlinks, relative, expression, files,
  213. variable, backtrace);
  214. }
  215. void cmState::RemoveCacheEntry(std::string const& key)
  216. {
  217. this->CacheManager->RemoveCacheEntry(key);
  218. }
  219. void cmState::AppendCacheEntryProperty(const std::string& key,
  220. const std::string& property,
  221. const std::string& value, bool asString)
  222. {
  223. this->CacheManager->AppendCacheEntryProperty(key, property, value, asString);
  224. }
  225. void cmState::RemoveCacheEntryProperty(std::string const& key,
  226. std::string const& propertyName)
  227. {
  228. this->CacheManager->RemoveCacheEntryProperty(key, propertyName);
  229. }
  230. cmStateSnapshot cmState::Reset()
  231. {
  232. this->GlobalProperties.Clear();
  233. this->PropertyDefinitions = {};
  234. this->GlobVerificationManager->Reset();
  235. cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
  236. this->ExecutionListFiles.Truncate();
  237. {
  238. cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it =
  239. this->BuildsystemDirectory.Truncate();
  240. it->IncludeDirectories.clear();
  241. it->IncludeDirectoryBacktraces.clear();
  242. it->CompileDefinitions.clear();
  243. it->CompileDefinitionsBacktraces.clear();
  244. it->CompileOptions.clear();
  245. it->CompileOptionsBacktraces.clear();
  246. it->LinkOptions.clear();
  247. it->LinkOptionsBacktraces.clear();
  248. it->LinkDirectories.clear();
  249. it->LinkDirectoriesBacktraces.clear();
  250. it->DirectoryEnd = pos;
  251. it->NormalTargetNames.clear();
  252. it->Properties.Clear();
  253. it->Children.clear();
  254. }
  255. this->PolicyStack.Clear();
  256. pos->Policies = this->PolicyStack.Root();
  257. pos->PolicyRoot = this->PolicyStack.Root();
  258. pos->PolicyScope = this->PolicyStack.Root();
  259. assert(pos->Policies.IsValid());
  260. assert(pos->PolicyRoot.IsValid());
  261. {
  262. std::string srcDir =
  263. *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
  264. std::string binDir =
  265. *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
  266. this->VarTree.Clear();
  267. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  268. pos->Parent = this->VarTree.Root();
  269. pos->Root = this->VarTree.Root();
  270. pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir);
  271. pos->Vars->Set("CMAKE_BINARY_DIR", binDir);
  272. }
  273. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
  274. true);
  275. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
  276. true);
  277. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
  278. true);
  279. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
  280. true);
  281. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
  282. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
  283. return { this, pos };
  284. }
  285. void cmState::DefineProperty(const std::string& name,
  286. cmProperty::ScopeType scope,
  287. const std::string& ShortDescription,
  288. const std::string& FullDescription, bool chained)
  289. {
  290. this->PropertyDefinitions.DefineProperty(name, scope, ShortDescription,
  291. FullDescription, chained);
  292. }
  293. cmPropertyDefinition const* cmState::GetPropertyDefinition(
  294. const std::string& name, cmProperty::ScopeType scope) const
  295. {
  296. return this->PropertyDefinitions.GetPropertyDefinition(name, scope);
  297. }
  298. bool cmState::IsPropertyChained(const std::string& name,
  299. cmProperty::ScopeType scope) const
  300. {
  301. if (auto def = this->GetPropertyDefinition(name, scope)) {
  302. return def->IsChained();
  303. }
  304. return false;
  305. }
  306. void cmState::SetLanguageEnabled(std::string const& l)
  307. {
  308. auto it = std::lower_bound(this->EnabledLanguages.begin(),
  309. this->EnabledLanguages.end(), l);
  310. if (it == this->EnabledLanguages.end() || *it != l) {
  311. this->EnabledLanguages.insert(it, l);
  312. }
  313. }
  314. bool cmState::GetLanguageEnabled(std::string const& l) const
  315. {
  316. return std::binary_search(this->EnabledLanguages.begin(),
  317. this->EnabledLanguages.end(), l);
  318. }
  319. std::vector<std::string> cmState::GetEnabledLanguages() const
  320. {
  321. return this->EnabledLanguages;
  322. }
  323. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  324. {
  325. this->EnabledLanguages = langs;
  326. }
  327. void cmState::ClearEnabledLanguages()
  328. {
  329. this->EnabledLanguages.clear();
  330. }
  331. bool cmState::GetIsInTryCompile() const
  332. {
  333. return this->IsInTryCompile;
  334. }
  335. void cmState::SetIsInTryCompile(bool b)
  336. {
  337. this->IsInTryCompile = b;
  338. }
  339. bool cmState::GetIsGeneratorMultiConfig() const
  340. {
  341. return this->IsGeneratorMultiConfig;
  342. }
  343. void cmState::SetIsGeneratorMultiConfig(bool b)
  344. {
  345. this->IsGeneratorMultiConfig = b;
  346. }
  347. void cmState::AddBuiltinCommand(std::string const& name,
  348. std::unique_ptr<cmCommand> command)
  349. {
  350. this->AddBuiltinCommand(name, cmLegacyCommandWrapper(std::move(command)));
  351. }
  352. void cmState::AddBuiltinCommand(std::string const& name, Command command)
  353. {
  354. assert(name == cmSystemTools::LowerCase(name));
  355. assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
  356. this->BuiltinCommands.emplace(name, std::move(command));
  357. }
  358. static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
  359. std::vector<cmListFileArgument> const& args,
  360. cmExecutionStatus& status)
  361. {
  362. cmMakefile& mf = status.GetMakefile();
  363. std::vector<std::string> expandedArguments;
  364. if (!mf.ExpandArguments(args, expandedArguments)) {
  365. // There was an error expanding arguments. It was already
  366. // reported, so we can skip this command without error.
  367. return true;
  368. }
  369. return command(expandedArguments, status);
  370. }
  371. void cmState::AddBuiltinCommand(std::string const& name,
  372. BuiltinCommand command)
  373. {
  374. this->AddBuiltinCommand(
  375. name,
  376. [command](const std::vector<cmListFileArgument>& args,
  377. cmExecutionStatus& status) -> bool {
  378. return InvokeBuiltinCommand(command, args, status);
  379. });
  380. }
  381. void cmState::AddDisallowedCommand(std::string const& name,
  382. BuiltinCommand command,
  383. cmPolicies::PolicyID policy,
  384. const char* message)
  385. {
  386. this->AddBuiltinCommand(
  387. name,
  388. [command, policy, message](const std::vector<cmListFileArgument>& args,
  389. cmExecutionStatus& status) -> bool {
  390. cmMakefile& mf = status.GetMakefile();
  391. switch (mf.GetPolicyStatus(policy)) {
  392. case cmPolicies::WARN:
  393. mf.IssueMessage(MessageType::AUTHOR_WARNING,
  394. cmPolicies::GetPolicyWarning(policy));
  395. break;
  396. case cmPolicies::OLD:
  397. break;
  398. case cmPolicies::REQUIRED_IF_USED:
  399. case cmPolicies::REQUIRED_ALWAYS:
  400. case cmPolicies::NEW:
  401. mf.IssueMessage(MessageType::FATAL_ERROR, message);
  402. return true;
  403. }
  404. return InvokeBuiltinCommand(command, args, status);
  405. });
  406. }
  407. void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
  408. {
  409. this->AddBuiltinCommand(
  410. name,
  411. [name, error](std::vector<cmListFileArgument> const&,
  412. cmExecutionStatus& status) -> bool {
  413. cmProp versionValue =
  414. status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
  415. if (name == "endif" &&
  416. (!versionValue || atof(versionValue->c_str()) <= 1.4)) {
  417. return true;
  418. }
  419. status.SetError(error);
  420. return false;
  421. });
  422. }
  423. void cmState::AddScriptedCommand(std::string const& name, Command command)
  424. {
  425. std::string sName = cmSystemTools::LowerCase(name);
  426. // if the command already exists, give a new name to the old command.
  427. if (Command oldCmd = this->GetCommandByExactName(sName)) {
  428. this->ScriptedCommands["_" + sName] = oldCmd;
  429. }
  430. this->ScriptedCommands[sName] = std::move(command);
  431. }
  432. cmState::Command cmState::GetCommand(std::string const& name) const
  433. {
  434. return GetCommandByExactName(cmSystemTools::LowerCase(name));
  435. }
  436. cmState::Command cmState::GetCommandByExactName(std::string const& name) const
  437. {
  438. auto pos = this->ScriptedCommands.find(name);
  439. if (pos != this->ScriptedCommands.end()) {
  440. return pos->second;
  441. }
  442. pos = this->BuiltinCommands.find(name);
  443. if (pos != this->BuiltinCommands.end()) {
  444. return pos->second;
  445. }
  446. return nullptr;
  447. }
  448. std::vector<std::string> cmState::GetCommandNames() const
  449. {
  450. std::vector<std::string> commandNames;
  451. commandNames.reserve(this->BuiltinCommands.size() +
  452. this->ScriptedCommands.size());
  453. for (auto const& bc : this->BuiltinCommands) {
  454. commandNames.push_back(bc.first);
  455. }
  456. for (auto const& sc : this->ScriptedCommands) {
  457. commandNames.push_back(sc.first);
  458. }
  459. std::sort(commandNames.begin(), commandNames.end());
  460. commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
  461. commandNames.end());
  462. return commandNames;
  463. }
  464. void cmState::RemoveBuiltinCommand(std::string const& name)
  465. {
  466. assert(name == cmSystemTools::LowerCase(name));
  467. this->BuiltinCommands.erase(name);
  468. }
  469. void cmState::RemoveUserDefinedCommands()
  470. {
  471. this->ScriptedCommands.clear();
  472. }
  473. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  474. {
  475. this->GlobalProperties.SetProperty(prop, value);
  476. }
  477. void cmState::AppendGlobalProperty(const std::string& prop,
  478. const std::string& value, bool asString)
  479. {
  480. this->GlobalProperties.AppendProperty(prop, value, asString);
  481. }
  482. cmProp cmState::GetGlobalProperty(const std::string& prop)
  483. {
  484. if (prop == "CACHE_VARIABLES") {
  485. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  486. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  487. } else if (prop == "COMMANDS") {
  488. std::vector<std::string> commands = this->GetCommandNames();
  489. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  490. } else if (prop == "IN_TRY_COMPILE") {
  491. this->SetGlobalProperty("IN_TRY_COMPILE",
  492. this->IsInTryCompile ? "1" : "0");
  493. } else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
  494. this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
  495. this->IsGeneratorMultiConfig ? "1" : "0");
  496. } else if (prop == "ENABLED_LANGUAGES") {
  497. std::string langs;
  498. langs = cmJoin(this->EnabledLanguages, ";");
  499. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  500. } else if (prop == "CMAKE_ROLE") {
  501. std::string mode = this->GetModeString();
  502. this->SetGlobalProperty("CMAKE_ROLE", mode.c_str());
  503. }
  504. #define STRING_LIST_ELEMENT(F) ";" #F
  505. if (prop == "CMAKE_C_KNOWN_FEATURES") {
  506. static const std::string s_out(
  507. &FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1]);
  508. return &s_out;
  509. }
  510. if (prop == "CMAKE_C90_KNOWN_FEATURES") {
  511. static const std::string s_out(
  512. &FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1]);
  513. return &s_out;
  514. }
  515. if (prop == "CMAKE_C99_KNOWN_FEATURES") {
  516. static const std::string s_out(
  517. &FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1]);
  518. return &s_out;
  519. }
  520. if (prop == "CMAKE_C11_KNOWN_FEATURES") {
  521. static const std::string s_out(
  522. &FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1]);
  523. return &s_out;
  524. }
  525. if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
  526. static const std::string s_out(
  527. &FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1]);
  528. return &s_out;
  529. }
  530. if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
  531. static const std::string s_out(
  532. &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1]);
  533. return &s_out;
  534. }
  535. if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
  536. static const std::string s_out(
  537. &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1]);
  538. return &s_out;
  539. }
  540. if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
  541. static const std::string s_out(
  542. &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1]);
  543. return &s_out;
  544. }
  545. if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
  546. static const std::string s_out(
  547. &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1]);
  548. return &s_out;
  549. }
  550. #undef STRING_LIST_ELEMENT
  551. return this->GlobalProperties.GetPropertyValue(prop);
  552. }
  553. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  554. {
  555. return cmIsOn(this->GetGlobalProperty(prop));
  556. }
  557. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  558. {
  559. this->SourceDirectory = sourceDirectory;
  560. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  561. }
  562. std::string const& cmState::GetSourceDirectory() const
  563. {
  564. return this->SourceDirectory;
  565. }
  566. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  567. {
  568. this->BinaryDirectory = binaryDirectory;
  569. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  570. }
  571. void cmState::SetWindowsShell(bool windowsShell)
  572. {
  573. this->WindowsShell = windowsShell;
  574. }
  575. bool cmState::UseWindowsShell() const
  576. {
  577. return this->WindowsShell;
  578. }
  579. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  580. {
  581. this->WindowsVSIDE = windowsVSIDE;
  582. }
  583. bool cmState::UseWindowsVSIDE() const
  584. {
  585. return this->WindowsVSIDE;
  586. }
  587. void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
  588. {
  589. this->GhsMultiIDE = ghsMultiIDE;
  590. }
  591. bool cmState::UseGhsMultiIDE() const
  592. {
  593. return this->GhsMultiIDE;
  594. }
  595. void cmState::SetWatcomWMake(bool watcomWMake)
  596. {
  597. this->WatcomWMake = watcomWMake;
  598. }
  599. bool cmState::UseWatcomWMake() const
  600. {
  601. return this->WatcomWMake;
  602. }
  603. void cmState::SetMinGWMake(bool minGWMake)
  604. {
  605. this->MinGWMake = minGWMake;
  606. }
  607. bool cmState::UseMinGWMake() const
  608. {
  609. return this->MinGWMake;
  610. }
  611. void cmState::SetNMake(bool nMake)
  612. {
  613. this->NMake = nMake;
  614. }
  615. bool cmState::UseNMake() const
  616. {
  617. return this->NMake;
  618. }
  619. void cmState::SetMSYSShell(bool mSYSShell)
  620. {
  621. this->MSYSShell = mSYSShell;
  622. }
  623. bool cmState::UseMSYSShell() const
  624. {
  625. return this->MSYSShell;
  626. }
  627. void cmState::SetNinjaMulti(bool ninjaMulti)
  628. {
  629. this->NinjaMulti = ninjaMulti;
  630. }
  631. bool cmState::UseNinjaMulti() const
  632. {
  633. return this->NinjaMulti;
  634. }
  635. unsigned int cmState::GetCacheMajorVersion() const
  636. {
  637. return this->CacheManager->GetCacheMajorVersion();
  638. }
  639. unsigned int cmState::GetCacheMinorVersion() const
  640. {
  641. return this->CacheManager->GetCacheMinorVersion();
  642. }
  643. cmState::Mode cmState::GetMode() const
  644. {
  645. return this->CurrentMode;
  646. }
  647. std::string cmState::GetModeString() const
  648. {
  649. return ModeToString(this->CurrentMode);
  650. }
  651. void cmState::SetMode(cmState::Mode mode)
  652. {
  653. this->CurrentMode = mode;
  654. }
  655. std::string cmState::ModeToString(cmState::Mode mode)
  656. {
  657. switch (mode) {
  658. case Project:
  659. return "PROJECT";
  660. case Script:
  661. return "SCRIPT";
  662. case FindPackage:
  663. return "FIND_PACKAGE";
  664. case CTest:
  665. return "CTEST";
  666. case CPack:
  667. return "CPACK";
  668. case Unknown:
  669. return "UNKNOWN";
  670. }
  671. return "UNKNOWN";
  672. }
  673. std::string const& cmState::GetBinaryDirectory() const
  674. {
  675. return this->BinaryDirectory;
  676. }
  677. cmStateSnapshot cmState::CreateBaseSnapshot()
  678. {
  679. cmStateDetail::PositionType pos =
  680. this->SnapshotData.Push(this->SnapshotData.Root());
  681. pos->DirectoryParent = this->SnapshotData.Root();
  682. pos->ScopeParent = this->SnapshotData.Root();
  683. pos->SnapshotType = cmStateEnums::BaseType;
  684. pos->Keep = true;
  685. pos->BuildSystemDirectory =
  686. this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
  687. pos->ExecutionListFile =
  688. this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
  689. pos->IncludeDirectoryPosition = 0;
  690. pos->CompileDefinitionsPosition = 0;
  691. pos->CompileOptionsPosition = 0;
  692. pos->LinkOptionsPosition = 0;
  693. pos->LinkDirectoriesPosition = 0;
  694. pos->BuildSystemDirectory->DirectoryEnd = pos;
  695. pos->Policies = this->PolicyStack.Root();
  696. pos->PolicyRoot = this->PolicyStack.Root();
  697. pos->PolicyScope = this->PolicyStack.Root();
  698. assert(pos->Policies.IsValid());
  699. assert(pos->PolicyRoot.IsValid());
  700. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  701. assert(pos->Vars.IsValid());
  702. pos->Parent = this->VarTree.Root();
  703. pos->Root = this->VarTree.Root();
  704. return { this, pos };
  705. }
  706. cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
  707. cmStateSnapshot const& originSnapshot)
  708. {
  709. assert(originSnapshot.IsValid());
  710. cmStateDetail::PositionType pos =
  711. this->SnapshotData.Push(originSnapshot.Position);
  712. pos->DirectoryParent = originSnapshot.Position;
  713. pos->ScopeParent = originSnapshot.Position;
  714. pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
  715. pos->Keep = true;
  716. pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
  717. originSnapshot.Position->BuildSystemDirectory);
  718. pos->ExecutionListFile =
  719. this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
  720. pos->BuildSystemDirectory->DirectoryEnd = pos;
  721. pos->Policies = originSnapshot.Position->Policies;
  722. pos->PolicyRoot = originSnapshot.Position->Policies;
  723. pos->PolicyScope = originSnapshot.Position->Policies;
  724. assert(pos->Policies.IsValid());
  725. assert(pos->PolicyRoot.IsValid());
  726. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  727. pos->Parent = origin;
  728. pos->Root = origin;
  729. pos->Vars = this->VarTree.Push(origin);
  730. cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
  731. originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
  732. snapshot.SetDefaultDefinitions();
  733. snapshot.InitializeFromParent();
  734. snapshot.SetDirectoryDefinitions();
  735. return snapshot;
  736. }
  737. cmStateSnapshot cmState::CreateDeferCallSnapshot(
  738. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  739. {
  740. cmStateDetail::PositionType pos =
  741. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  742. pos->SnapshotType = cmStateEnums::DeferCallType;
  743. pos->Keep = false;
  744. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  745. originSnapshot.Position->ExecutionListFile, fileName);
  746. assert(originSnapshot.Position->Vars.IsValid());
  747. pos->BuildSystemDirectory->DirectoryEnd = pos;
  748. pos->PolicyScope = originSnapshot.Position->Policies;
  749. return { this, pos };
  750. }
  751. cmStateSnapshot cmState::CreateFunctionCallSnapshot(
  752. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  753. {
  754. cmStateDetail::PositionType pos =
  755. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  756. pos->ScopeParent = originSnapshot.Position;
  757. pos->SnapshotType = cmStateEnums::FunctionCallType;
  758. pos->Keep = false;
  759. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  760. originSnapshot.Position->ExecutionListFile, fileName);
  761. pos->BuildSystemDirectory->DirectoryEnd = pos;
  762. pos->PolicyScope = originSnapshot.Position->Policies;
  763. assert(originSnapshot.Position->Vars.IsValid());
  764. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  765. pos->Parent = origin;
  766. pos->Vars = this->VarTree.Push(origin);
  767. return { this, pos };
  768. }
  769. cmStateSnapshot cmState::CreateMacroCallSnapshot(
  770. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  771. {
  772. cmStateDetail::PositionType pos =
  773. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  774. pos->SnapshotType = cmStateEnums::MacroCallType;
  775. pos->Keep = false;
  776. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  777. originSnapshot.Position->ExecutionListFile, fileName);
  778. assert(originSnapshot.Position->Vars.IsValid());
  779. pos->BuildSystemDirectory->DirectoryEnd = pos;
  780. pos->PolicyScope = originSnapshot.Position->Policies;
  781. return { this, pos };
  782. }
  783. cmStateSnapshot cmState::CreateIncludeFileSnapshot(
  784. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  785. {
  786. cmStateDetail::PositionType pos =
  787. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  788. pos->SnapshotType = cmStateEnums::IncludeFileType;
  789. pos->Keep = true;
  790. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  791. originSnapshot.Position->ExecutionListFile, fileName);
  792. assert(originSnapshot.Position->Vars.IsValid());
  793. pos->BuildSystemDirectory->DirectoryEnd = pos;
  794. pos->PolicyScope = originSnapshot.Position->Policies;
  795. return { this, pos };
  796. }
  797. cmStateSnapshot cmState::CreateVariableScopeSnapshot(
  798. cmStateSnapshot const& originSnapshot)
  799. {
  800. cmStateDetail::PositionType pos =
  801. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  802. pos->ScopeParent = originSnapshot.Position;
  803. pos->SnapshotType = cmStateEnums::VariableScopeType;
  804. pos->Keep = false;
  805. pos->PolicyScope = originSnapshot.Position->Policies;
  806. assert(originSnapshot.Position->Vars.IsValid());
  807. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  808. pos->Parent = origin;
  809. pos->Vars = this->VarTree.Push(origin);
  810. assert(pos->Vars.IsValid());
  811. return { this, pos };
  812. }
  813. cmStateSnapshot cmState::CreateInlineListFileSnapshot(
  814. cmStateSnapshot const& originSnapshot, std::string const& fileName)
  815. {
  816. cmStateDetail::PositionType pos =
  817. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  818. pos->SnapshotType = cmStateEnums::InlineListFileType;
  819. pos->Keep = true;
  820. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  821. originSnapshot.Position->ExecutionListFile, fileName);
  822. pos->BuildSystemDirectory->DirectoryEnd = pos;
  823. pos->PolicyScope = originSnapshot.Position->Policies;
  824. return { this, pos };
  825. }
  826. cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
  827. cmStateSnapshot const& originSnapshot)
  828. {
  829. cmStateDetail::PositionType pos =
  830. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  831. pos->SnapshotType = cmStateEnums::PolicyScopeType;
  832. pos->Keep = false;
  833. pos->BuildSystemDirectory->DirectoryEnd = pos;
  834. pos->PolicyScope = originSnapshot.Position->Policies;
  835. return { this, pos };
  836. }
  837. cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
  838. {
  839. cmStateDetail::PositionType pos = originSnapshot.Position;
  840. cmStateDetail::PositionType prevPos = pos;
  841. ++prevPos;
  842. prevPos->IncludeDirectoryPosition =
  843. prevPos->BuildSystemDirectory->IncludeDirectories.size();
  844. prevPos->CompileDefinitionsPosition =
  845. prevPos->BuildSystemDirectory->CompileDefinitions.size();
  846. prevPos->CompileOptionsPosition =
  847. prevPos->BuildSystemDirectory->CompileOptions.size();
  848. prevPos->LinkOptionsPosition =
  849. prevPos->BuildSystemDirectory->LinkOptions.size();
  850. prevPos->LinkDirectoriesPosition =
  851. prevPos->BuildSystemDirectory->LinkDirectories.size();
  852. prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
  853. if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
  854. if (pos->Vars != prevPos->Vars) {
  855. assert(this->VarTree.IsLast(pos->Vars));
  856. this->VarTree.Pop(pos->Vars);
  857. }
  858. if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
  859. assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
  860. this->ExecutionListFiles.Pop(pos->ExecutionListFile);
  861. }
  862. this->SnapshotData.Pop(pos);
  863. }
  864. return { this, prevPos };
  865. }
  866. static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
  867. std::string& value)
  868. {
  869. // input line is: key=value
  870. static cmsys::RegularExpression reg(
  871. "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  872. // input line is: "key"=value
  873. static cmsys::RegularExpression regQuoted(
  874. "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  875. bool flag = false;
  876. if (regQuoted.find(entry)) {
  877. var = regQuoted.match(1);
  878. value = regQuoted.match(2);
  879. flag = true;
  880. } else if (reg.find(entry)) {
  881. var = reg.match(1);
  882. value = reg.match(2);
  883. flag = true;
  884. }
  885. // if value is enclosed in single quotes ('foo') then remove them
  886. // it is used to enclose trailing space or tab
  887. if (flag && value.size() >= 2 && value.front() == '\'' &&
  888. value.back() == '\'') {
  889. value = value.substr(1, value.size() - 2);
  890. }
  891. return flag;
  892. }
  893. bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
  894. std::string& value,
  895. cmStateEnums::CacheEntryType& type)
  896. {
  897. // input line is: key:type=value
  898. static cmsys::RegularExpression reg(
  899. "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  900. // input line is: "key":type=value
  901. static cmsys::RegularExpression regQuoted(
  902. "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  903. bool flag = false;
  904. if (regQuoted.find(entry)) {
  905. var = regQuoted.match(1);
  906. type = cmState::StringToCacheEntryType(regQuoted.match(2));
  907. value = regQuoted.match(3);
  908. flag = true;
  909. } else if (reg.find(entry)) {
  910. var = reg.match(1);
  911. type = cmState::StringToCacheEntryType(reg.match(2));
  912. value = reg.match(3);
  913. flag = true;
  914. }
  915. // if value is enclosed in single quotes ('foo') then remove them
  916. // it is used to enclose trailing space or tab
  917. if (flag && value.size() >= 2 && value.front() == '\'' &&
  918. value.back() == '\'') {
  919. value = value.substr(1, value.size() - 2);
  920. }
  921. if (!flag) {
  922. return ParseEntryWithoutType(entry, var, value);
  923. }
  924. return flag;
  925. }