You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1838 lines
56 KiB

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  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 "cmAlgorithms.h"
  5. #include "cmCacheManager.h"
  6. #include "cmCommand.h"
  7. #include "cmDefinitions.h"
  8. #include "cmListFileCache.h"
  9. #include "cmSystemTools.h"
  10. #include "cmTypeMacro.h"
  11. #include "cmVersion.h"
  12. #include "cmake.h"
  13. #include <algorithm>
  14. #include <assert.h>
  15. #include <cmsys/RegularExpression.hxx>
  16. #include <iterator>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <utility>
  20. static std::string const kBINARY_DIR = "BINARY_DIR";
  21. static std::string const kBUILDSYSTEM_TARGETS = "BUILDSYSTEM_TARGETS";
  22. static std::string const kSOURCE_DIR = "SOURCE_DIR";
  23. static std::string const kSUBDIRECTORIES = "SUBDIRECTORIES";
  24. struct cmState::SnapshotDataType
  25. {
  26. cmState::PositionType ScopeParent;
  27. cmState::PositionType DirectoryParent;
  28. cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
  29. cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
  30. cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
  31. cmState::SnapshotType SnapshotType;
  32. bool Keep;
  33. cmLinkedTree<std::string>::iterator ExecutionListFile;
  34. cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
  35. BuildSystemDirectory;
  36. cmLinkedTree<cmDefinitions>::iterator Vars;
  37. cmLinkedTree<cmDefinitions>::iterator Root;
  38. cmLinkedTree<cmDefinitions>::iterator Parent;
  39. std::vector<std::string>::size_type IncludeDirectoryPosition;
  40. std::vector<std::string>::size_type CompileDefinitionsPosition;
  41. std::vector<std::string>::size_type CompileOptionsPosition;
  42. };
  43. struct cmState::PolicyStackEntry : public cmPolicies::PolicyMap
  44. {
  45. typedef cmPolicies::PolicyMap derived;
  46. PolicyStackEntry(bool w = false)
  47. : derived()
  48. , Weak(w)
  49. {
  50. }
  51. PolicyStackEntry(derived const& d, bool w)
  52. : derived(d)
  53. , Weak(w)
  54. {
  55. }
  56. PolicyStackEntry(PolicyStackEntry const& r)
  57. : derived(r)
  58. , Weak(r.Weak)
  59. {
  60. }
  61. bool Weak;
  62. };
  63. struct cmState::BuildsystemDirectoryStateType
  64. {
  65. cmState::PositionType DirectoryEnd;
  66. std::string Location;
  67. std::string OutputLocation;
  68. // The top-most directories for relative path conversion. Both the
  69. // source and destination location of a relative path conversion
  70. // must be underneath one of these directories (both under source or
  71. // both under binary) in order for the relative path to be evaluated
  72. // safely by the build tools.
  73. std::string RelativePathTopSource;
  74. std::string RelativePathTopBinary;
  75. std::vector<std::string> IncludeDirectories;
  76. std::vector<cmListFileBacktrace> IncludeDirectoryBacktraces;
  77. std::vector<std::string> CompileDefinitions;
  78. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  79. std::vector<std::string> CompileOptions;
  80. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  81. std::vector<std::string> NormalTargetNames;
  82. std::string ProjectName;
  83. cmPropertyMap Properties;
  84. std::vector<cmState::Snapshot> Children;
  85. };
  86. cmState::cmState()
  87. : IsInTryCompile(false)
  88. , WindowsShell(false)
  89. , WindowsVSIDE(false)
  90. , WatcomWMake(false)
  91. , MinGWMake(false)
  92. , NMake(false)
  93. , MSYSShell(false)
  94. {
  95. this->CacheManager = new cmCacheManager;
  96. }
  97. cmState::~cmState()
  98. {
  99. delete this->CacheManager;
  100. cmDeleteAll(this->Commands);
  101. }
  102. const char* cmState::GetTargetTypeName(cmState::TargetType targetType)
  103. {
  104. switch (targetType) {
  105. case cmState::STATIC_LIBRARY:
  106. return "STATIC_LIBRARY";
  107. case cmState::MODULE_LIBRARY:
  108. return "MODULE_LIBRARY";
  109. case cmState::SHARED_LIBRARY:
  110. return "SHARED_LIBRARY";
  111. case cmState::OBJECT_LIBRARY:
  112. return "OBJECT_LIBRARY";
  113. case cmState::EXECUTABLE:
  114. return "EXECUTABLE";
  115. case cmState::UTILITY:
  116. return "UTILITY";
  117. case cmState::GLOBAL_TARGET:
  118. return "GLOBAL_TARGET";
  119. case cmState::INTERFACE_LIBRARY:
  120. return "INTERFACE_LIBRARY";
  121. case cmState::UNKNOWN_LIBRARY:
  122. return "UNKNOWN_LIBRARY";
  123. }
  124. assert(0 && "Unexpected target type");
  125. return CM_NULLPTR;
  126. }
  127. const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH",
  128. "STRING", "INTERNAL", "STATIC",
  129. "UNINITIALIZED", CM_NULLPTR };
  130. const char* cmState::CacheEntryTypeToString(cmState::CacheEntryType type)
  131. {
  132. if (type > 6) {
  133. return cmCacheEntryTypes[6];
  134. }
  135. return cmCacheEntryTypes[type];
  136. }
  137. cmState::CacheEntryType cmState::StringToCacheEntryType(const char* s)
  138. {
  139. int i = 0;
  140. while (cmCacheEntryTypes[i]) {
  141. if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
  142. return static_cast<cmState::CacheEntryType>(i);
  143. }
  144. ++i;
  145. }
  146. return STRING;
  147. }
  148. bool cmState::IsCacheEntryType(std::string const& key)
  149. {
  150. for (int i = 0; cmCacheEntryTypes[i]; ++i) {
  151. if (strcmp(key.c_str(), cmCacheEntryTypes[i]) == 0) {
  152. return true;
  153. }
  154. }
  155. return false;
  156. }
  157. bool cmState::LoadCache(const std::string& path, bool internal,
  158. std::set<std::string>& excludes,
  159. std::set<std::string>& includes)
  160. {
  161. return this->CacheManager->LoadCache(path, internal, excludes, includes);
  162. }
  163. bool cmState::SaveCache(const std::string& path)
  164. {
  165. return this->CacheManager->SaveCache(path);
  166. }
  167. bool cmState::DeleteCache(const std::string& path)
  168. {
  169. return this->CacheManager->DeleteCache(path);
  170. }
  171. std::vector<std::string> cmState::GetCacheEntryKeys() const
  172. {
  173. std::vector<std::string> definitions;
  174. definitions.reserve(this->CacheManager->GetSize());
  175. cmCacheManager::CacheIterator cit = this->CacheManager->GetCacheIterator();
  176. for (cit.Begin(); !cit.IsAtEnd(); cit.Next()) {
  177. definitions.push_back(cit.GetName());
  178. }
  179. return definitions;
  180. }
  181. const char* cmState::GetCacheEntryValue(std::string const& key) const
  182. {
  183. cmCacheManager::CacheEntry* e = this->CacheManager->GetCacheEntry(key);
  184. if (!e) {
  185. return CM_NULLPTR;
  186. }
  187. return e->Value.c_str();
  188. }
  189. const char* cmState::GetInitializedCacheValue(std::string const& key) const
  190. {
  191. return this->CacheManager->GetInitializedCacheValue(key);
  192. }
  193. cmState::CacheEntryType cmState::GetCacheEntryType(
  194. std::string const& key) const
  195. {
  196. cmCacheManager::CacheIterator it =
  197. this->CacheManager->GetCacheIterator(key.c_str());
  198. return it.GetType();
  199. }
  200. void cmState::SetCacheEntryValue(std::string const& key,
  201. std::string const& value)
  202. {
  203. this->CacheManager->SetCacheEntryValue(key, value);
  204. }
  205. void cmState::SetCacheEntryProperty(std::string const& key,
  206. std::string const& propertyName,
  207. std::string const& value)
  208. {
  209. cmCacheManager::CacheIterator it =
  210. this->CacheManager->GetCacheIterator(key.c_str());
  211. it.SetProperty(propertyName, value.c_str());
  212. }
  213. void cmState::SetCacheEntryBoolProperty(std::string const& key,
  214. std::string const& propertyName,
  215. bool value)
  216. {
  217. cmCacheManager::CacheIterator it =
  218. this->CacheManager->GetCacheIterator(key.c_str());
  219. it.SetProperty(propertyName, value);
  220. }
  221. std::vector<std::string> cmState::GetCacheEntryPropertyList(
  222. const std::string& key)
  223. {
  224. cmCacheManager::CacheIterator it =
  225. this->CacheManager->GetCacheIterator(key.c_str());
  226. return it.GetPropertyList();
  227. }
  228. const char* cmState::GetCacheEntryProperty(std::string const& key,
  229. std::string const& propertyName)
  230. {
  231. cmCacheManager::CacheIterator it =
  232. this->CacheManager->GetCacheIterator(key.c_str());
  233. if (!it.PropertyExists(propertyName)) {
  234. return CM_NULLPTR;
  235. }
  236. return it.GetProperty(propertyName);
  237. }
  238. bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
  239. std::string const& propertyName)
  240. {
  241. return this->CacheManager->GetCacheIterator(key.c_str())
  242. .GetPropertyAsBool(propertyName);
  243. }
  244. void cmState::AddCacheEntry(const std::string& key, const char* value,
  245. const char* helpString,
  246. cmState::CacheEntryType type)
  247. {
  248. this->CacheManager->AddCacheEntry(key, value, helpString, type);
  249. }
  250. void cmState::RemoveCacheEntry(std::string const& key)
  251. {
  252. this->CacheManager->RemoveCacheEntry(key);
  253. }
  254. void cmState::AppendCacheEntryProperty(const std::string& key,
  255. const std::string& property,
  256. const std::string& value, bool asString)
  257. {
  258. this->CacheManager->GetCacheIterator(key.c_str())
  259. .AppendProperty(property, value.c_str(), asString);
  260. }
  261. void cmState::RemoveCacheEntryProperty(std::string const& key,
  262. std::string const& propertyName)
  263. {
  264. this->CacheManager->GetCacheIterator(key.c_str())
  265. .SetProperty(propertyName, (void*)CM_NULLPTR);
  266. }
  267. cmState::Snapshot cmState::Reset()
  268. {
  269. this->GlobalProperties.clear();
  270. this->PropertyDefinitions.clear();
  271. PositionType pos = this->SnapshotData.Truncate();
  272. this->ExecutionListFiles.Truncate();
  273. {
  274. cmLinkedTree<BuildsystemDirectoryStateType>::iterator it =
  275. this->BuildsystemDirectory.Truncate();
  276. it->IncludeDirectories.clear();
  277. it->IncludeDirectoryBacktraces.clear();
  278. it->CompileDefinitions.clear();
  279. it->CompileDefinitionsBacktraces.clear();
  280. it->CompileOptions.clear();
  281. it->CompileOptionsBacktraces.clear();
  282. it->DirectoryEnd = pos;
  283. it->NormalTargetNames.clear();
  284. it->Properties.clear();
  285. it->Children.clear();
  286. }
  287. this->PolicyStack.Clear();
  288. pos->Policies = this->PolicyStack.Root();
  289. pos->PolicyRoot = this->PolicyStack.Root();
  290. pos->PolicyScope = this->PolicyStack.Root();
  291. assert(pos->Policies.IsValid());
  292. assert(pos->PolicyRoot.IsValid());
  293. {
  294. std::string srcDir =
  295. cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
  296. std::string binDir =
  297. cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
  298. this->VarTree.Clear();
  299. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  300. pos->Parent = this->VarTree.Root();
  301. pos->Root = this->VarTree.Root();
  302. pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str());
  303. pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str());
  304. }
  305. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
  306. true);
  307. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
  308. true);
  309. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
  310. true);
  311. this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
  312. true);
  313. this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
  314. this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
  315. return Snapshot(this, pos);
  316. }
  317. void cmState::DefineProperty(const std::string& name,
  318. cmProperty::ScopeType scope,
  319. const char* ShortDescription,
  320. const char* FullDescription, bool chained)
  321. {
  322. this->PropertyDefinitions[scope].DefineProperty(
  323. name, scope, ShortDescription, FullDescription, chained);
  324. }
  325. cmPropertyDefinition const* cmState::GetPropertyDefinition(
  326. const std::string& name, cmProperty::ScopeType scope) const
  327. {
  328. if (this->IsPropertyDefined(name, scope)) {
  329. cmPropertyDefinitionMap const& defs =
  330. this->PropertyDefinitions.find(scope)->second;
  331. return &defs.find(name)->second;
  332. }
  333. return CM_NULLPTR;
  334. }
  335. bool cmState::IsPropertyDefined(const std::string& name,
  336. cmProperty::ScopeType scope) const
  337. {
  338. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  339. this->PropertyDefinitions.find(scope);
  340. if (it == this->PropertyDefinitions.end()) {
  341. return false;
  342. }
  343. return it->second.IsPropertyDefined(name);
  344. }
  345. bool cmState::IsPropertyChained(const std::string& name,
  346. cmProperty::ScopeType scope) const
  347. {
  348. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it =
  349. this->PropertyDefinitions.find(scope);
  350. if (it == this->PropertyDefinitions.end()) {
  351. return false;
  352. }
  353. return it->second.IsPropertyChained(name);
  354. }
  355. void cmState::SetLanguageEnabled(std::string const& l)
  356. {
  357. std::vector<std::string>::iterator it = std::lower_bound(
  358. this->EnabledLanguages.begin(), this->EnabledLanguages.end(), l);
  359. if (it == this->EnabledLanguages.end() || *it != l) {
  360. this->EnabledLanguages.insert(it, l);
  361. }
  362. }
  363. bool cmState::GetLanguageEnabled(std::string const& l) const
  364. {
  365. return std::binary_search(this->EnabledLanguages.begin(),
  366. this->EnabledLanguages.end(), l);
  367. }
  368. std::vector<std::string> cmState::GetEnabledLanguages() const
  369. {
  370. return this->EnabledLanguages;
  371. }
  372. void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
  373. {
  374. this->EnabledLanguages = langs;
  375. }
  376. void cmState::ClearEnabledLanguages()
  377. {
  378. this->EnabledLanguages.clear();
  379. }
  380. bool cmState::GetIsInTryCompile() const
  381. {
  382. return this->IsInTryCompile;
  383. }
  384. void cmState::SetIsInTryCompile(bool b)
  385. {
  386. this->IsInTryCompile = b;
  387. }
  388. void cmState::RenameCommand(std::string const& oldName,
  389. std::string const& newName)
  390. {
  391. // if the command already exists, free the old one
  392. std::string sOldName = cmSystemTools::LowerCase(oldName);
  393. std::string sNewName = cmSystemTools::LowerCase(newName);
  394. std::map<std::string, cmCommand*>::iterator pos =
  395. this->Commands.find(sOldName);
  396. if (pos == this->Commands.end()) {
  397. return;
  398. }
  399. cmCommand* cmd = pos->second;
  400. pos = this->Commands.find(sNewName);
  401. if (pos != this->Commands.end()) {
  402. delete pos->second;
  403. this->Commands.erase(pos);
  404. }
  405. this->Commands.insert(std::make_pair(sNewName, cmd));
  406. pos = this->Commands.find(sOldName);
  407. this->Commands.erase(pos);
  408. }
  409. void cmState::AddCommand(cmCommand* command)
  410. {
  411. std::string name = cmSystemTools::LowerCase(command->GetName());
  412. // if the command already exists, free the old one
  413. std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name);
  414. if (pos != this->Commands.end()) {
  415. delete pos->second;
  416. this->Commands.erase(pos);
  417. }
  418. this->Commands.insert(std::make_pair(name, command));
  419. }
  420. void cmState::RemoveUnscriptableCommands()
  421. {
  422. std::vector<std::string> unscriptableCommands;
  423. for (std::map<std::string, cmCommand*>::iterator pos =
  424. this->Commands.begin();
  425. pos != this->Commands.end();) {
  426. if (!pos->second->IsScriptable()) {
  427. delete pos->second;
  428. this->Commands.erase(pos++);
  429. } else {
  430. ++pos;
  431. }
  432. }
  433. }
  434. cmCommand* cmState::GetCommand(std::string const& name) const
  435. {
  436. cmCommand* command = CM_NULLPTR;
  437. std::string sName = cmSystemTools::LowerCase(name);
  438. std::map<std::string, cmCommand*>::const_iterator pos =
  439. this->Commands.find(sName);
  440. if (pos != this->Commands.end()) {
  441. command = (*pos).second;
  442. }
  443. return command;
  444. }
  445. std::vector<std::string> cmState::GetCommandNames() const
  446. {
  447. std::vector<std::string> commandNames;
  448. commandNames.reserve(this->Commands.size());
  449. std::map<std::string, cmCommand*>::const_iterator cmds =
  450. this->Commands.begin();
  451. for (; cmds != this->Commands.end(); ++cmds) {
  452. commandNames.push_back(cmds->first);
  453. }
  454. return commandNames;
  455. }
  456. void cmState::RemoveUserDefinedCommands()
  457. {
  458. std::vector<cmCommand*> renamedCommands;
  459. for (std::map<std::string, cmCommand*>::iterator j = this->Commands.begin();
  460. j != this->Commands.end();) {
  461. if (j->second->IsA("cmMacroHelperCommand") ||
  462. j->second->IsA("cmFunctionHelperCommand")) {
  463. delete j->second;
  464. this->Commands.erase(j++);
  465. } else if (j->first != j->second->GetName()) {
  466. renamedCommands.push_back(j->second);
  467. this->Commands.erase(j++);
  468. } else {
  469. ++j;
  470. }
  471. }
  472. for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin();
  473. it != renamedCommands.end(); ++it) {
  474. this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  475. }
  476. }
  477. void cmState::SetGlobalProperty(const std::string& prop, const char* value)
  478. {
  479. this->GlobalProperties.SetProperty(prop, value);
  480. }
  481. void cmState::AppendGlobalProperty(const std::string& prop, const char* value,
  482. bool asString)
  483. {
  484. this->GlobalProperties.AppendProperty(prop, value, asString);
  485. }
  486. const char* cmState::GetGlobalProperty(const std::string& prop)
  487. {
  488. if (prop == "CACHE_VARIABLES") {
  489. std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
  490. this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
  491. } else if (prop == "COMMANDS") {
  492. std::vector<std::string> commands = this->GetCommandNames();
  493. this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
  494. } else if (prop == "IN_TRY_COMPILE") {
  495. this->SetGlobalProperty("IN_TRY_COMPILE",
  496. this->IsInTryCompile ? "1" : "0");
  497. } else if (prop == "ENABLED_LANGUAGES") {
  498. std::string langs;
  499. langs = cmJoin(this->EnabledLanguages, ";");
  500. this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
  501. }
  502. #define STRING_LIST_ELEMENT(F) ";" #F
  503. if (prop == "CMAKE_C_KNOWN_FEATURES") {
  504. return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
  505. }
  506. if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
  507. return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
  508. }
  509. #undef STRING_LIST_ELEMENT
  510. return this->GlobalProperties.GetPropertyValue(prop);
  511. }
  512. bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
  513. {
  514. return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
  515. }
  516. void cmState::SetSourceDirectory(std::string const& sourceDirectory)
  517. {
  518. this->SourceDirectory = sourceDirectory;
  519. cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
  520. }
  521. const char* cmState::GetSourceDirectory() const
  522. {
  523. return this->SourceDirectory.c_str();
  524. }
  525. void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
  526. {
  527. this->BinaryDirectory = binaryDirectory;
  528. cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
  529. }
  530. void cmState::SetWindowsShell(bool windowsShell)
  531. {
  532. this->WindowsShell = windowsShell;
  533. }
  534. bool cmState::UseWindowsShell() const
  535. {
  536. return this->WindowsShell;
  537. }
  538. void cmState::SetWindowsVSIDE(bool windowsVSIDE)
  539. {
  540. this->WindowsVSIDE = windowsVSIDE;
  541. }
  542. bool cmState::UseWindowsVSIDE() const
  543. {
  544. return this->WindowsVSIDE;
  545. }
  546. void cmState::SetWatcomWMake(bool watcomWMake)
  547. {
  548. this->WatcomWMake = watcomWMake;
  549. }
  550. bool cmState::UseWatcomWMake() const
  551. {
  552. return this->WatcomWMake;
  553. }
  554. void cmState::SetMinGWMake(bool minGWMake)
  555. {
  556. this->MinGWMake = minGWMake;
  557. }
  558. bool cmState::UseMinGWMake() const
  559. {
  560. return this->MinGWMake;
  561. }
  562. void cmState::SetNMake(bool nMake)
  563. {
  564. this->NMake = nMake;
  565. }
  566. bool cmState::UseNMake() const
  567. {
  568. return this->NMake;
  569. }
  570. void cmState::SetMSYSShell(bool mSYSShell)
  571. {
  572. this->MSYSShell = mSYSShell;
  573. }
  574. bool cmState::UseMSYSShell() const
  575. {
  576. return this->MSYSShell;
  577. }
  578. unsigned int cmState::GetCacheMajorVersion() const
  579. {
  580. return this->CacheManager->GetCacheMajorVersion();
  581. }
  582. unsigned int cmState::GetCacheMinorVersion() const
  583. {
  584. return this->CacheManager->GetCacheMinorVersion();
  585. }
  586. const char* cmState::GetBinaryDirectory() const
  587. {
  588. return this->BinaryDirectory.c_str();
  589. }
  590. void cmState::Directory::ComputeRelativePathTopSource()
  591. {
  592. // Relative path conversion inside the source tree is not used to
  593. // construct relative paths passed to build tools so it is safe to use
  594. // even when the source is a network path.
  595. cmState::Snapshot snapshot = this->Snapshot_;
  596. std::vector<cmState::Snapshot> snapshots;
  597. snapshots.push_back(snapshot);
  598. while (true) {
  599. snapshot = snapshot.GetBuildsystemDirectoryParent();
  600. if (snapshot.IsValid()) {
  601. snapshots.push_back(snapshot);
  602. } else {
  603. break;
  604. }
  605. }
  606. std::string result = snapshots.front().GetDirectory().GetCurrentSource();
  607. for (std::vector<cmState::Snapshot>::const_iterator it =
  608. snapshots.begin() + 1;
  609. it != snapshots.end(); ++it) {
  610. std::string currentSource = it->GetDirectory().GetCurrentSource();
  611. if (cmSystemTools::IsSubDirectory(result, currentSource)) {
  612. result = currentSource;
  613. }
  614. }
  615. this->DirectoryState->RelativePathTopSource = result;
  616. }
  617. void cmState::Directory::ComputeRelativePathTopBinary()
  618. {
  619. cmState::Snapshot snapshot = this->Snapshot_;
  620. std::vector<cmState::Snapshot> snapshots;
  621. snapshots.push_back(snapshot);
  622. while (true) {
  623. snapshot = snapshot.GetBuildsystemDirectoryParent();
  624. if (snapshot.IsValid()) {
  625. snapshots.push_back(snapshot);
  626. } else {
  627. break;
  628. }
  629. }
  630. std::string result = snapshots.front().GetDirectory().GetCurrentBinary();
  631. for (std::vector<cmState::Snapshot>::const_iterator it =
  632. snapshots.begin() + 1;
  633. it != snapshots.end(); ++it) {
  634. std::string currentBinary = it->GetDirectory().GetCurrentBinary();
  635. if (cmSystemTools::IsSubDirectory(result, currentBinary)) {
  636. result = currentBinary;
  637. }
  638. }
  639. // The current working directory on Windows cannot be a network
  640. // path. Therefore relative paths cannot work when the binary tree
  641. // is a network path.
  642. if (result.size() < 2 || result.substr(0, 2) != "//") {
  643. this->DirectoryState->RelativePathTopBinary = result;
  644. } else {
  645. this->DirectoryState->RelativePathTopBinary = "";
  646. }
  647. }
  648. cmState::Snapshot cmState::CreateBaseSnapshot()
  649. {
  650. PositionType pos = this->SnapshotData.Push(this->SnapshotData.Root());
  651. pos->DirectoryParent = this->SnapshotData.Root();
  652. pos->ScopeParent = this->SnapshotData.Root();
  653. pos->SnapshotType = BaseType;
  654. pos->Keep = true;
  655. pos->BuildSystemDirectory =
  656. this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
  657. pos->ExecutionListFile =
  658. this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
  659. pos->IncludeDirectoryPosition = 0;
  660. pos->CompileDefinitionsPosition = 0;
  661. pos->CompileOptionsPosition = 0;
  662. pos->BuildSystemDirectory->DirectoryEnd = pos;
  663. pos->Policies = this->PolicyStack.Root();
  664. pos->PolicyRoot = this->PolicyStack.Root();
  665. pos->PolicyScope = this->PolicyStack.Root();
  666. assert(pos->Policies.IsValid());
  667. assert(pos->PolicyRoot.IsValid());
  668. pos->Vars = this->VarTree.Push(this->VarTree.Root());
  669. assert(pos->Vars.IsValid());
  670. pos->Parent = this->VarTree.Root();
  671. pos->Root = this->VarTree.Root();
  672. return cmState::Snapshot(this, pos);
  673. }
  674. cmState::Snapshot cmState::CreateBuildsystemDirectorySnapshot(
  675. Snapshot originSnapshot)
  676. {
  677. assert(originSnapshot.IsValid());
  678. PositionType pos = this->SnapshotData.Push(originSnapshot.Position);
  679. pos->DirectoryParent = originSnapshot.Position;
  680. pos->ScopeParent = originSnapshot.Position;
  681. pos->SnapshotType = BuildsystemDirectoryType;
  682. pos->Keep = true;
  683. pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
  684. originSnapshot.Position->BuildSystemDirectory);
  685. pos->ExecutionListFile =
  686. this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
  687. pos->BuildSystemDirectory->DirectoryEnd = pos;
  688. pos->Policies = originSnapshot.Position->Policies;
  689. pos->PolicyRoot = originSnapshot.Position->Policies;
  690. pos->PolicyScope = originSnapshot.Position->Policies;
  691. assert(pos->Policies.IsValid());
  692. assert(pos->PolicyRoot.IsValid());
  693. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  694. pos->Parent = origin;
  695. pos->Root = origin;
  696. pos->Vars = this->VarTree.Push(origin);
  697. cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
  698. originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
  699. snapshot.SetDefaultDefinitions();
  700. snapshot.InitializeFromParent();
  701. snapshot.SetDirectoryDefinitions();
  702. return snapshot;
  703. }
  704. cmState::Snapshot cmState::CreateFunctionCallSnapshot(
  705. cmState::Snapshot originSnapshot, std::string const& fileName)
  706. {
  707. PositionType pos =
  708. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  709. pos->ScopeParent = originSnapshot.Position;
  710. pos->SnapshotType = FunctionCallType;
  711. pos->Keep = false;
  712. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  713. originSnapshot.Position->ExecutionListFile, fileName);
  714. pos->BuildSystemDirectory->DirectoryEnd = pos;
  715. pos->PolicyScope = originSnapshot.Position->Policies;
  716. assert(originSnapshot.Position->Vars.IsValid());
  717. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  718. pos->Parent = origin;
  719. pos->Vars = this->VarTree.Push(origin);
  720. return cmState::Snapshot(this, pos);
  721. }
  722. cmState::Snapshot cmState::CreateMacroCallSnapshot(
  723. cmState::Snapshot originSnapshot, std::string const& fileName)
  724. {
  725. PositionType pos =
  726. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  727. pos->SnapshotType = MacroCallType;
  728. pos->Keep = false;
  729. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  730. originSnapshot.Position->ExecutionListFile, fileName);
  731. assert(originSnapshot.Position->Vars.IsValid());
  732. pos->BuildSystemDirectory->DirectoryEnd = pos;
  733. pos->PolicyScope = originSnapshot.Position->Policies;
  734. return cmState::Snapshot(this, pos);
  735. }
  736. cmState::Snapshot cmState::CreateIncludeFileSnapshot(
  737. cmState::Snapshot originSnapshot, const std::string& fileName)
  738. {
  739. PositionType pos =
  740. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  741. pos->SnapshotType = IncludeFileType;
  742. pos->Keep = true;
  743. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  744. originSnapshot.Position->ExecutionListFile, fileName);
  745. assert(originSnapshot.Position->Vars.IsValid());
  746. pos->BuildSystemDirectory->DirectoryEnd = pos;
  747. pos->PolicyScope = originSnapshot.Position->Policies;
  748. return cmState::Snapshot(this, pos);
  749. }
  750. cmState::Snapshot cmState::CreateVariableScopeSnapshot(
  751. cmState::Snapshot originSnapshot)
  752. {
  753. PositionType pos =
  754. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  755. pos->ScopeParent = originSnapshot.Position;
  756. pos->SnapshotType = VariableScopeType;
  757. pos->Keep = false;
  758. pos->PolicyScope = originSnapshot.Position->Policies;
  759. assert(originSnapshot.Position->Vars.IsValid());
  760. cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
  761. pos->Parent = origin;
  762. pos->Vars = this->VarTree.Push(origin);
  763. assert(pos->Vars.IsValid());
  764. return cmState::Snapshot(this, pos);
  765. }
  766. cmState::Snapshot cmState::CreateInlineListFileSnapshot(
  767. cmState::Snapshot originSnapshot, const std::string& fileName)
  768. {
  769. PositionType pos =
  770. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  771. pos->SnapshotType = InlineListFileType;
  772. pos->Keep = true;
  773. pos->ExecutionListFile = this->ExecutionListFiles.Push(
  774. originSnapshot.Position->ExecutionListFile, fileName);
  775. pos->BuildSystemDirectory->DirectoryEnd = pos;
  776. pos->PolicyScope = originSnapshot.Position->Policies;
  777. return cmState::Snapshot(this, pos);
  778. }
  779. cmState::Snapshot cmState::CreatePolicyScopeSnapshot(
  780. cmState::Snapshot originSnapshot)
  781. {
  782. PositionType pos =
  783. this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
  784. pos->SnapshotType = PolicyScopeType;
  785. pos->Keep = false;
  786. pos->BuildSystemDirectory->DirectoryEnd = pos;
  787. pos->PolicyScope = originSnapshot.Position->Policies;
  788. return cmState::Snapshot(this, pos);
  789. }
  790. cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
  791. {
  792. PositionType pos = originSnapshot.Position;
  793. PositionType prevPos = pos;
  794. ++prevPos;
  795. prevPos->IncludeDirectoryPosition =
  796. prevPos->BuildSystemDirectory->IncludeDirectories.size();
  797. prevPos->CompileDefinitionsPosition =
  798. prevPos->BuildSystemDirectory->CompileDefinitions.size();
  799. prevPos->CompileOptionsPosition =
  800. prevPos->BuildSystemDirectory->CompileOptions.size();
  801. prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
  802. if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
  803. if (pos->Vars != prevPos->Vars) {
  804. assert(this->VarTree.IsLast(pos->Vars));
  805. this->VarTree.Pop(pos->Vars);
  806. }
  807. if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
  808. assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
  809. this->ExecutionListFiles.Pop(pos->ExecutionListFile);
  810. }
  811. this->SnapshotData.Pop(pos);
  812. }
  813. return Snapshot(this, prevPos);
  814. }
  815. cmState::Snapshot::Snapshot(cmState* state)
  816. : State(state)
  817. , Position()
  818. {
  819. }
  820. std::vector<cmState::Snapshot> cmState::Snapshot::GetChildren()
  821. {
  822. return this->Position->BuildSystemDirectory->Children;
  823. }
  824. cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  825. : State(state)
  826. , Position(position)
  827. {
  828. }
  829. cmState::SnapshotType cmState::Snapshot::GetType() const
  830. {
  831. return this->Position->SnapshotType;
  832. }
  833. const char* cmState::Directory::GetCurrentSource() const
  834. {
  835. return this->DirectoryState->Location.c_str();
  836. }
  837. void cmState::Directory::SetCurrentSource(std::string const& dir)
  838. {
  839. std::string& loc = this->DirectoryState->Location;
  840. loc = dir;
  841. cmSystemTools::ConvertToUnixSlashes(loc);
  842. loc = cmSystemTools::CollapseFullPath(loc);
  843. this->ComputeRelativePathTopSource();
  844. this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc);
  845. }
  846. const char* cmState::Directory::GetCurrentBinary() const
  847. {
  848. return this->DirectoryState->OutputLocation.c_str();
  849. }
  850. void cmState::Directory::SetCurrentBinary(std::string const& dir)
  851. {
  852. std::string& loc = this->DirectoryState->OutputLocation;
  853. loc = dir;
  854. cmSystemTools::ConvertToUnixSlashes(loc);
  855. loc = cmSystemTools::CollapseFullPath(loc);
  856. this->ComputeRelativePathTopBinary();
  857. this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc);
  858. }
  859. void cmState::Snapshot::SetListFile(const std::string& listfile)
  860. {
  861. *this->Position->ExecutionListFile = listfile;
  862. }
  863. const char* cmState::Directory::GetRelativePathTopSource() const
  864. {
  865. return this->DirectoryState->RelativePathTopSource.c_str();
  866. }
  867. const char* cmState::Directory::GetRelativePathTopBinary() const
  868. {
  869. return this->DirectoryState->RelativePathTopBinary.c_str();
  870. }
  871. void cmState::Directory::SetRelativePathTopSource(const char* dir)
  872. {
  873. this->DirectoryState->RelativePathTopSource = dir;
  874. }
  875. void cmState::Directory::SetRelativePathTopBinary(const char* dir)
  876. {
  877. this->DirectoryState->RelativePathTopBinary = dir;
  878. }
  879. std::string cmState::Snapshot::GetExecutionListFile() const
  880. {
  881. return *this->Position->ExecutionListFile;
  882. }
  883. bool cmState::Snapshot::IsValid() const
  884. {
  885. return this->State && this->Position.IsValid()
  886. ? this->Position != this->State->SnapshotData.Root()
  887. : false;
  888. }
  889. cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
  890. {
  891. Snapshot snapshot;
  892. if (!this->State || this->Position == this->State->SnapshotData.Root()) {
  893. return snapshot;
  894. }
  895. PositionType parentPos = this->Position->DirectoryParent;
  896. if (parentPos != this->State->SnapshotData.Root()) {
  897. snapshot =
  898. Snapshot(this->State, parentPos->BuildSystemDirectory->DirectoryEnd);
  899. }
  900. return snapshot;
  901. }
  902. cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
  903. {
  904. assert(this->State);
  905. assert(this->Position != this->State->SnapshotData.Root());
  906. Snapshot snapshot;
  907. PositionType parentPos = this->Position;
  908. while (parentPos->SnapshotType == cmState::PolicyScopeType ||
  909. parentPos->SnapshotType == cmState::VariableScopeType) {
  910. ++parentPos;
  911. }
  912. if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType ||
  913. parentPos->SnapshotType == cmState::BaseType) {
  914. return snapshot;
  915. }
  916. ++parentPos;
  917. while (parentPos->SnapshotType == cmState::PolicyScopeType ||
  918. parentPos->SnapshotType == cmState::VariableScopeType) {
  919. ++parentPos;
  920. }
  921. if (parentPos == this->State->SnapshotData.Root()) {
  922. return snapshot;
  923. }
  924. snapshot = Snapshot(this->State, parentPos);
  925. return snapshot;
  926. }
  927. cmState::Snapshot cmState::Snapshot::GetCallStackBottom() const
  928. {
  929. assert(this->State);
  930. assert(this->Position != this->State->SnapshotData.Root());
  931. PositionType pos = this->Position;
  932. while (pos->SnapshotType != cmState::BaseType &&
  933. pos->SnapshotType != cmState::BuildsystemDirectoryType &&
  934. pos != this->State->SnapshotData.Root()) {
  935. ++pos;
  936. }
  937. return Snapshot(this->State, pos);
  938. }
  939. void cmState::Snapshot::PushPolicy(cmPolicies::PolicyMap entry, bool weak)
  940. {
  941. PositionType pos = this->Position;
  942. pos->Policies = this->State->PolicyStack.Push(pos->Policies,
  943. PolicyStackEntry(entry, weak));
  944. }
  945. bool cmState::Snapshot::PopPolicy()
  946. {
  947. PositionType pos = this->Position;
  948. if (pos->Policies == pos->PolicyScope) {
  949. return false;
  950. }
  951. pos->Policies = this->State->PolicyStack.Pop(pos->Policies);
  952. return true;
  953. }
  954. bool cmState::Snapshot::CanPopPolicyScope()
  955. {
  956. return this->Position->Policies == this->Position->PolicyScope;
  957. }
  958. void cmState::Snapshot::SetPolicy(cmPolicies::PolicyID id,
  959. cmPolicies::PolicyStatus status)
  960. {
  961. // Update the policy stack from the top to the top-most strong entry.
  962. bool previous_was_weak = true;
  963. for (cmLinkedTree<PolicyStackEntry>::iterator psi = this->Position->Policies;
  964. previous_was_weak && psi != this->Position->PolicyRoot; ++psi) {
  965. psi->Set(id, status);
  966. previous_was_weak = psi->Weak;
  967. }
  968. }
  969. cmPolicies::PolicyStatus cmState::Snapshot::GetPolicy(
  970. cmPolicies::PolicyID id) const
  971. {
  972. cmPolicies::PolicyStatus status = cmPolicies::GetPolicyStatus(id);
  973. if (status == cmPolicies::REQUIRED_ALWAYS ||
  974. status == cmPolicies::REQUIRED_IF_USED) {
  975. return status;
  976. }
  977. cmLinkedTree<BuildsystemDirectoryStateType>::iterator dir =
  978. this->Position->BuildSystemDirectory;
  979. while (true) {
  980. assert(dir.IsValid());
  981. cmLinkedTree<PolicyStackEntry>::iterator leaf =
  982. dir->DirectoryEnd->Policies;
  983. cmLinkedTree<PolicyStackEntry>::iterator root =
  984. dir->DirectoryEnd->PolicyRoot;
  985. for (; leaf != root; ++leaf) {
  986. if (leaf->IsDefined(id)) {
  987. status = leaf->Get(id);
  988. return status;
  989. }
  990. }
  991. cmState::PositionType e = dir->DirectoryEnd;
  992. cmState::PositionType p = e->DirectoryParent;
  993. if (p == this->State->SnapshotData.Root()) {
  994. break;
  995. }
  996. dir = p->BuildSystemDirectory;
  997. }
  998. return status;
  999. }
  1000. bool cmState::Snapshot::HasDefinedPolicyCMP0011()
  1001. {
  1002. return !this->Position->Policies->IsEmpty();
  1003. }
  1004. const char* cmState::Snapshot::GetDefinition(std::string const& name) const
  1005. {
  1006. assert(this->Position->Vars.IsValid());
  1007. return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
  1008. }
  1009. bool cmState::Snapshot::IsInitialized(std::string const& name) const
  1010. {
  1011. return cmDefinitions::HasKey(name, this->Position->Vars,
  1012. this->Position->Root);
  1013. }
  1014. void cmState::Snapshot::SetDefinition(std::string const& name,
  1015. std::string const& value)
  1016. {
  1017. this->Position->Vars->Set(name, value.c_str());
  1018. }
  1019. void cmState::Snapshot::RemoveDefinition(std::string const& name)
  1020. {
  1021. this->Position->Vars->Set(name, CM_NULLPTR);
  1022. }
  1023. std::vector<std::string> cmState::Snapshot::UnusedKeys() const
  1024. {
  1025. return this->Position->Vars->UnusedKeys();
  1026. }
  1027. std::vector<std::string> cmState::Snapshot::ClosureKeys() const
  1028. {
  1029. return cmDefinitions::ClosureKeys(this->Position->Vars,
  1030. this->Position->Root);
  1031. }
  1032. bool cmState::Snapshot::RaiseScope(std::string const& var, const char* varDef)
  1033. {
  1034. if (this->Position->ScopeParent == this->Position->DirectoryParent) {
  1035. Snapshot parentDir = this->GetBuildsystemDirectoryParent();
  1036. if (!parentDir.IsValid()) {
  1037. return false;
  1038. }
  1039. // Update the definition in the parent directory top scope. This
  1040. // directory's scope was initialized by the closure of the parent
  1041. // scope, so we do not need to localize the definition first.
  1042. if (varDef) {
  1043. parentDir.SetDefinition(var, varDef);
  1044. } else {
  1045. parentDir.RemoveDefinition(var);
  1046. }
  1047. return true;
  1048. }
  1049. // First localize the definition in the current scope.
  1050. cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root);
  1051. // Now update the definition in the parent scope.
  1052. this->Position->Parent->Set(var, varDef);
  1053. return true;
  1054. }
  1055. static const std::string cmPropertySentinal = std::string();
  1056. template <typename T, typename U, typename V>
  1057. void InitializeContentFromParent(T& parentContent, T& thisContent,
  1058. U& parentBacktraces, U& thisBacktraces,
  1059. V& contentEndPosition)
  1060. {
  1061. std::vector<std::string>::const_iterator parentBegin = parentContent.begin();
  1062. std::vector<std::string>::const_iterator parentEnd = parentContent.end();
  1063. std::vector<std::string>::const_reverse_iterator parentRbegin =
  1064. cmMakeReverseIterator(parentEnd);
  1065. std::vector<std::string>::const_reverse_iterator parentRend =
  1066. parentContent.rend();
  1067. parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal);
  1068. std::vector<std::string>::const_iterator parentIt = parentRbegin.base();
  1069. thisContent = std::vector<std::string>(parentIt, parentEnd);
  1070. std::vector<cmListFileBacktrace>::const_iterator btIt =
  1071. parentBacktraces.begin() + std::distance(parentBegin, parentIt);
  1072. std::vector<cmListFileBacktrace>::const_iterator btEnd =
  1073. parentBacktraces.end();
  1074. thisBacktraces = std::vector<cmListFileBacktrace>(btIt, btEnd);
  1075. contentEndPosition = thisContent.size();
  1076. }
  1077. void cmState::Snapshot::SetDefaultDefinitions()
  1078. {
  1079. /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
  1080. With CMake must separate between target and host platform. In most cases
  1081. the tests for WIN32, UNIX and APPLE will be for the target system, so an
  1082. additional set of variables for the host system is required ->
  1083. CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
  1084. WIN32, UNIX and APPLE are now set in the platform files in
  1085. Modules/Platforms/.
  1086. To keep cmake scripts (-P) and custom language and compiler modules
  1087. working, these variables are still also set here in this place, but they
  1088. will be reset in CMakeSystemSpecificInformation.cmake before the platform
  1089. files are executed. */
  1090. #if defined(_WIN32)
  1091. this->SetDefinition("WIN32", "1");
  1092. this->SetDefinition("CMAKE_HOST_WIN32", "1");
  1093. #else
  1094. this->SetDefinition("UNIX", "1");
  1095. this->SetDefinition("CMAKE_HOST_UNIX", "1");
  1096. #endif
  1097. #if defined(__CYGWIN__)
  1098. std::string legacy;
  1099. if (cmSystemTools::GetEnv("CMAKE_LEGACY_CYGWIN_WIN32", legacy) &&
  1100. cmSystemTools::IsOn(legacy.c_str())) {
  1101. this->SetDefinition("WIN32", "1");
  1102. this->SetDefinition("CMAKE_HOST_WIN32", "1");
  1103. }
  1104. #endif
  1105. #if defined(__APPLE__)
  1106. this->SetDefinition("APPLE", "1");
  1107. this->SetDefinition("CMAKE_HOST_APPLE", "1");
  1108. #endif
  1109. #if defined(__sun__)
  1110. this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
  1111. #endif
  1112. char temp[1024];
  1113. sprintf(temp, "%d", cmVersion::GetMinorVersion());
  1114. this->SetDefinition("CMAKE_MINOR_VERSION", temp);
  1115. sprintf(temp, "%d", cmVersion::GetMajorVersion());
  1116. this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
  1117. sprintf(temp, "%d", cmVersion::GetPatchVersion());
  1118. this->SetDefinition("CMAKE_PATCH_VERSION", temp);
  1119. sprintf(temp, "%d", cmVersion::GetTweakVersion());
  1120. this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
  1121. this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
  1122. this->SetDefinition("CMAKE_FILES_DIRECTORY",
  1123. cmake::GetCMakeFilesDirectory());
  1124. // Setup the default include file regular expression (match everything).
  1125. this->Position->BuildSystemDirectory->Properties.SetProperty(
  1126. "INCLUDE_REGULAR_EXPRESSION", "^.*$");
  1127. }
  1128. void cmState::Snapshot::SetDirectoryDefinitions()
  1129. {
  1130. this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
  1131. this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
  1132. this->State->GetSourceDirectory());
  1133. this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
  1134. this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
  1135. this->State->GetBinaryDirectory());
  1136. }
  1137. void cmState::Snapshot::InitializeFromParent()
  1138. {
  1139. PositionType parent = this->Position->DirectoryParent;
  1140. assert(this->Position->Vars.IsValid());
  1141. assert(parent->Vars.IsValid());
  1142. *this->Position->Vars =
  1143. cmDefinitions::MakeClosure(parent->Vars, parent->Root);
  1144. InitializeContentFromParent(
  1145. parent->BuildSystemDirectory->IncludeDirectories,
  1146. this->Position->BuildSystemDirectory->IncludeDirectories,
  1147. parent->BuildSystemDirectory->IncludeDirectoryBacktraces,
  1148. this->Position->BuildSystemDirectory->IncludeDirectoryBacktraces,
  1149. this->Position->IncludeDirectoryPosition);
  1150. InitializeContentFromParent(
  1151. parent->BuildSystemDirectory->CompileDefinitions,
  1152. this->Position->BuildSystemDirectory->CompileDefinitions,
  1153. parent->BuildSystemDirectory->CompileDefinitionsBacktraces,
  1154. this->Position->BuildSystemDirectory->CompileDefinitionsBacktraces,
  1155. this->Position->CompileDefinitionsPosition);
  1156. InitializeContentFromParent(
  1157. parent->BuildSystemDirectory->CompileOptions,
  1158. this->Position->BuildSystemDirectory->CompileOptions,
  1159. parent->BuildSystemDirectory->CompileOptionsBacktraces,
  1160. this->Position->BuildSystemDirectory->CompileOptionsBacktraces,
  1161. this->Position->CompileOptionsPosition);
  1162. }
  1163. cmState* cmState::Snapshot::GetState() const
  1164. {
  1165. return this->State;
  1166. }
  1167. cmState::Directory cmState::Snapshot::GetDirectory() const
  1168. {
  1169. return Directory(this->Position->BuildSystemDirectory, *this);
  1170. }
  1171. void cmState::Snapshot::SetProjectName(const std::string& name)
  1172. {
  1173. this->Position->BuildSystemDirectory->ProjectName = name;
  1174. }
  1175. std::string cmState::Snapshot::GetProjectName() const
  1176. {
  1177. return this->Position->BuildSystemDirectory->ProjectName;
  1178. }
  1179. void cmState::Snapshot::InitializeFromParent_ForSubdirsCommand()
  1180. {
  1181. std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
  1182. std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
  1183. this->InitializeFromParent();
  1184. this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
  1185. this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
  1186. this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir);
  1187. this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir);
  1188. }
  1189. cmState::Directory::Directory(
  1190. cmLinkedTree<BuildsystemDirectoryStateType>::iterator iter,
  1191. const cmState::Snapshot& snapshot)
  1192. : DirectoryState(iter)
  1193. , Snapshot_(snapshot)
  1194. {
  1195. }
  1196. template <typename T, typename U>
  1197. cmStringRange GetPropertyContent(T const& content, U contentEndPosition)
  1198. {
  1199. std::vector<std::string>::const_iterator end =
  1200. content.begin() + contentEndPosition;
  1201. std::vector<std::string>::const_reverse_iterator rbegin =
  1202. cmMakeReverseIterator(end);
  1203. rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
  1204. return cmMakeRange(rbegin.base(), end);
  1205. }
  1206. template <typename T, typename U, typename V>
  1207. cmBacktraceRange GetPropertyBacktraces(T const& content, U const& backtraces,
  1208. V contentEndPosition)
  1209. {
  1210. std::vector<std::string>::const_iterator entryEnd =
  1211. content.begin() + contentEndPosition;
  1212. std::vector<std::string>::const_reverse_iterator rbegin =
  1213. cmMakeReverseIterator(entryEnd);
  1214. rbegin = std::find(rbegin, content.rend(), cmPropertySentinal);
  1215. std::vector<cmListFileBacktrace>::const_iterator it =
  1216. backtraces.begin() + std::distance(content.begin(), rbegin.base());
  1217. std::vector<cmListFileBacktrace>::const_iterator end = backtraces.end();
  1218. return cmMakeRange(it, end);
  1219. }
  1220. template <typename T, typename U, typename V>
  1221. void AppendEntry(T& content, U& backtraces, V& endContentPosition,
  1222. const std::string& value, const cmListFileBacktrace& lfbt)
  1223. {
  1224. if (value.empty()) {
  1225. return;
  1226. }
  1227. assert(endContentPosition == content.size());
  1228. content.push_back(value);
  1229. backtraces.push_back(lfbt);
  1230. endContentPosition = content.size();
  1231. }
  1232. template <typename T, typename U, typename V>
  1233. void SetContent(T& content, U& backtraces, V& endContentPosition,
  1234. const std::string& vec, const cmListFileBacktrace& lfbt)
  1235. {
  1236. assert(endContentPosition == content.size());
  1237. content.resize(content.size() + 2);
  1238. backtraces.resize(backtraces.size() + 2);
  1239. content.back() = vec;
  1240. backtraces.back() = lfbt;
  1241. endContentPosition = content.size();
  1242. }
  1243. template <typename T, typename U, typename V>
  1244. void ClearContent(T& content, U& backtraces, V& endContentPosition)
  1245. {
  1246. assert(endContentPosition == content.size());
  1247. content.resize(content.size() + 1);
  1248. backtraces.resize(backtraces.size() + 1);
  1249. endContentPosition = content.size();
  1250. }
  1251. cmStringRange cmState::Directory::GetIncludeDirectoriesEntries() const
  1252. {
  1253. return GetPropertyContent(
  1254. this->DirectoryState->IncludeDirectories,
  1255. this->Snapshot_.Position->IncludeDirectoryPosition);
  1256. }
  1257. cmBacktraceRange cmState::Directory::GetIncludeDirectoriesEntryBacktraces()
  1258. const
  1259. {
  1260. return GetPropertyBacktraces(
  1261. this->DirectoryState->IncludeDirectories,
  1262. this->DirectoryState->IncludeDirectoryBacktraces,
  1263. this->Snapshot_.Position->IncludeDirectoryPosition);
  1264. }
  1265. void cmState::Directory::AppendIncludeDirectoriesEntry(
  1266. const std::string& vec, const cmListFileBacktrace& lfbt)
  1267. {
  1268. AppendEntry(this->DirectoryState->IncludeDirectories,
  1269. this->DirectoryState->IncludeDirectoryBacktraces,
  1270. this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
  1271. }
  1272. void cmState::Directory::PrependIncludeDirectoriesEntry(
  1273. const std::string& vec, const cmListFileBacktrace& lfbt)
  1274. {
  1275. std::vector<std::string>::iterator entryEnd =
  1276. this->DirectoryState->IncludeDirectories.begin() +
  1277. this->Snapshot_.Position->IncludeDirectoryPosition;
  1278. std::vector<std::string>::reverse_iterator rend =
  1279. this->DirectoryState->IncludeDirectories.rend();
  1280. std::vector<std::string>::reverse_iterator rbegin =
  1281. cmMakeReverseIterator(entryEnd);
  1282. rbegin = std::find(rbegin, rend, cmPropertySentinal);
  1283. std::vector<std::string>::iterator entryIt = rbegin.base();
  1284. std::vector<std::string>::iterator entryBegin =
  1285. this->DirectoryState->IncludeDirectories.begin();
  1286. std::vector<cmListFileBacktrace>::iterator btIt =
  1287. this->DirectoryState->IncludeDirectoryBacktraces.begin() +
  1288. std::distance(entryBegin, entryIt);
  1289. this->DirectoryState->IncludeDirectories.insert(entryIt, vec);
  1290. this->DirectoryState->IncludeDirectoryBacktraces.insert(btIt, lfbt);
  1291. this->Snapshot_.Position->IncludeDirectoryPosition =
  1292. this->DirectoryState->IncludeDirectories.size();
  1293. }
  1294. void cmState::Directory::SetIncludeDirectories(const std::string& vec,
  1295. const cmListFileBacktrace& lfbt)
  1296. {
  1297. SetContent(this->DirectoryState->IncludeDirectories,
  1298. this->DirectoryState->IncludeDirectoryBacktraces,
  1299. this->Snapshot_.Position->IncludeDirectoryPosition, vec, lfbt);
  1300. }
  1301. void cmState::Directory::ClearIncludeDirectories()
  1302. {
  1303. ClearContent(this->DirectoryState->IncludeDirectories,
  1304. this->DirectoryState->IncludeDirectoryBacktraces,
  1305. this->Snapshot_.Position->IncludeDirectoryPosition);
  1306. }
  1307. cmStringRange cmState::Directory::GetCompileDefinitionsEntries() const
  1308. {
  1309. return GetPropertyContent(
  1310. this->DirectoryState->CompileDefinitions,
  1311. this->Snapshot_.Position->CompileDefinitionsPosition);
  1312. }
  1313. cmBacktraceRange cmState::Directory::GetCompileDefinitionsEntryBacktraces()
  1314. const
  1315. {
  1316. return GetPropertyBacktraces(
  1317. this->DirectoryState->CompileDefinitions,
  1318. this->DirectoryState->CompileDefinitionsBacktraces,
  1319. this->Snapshot_.Position->CompileDefinitionsPosition);
  1320. }
  1321. void cmState::Directory::AppendCompileDefinitionsEntry(
  1322. const std::string& vec, const cmListFileBacktrace& lfbt)
  1323. {
  1324. AppendEntry(this->DirectoryState->CompileDefinitions,
  1325. this->DirectoryState->CompileDefinitionsBacktraces,
  1326. this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
  1327. }
  1328. void cmState::Directory::SetCompileDefinitions(const std::string& vec,
  1329. const cmListFileBacktrace& lfbt)
  1330. {
  1331. SetContent(this->DirectoryState->CompileDefinitions,
  1332. this->DirectoryState->CompileDefinitionsBacktraces,
  1333. this->Snapshot_.Position->CompileDefinitionsPosition, vec, lfbt);
  1334. }
  1335. void cmState::Directory::ClearCompileDefinitions()
  1336. {
  1337. ClearContent(this->DirectoryState->CompileDefinitions,
  1338. this->DirectoryState->CompileDefinitionsBacktraces,
  1339. this->Snapshot_.Position->CompileDefinitionsPosition);
  1340. }
  1341. cmStringRange cmState::Directory::GetCompileOptionsEntries() const
  1342. {
  1343. return GetPropertyContent(this->DirectoryState->CompileOptions,
  1344. this->Snapshot_.Position->CompileOptionsPosition);
  1345. }
  1346. cmBacktraceRange cmState::Directory::GetCompileOptionsEntryBacktraces() const
  1347. {
  1348. return GetPropertyBacktraces(
  1349. this->DirectoryState->CompileOptions,
  1350. this->DirectoryState->CompileOptionsBacktraces,
  1351. this->Snapshot_.Position->CompileOptionsPosition);
  1352. }
  1353. void cmState::Directory::AppendCompileOptionsEntry(
  1354. const std::string& vec, const cmListFileBacktrace& lfbt)
  1355. {
  1356. AppendEntry(this->DirectoryState->CompileOptions,
  1357. this->DirectoryState->CompileOptionsBacktraces,
  1358. this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt);
  1359. }
  1360. void cmState::Directory::SetCompileOptions(const std::string& vec,
  1361. const cmListFileBacktrace& lfbt)
  1362. {
  1363. SetContent(this->DirectoryState->CompileOptions,
  1364. this->DirectoryState->CompileOptionsBacktraces,
  1365. this->Snapshot_.Position->CompileOptionsPosition, vec, lfbt);
  1366. }
  1367. void cmState::Directory::ClearCompileOptions()
  1368. {
  1369. ClearContent(this->DirectoryState->CompileOptions,
  1370. this->DirectoryState->CompileOptionsBacktraces,
  1371. this->Snapshot_.Position->CompileOptionsPosition);
  1372. }
  1373. bool cmState::Snapshot::StrictWeakOrder::operator()(
  1374. const cmState::Snapshot& lhs, const cmState::Snapshot& rhs) const
  1375. {
  1376. return lhs.Position.StrictWeakOrdered(rhs.Position);
  1377. }
  1378. void cmState::Directory::SetProperty(const std::string& prop,
  1379. const char* value,
  1380. cmListFileBacktrace const& lfbt)
  1381. {
  1382. if (prop == "INCLUDE_DIRECTORIES") {
  1383. if (!value) {
  1384. this->ClearIncludeDirectories();
  1385. return;
  1386. }
  1387. this->SetIncludeDirectories(value, lfbt);
  1388. return;
  1389. }
  1390. if (prop == "COMPILE_OPTIONS") {
  1391. if (!value) {
  1392. this->ClearCompileOptions();
  1393. return;
  1394. }
  1395. this->SetCompileOptions(value, lfbt);
  1396. return;
  1397. }
  1398. if (prop == "COMPILE_DEFINITIONS") {
  1399. if (!value) {
  1400. this->ClearCompileDefinitions();
  1401. return;
  1402. }
  1403. this->SetCompileDefinitions(value, lfbt);
  1404. return;
  1405. }
  1406. this->DirectoryState->Properties.SetProperty(prop, value);
  1407. }
  1408. void cmState::Directory::AppendProperty(const std::string& prop,
  1409. const char* value, bool asString,
  1410. cmListFileBacktrace const& lfbt)
  1411. {
  1412. if (prop == "INCLUDE_DIRECTORIES") {
  1413. this->AppendIncludeDirectoriesEntry(value, lfbt);
  1414. return;
  1415. }
  1416. if (prop == "COMPILE_OPTIONS") {
  1417. this->AppendCompileOptionsEntry(value, lfbt);
  1418. return;
  1419. }
  1420. if (prop == "COMPILE_DEFINITIONS") {
  1421. this->AppendCompileDefinitionsEntry(value, lfbt);
  1422. return;
  1423. }
  1424. this->DirectoryState->Properties.AppendProperty(prop, value, asString);
  1425. }
  1426. const char* cmState::Directory::GetProperty(const std::string& prop) const
  1427. {
  1428. const bool chain =
  1429. this->Snapshot_.State->IsPropertyChained(prop, cmProperty::DIRECTORY);
  1430. return this->GetProperty(prop, chain);
  1431. }
  1432. const char* cmState::Directory::GetProperty(const std::string& prop,
  1433. bool chain) const
  1434. {
  1435. static std::string output;
  1436. output = "";
  1437. if (prop == "PARENT_DIRECTORY") {
  1438. cmState::Snapshot parent = this->Snapshot_.GetBuildsystemDirectoryParent();
  1439. if (parent.IsValid()) {
  1440. return parent.GetDirectory().GetCurrentSource();
  1441. }
  1442. return "";
  1443. }
  1444. if (prop == kBINARY_DIR) {
  1445. output = this->GetCurrentBinary();
  1446. return output.c_str();
  1447. }
  1448. if (prop == kSOURCE_DIR) {
  1449. output = this->GetCurrentSource();
  1450. return output.c_str();
  1451. }
  1452. if (prop == kSUBDIRECTORIES) {
  1453. std::vector<std::string> child_dirs;
  1454. std::vector<cmState::Snapshot> const& children =
  1455. this->DirectoryState->Children;
  1456. for (std::vector<cmState::Snapshot>::const_iterator ci = children.begin();
  1457. ci != children.end(); ++ci) {
  1458. child_dirs.push_back(ci->GetDirectory().GetCurrentSource());
  1459. }
  1460. output = cmJoin(child_dirs, ";");
  1461. return output.c_str();
  1462. }
  1463. if (prop == kBUILDSYSTEM_TARGETS) {
  1464. output = cmJoin(this->DirectoryState->NormalTargetNames, ";");
  1465. return output.c_str();
  1466. }
  1467. if (prop == "LISTFILE_STACK") {
  1468. std::vector<std::string> listFiles;
  1469. cmState::Snapshot snp = this->Snapshot_;
  1470. while (snp.IsValid()) {
  1471. listFiles.push_back(snp.GetExecutionListFile());
  1472. snp = snp.GetCallStackParent();
  1473. }
  1474. std::reverse(listFiles.begin(), listFiles.end());
  1475. output = cmJoin(listFiles, ";");
  1476. return output.c_str();
  1477. }
  1478. if (prop == "CACHE_VARIABLES") {
  1479. output = cmJoin(this->Snapshot_.State->GetCacheEntryKeys(), ";");
  1480. return output.c_str();
  1481. }
  1482. if (prop == "VARIABLES") {
  1483. std::vector<std::string> res = this->Snapshot_.ClosureKeys();
  1484. std::vector<std::string> cacheKeys =
  1485. this->Snapshot_.State->GetCacheEntryKeys();
  1486. res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
  1487. std::sort(res.begin(), res.end());
  1488. output = cmJoin(res, ";");
  1489. return output.c_str();
  1490. }
  1491. if (prop == "INCLUDE_DIRECTORIES") {
  1492. output = cmJoin(this->GetIncludeDirectoriesEntries(), ";");
  1493. return output.c_str();
  1494. }
  1495. if (prop == "COMPILE_OPTIONS") {
  1496. output = cmJoin(this->GetCompileOptionsEntries(), ";");
  1497. return output.c_str();
  1498. }
  1499. if (prop == "COMPILE_DEFINITIONS") {
  1500. output = cmJoin(this->GetCompileDefinitionsEntries(), ";");
  1501. return output.c_str();
  1502. }
  1503. const char* retVal = this->DirectoryState->Properties.GetPropertyValue(prop);
  1504. if (!retVal && chain) {
  1505. Snapshot parentSnapshot = this->Snapshot_.GetBuildsystemDirectoryParent();
  1506. if (parentSnapshot.IsValid()) {
  1507. return parentSnapshot.GetDirectory().GetProperty(prop, chain);
  1508. }
  1509. return this->Snapshot_.State->GetGlobalProperty(prop);
  1510. }
  1511. return retVal;
  1512. }
  1513. bool cmState::Directory::GetPropertyAsBool(const std::string& prop) const
  1514. {
  1515. return cmSystemTools::IsOn(this->GetProperty(prop));
  1516. }
  1517. std::vector<std::string> cmState::Directory::GetPropertyKeys() const
  1518. {
  1519. std::vector<std::string> keys;
  1520. keys.reserve(this->DirectoryState->Properties.size());
  1521. for (cmPropertyMap::const_iterator it =
  1522. this->DirectoryState->Properties.begin();
  1523. it != this->DirectoryState->Properties.end(); ++it) {
  1524. keys.push_back(it->first);
  1525. }
  1526. return keys;
  1527. }
  1528. void cmState::Directory::AddNormalTargetName(std::string const& name)
  1529. {
  1530. this->DirectoryState->NormalTargetNames.push_back(name);
  1531. }
  1532. bool operator==(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
  1533. {
  1534. return lhs.Position == rhs.Position;
  1535. }
  1536. bool operator!=(const cmState::Snapshot& lhs, const cmState::Snapshot& rhs)
  1537. {
  1538. return lhs.Position != rhs.Position;
  1539. }
  1540. static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
  1541. std::string& value)
  1542. {
  1543. // input line is: key=value
  1544. static cmsys::RegularExpression reg(
  1545. "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1546. // input line is: "key"=value
  1547. static cmsys::RegularExpression regQuoted(
  1548. "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1549. bool flag = false;
  1550. if (regQuoted.find(entry)) {
  1551. var = regQuoted.match(1);
  1552. value = regQuoted.match(2);
  1553. flag = true;
  1554. } else if (reg.find(entry)) {
  1555. var = reg.match(1);
  1556. value = reg.match(2);
  1557. flag = true;
  1558. }
  1559. // if value is enclosed in single quotes ('foo') then remove them
  1560. // it is used to enclose trailing space or tab
  1561. if (flag && value.size() >= 2 && value[0] == '\'' &&
  1562. value[value.size() - 1] == '\'') {
  1563. value = value.substr(1, value.size() - 2);
  1564. }
  1565. return flag;
  1566. }
  1567. bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
  1568. std::string& value, CacheEntryType& type)
  1569. {
  1570. // input line is: key:type=value
  1571. static cmsys::RegularExpression reg(
  1572. "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1573. // input line is: "key":type=value
  1574. static cmsys::RegularExpression regQuoted(
  1575. "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
  1576. bool flag = false;
  1577. if (regQuoted.find(entry)) {
  1578. var = regQuoted.match(1);
  1579. type = cmState::StringToCacheEntryType(regQuoted.match(2).c_str());
  1580. value = regQuoted.match(3);
  1581. flag = true;
  1582. } else if (reg.find(entry)) {
  1583. var = reg.match(1);
  1584. type = cmState::StringToCacheEntryType(reg.match(2).c_str());
  1585. value = reg.match(3);
  1586. flag = true;
  1587. }
  1588. // if value is enclosed in single quotes ('foo') then remove them
  1589. // it is used to enclose trailing space or tab
  1590. if (flag && value.size() >= 2 && value[0] == '\'' &&
  1591. value[value.size() - 1] == '\'') {
  1592. value = value.substr(1, value.size() - 2);
  1593. }
  1594. if (!flag) {
  1595. return ParseEntryWithoutType(entry, var, value);
  1596. }
  1597. return flag;
  1598. }