cmState.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmState_h
  4. #define cmState_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include "cmDefinitions.h"
  11. #include "cmLinkedTree.h"
  12. #include "cmListFileCache.h"
  13. #include "cmPolicies.h"
  14. #include "cmProperty.h"
  15. #include "cmPropertyDefinitionMap.h"
  16. #include "cmPropertyMap.h"
  17. #include "cmStatePrivate.h"
  18. #include "cmStateTypes.h"
  19. class cmCacheManager;
  20. class cmCommand;
  21. class cmGlobVerificationManager;
  22. class cmPropertyDefinition;
  23. class cmStateSnapshot;
  24. class cmMessenger;
  25. class cmState
  26. {
  27. friend class cmStateSnapshot;
  28. public:
  29. cmState();
  30. ~cmState();
  31. static const char* GetTargetTypeName(cmStateEnums::TargetType targetType);
  32. cmStateSnapshot CreateBaseSnapshot();
  33. cmStateSnapshot CreateBuildsystemDirectorySnapshot(
  34. cmStateSnapshot const& originSnapshot);
  35. cmStateSnapshot CreateFunctionCallSnapshot(
  36. cmStateSnapshot const& originSnapshot, std::string const& fileName);
  37. cmStateSnapshot CreateMacroCallSnapshot(
  38. cmStateSnapshot const& originSnapshot, std::string const& fileName);
  39. cmStateSnapshot CreateIncludeFileSnapshot(
  40. cmStateSnapshot const& originSnapshot, std::string const& fileName);
  41. cmStateSnapshot CreateVariableScopeSnapshot(
  42. cmStateSnapshot const& originSnapshot);
  43. cmStateSnapshot CreateInlineListFileSnapshot(
  44. cmStateSnapshot const& originSnapshot, std::string const& fileName);
  45. cmStateSnapshot CreatePolicyScopeSnapshot(
  46. cmStateSnapshot const& originSnapshot);
  47. cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot);
  48. static cmStateEnums::CacheEntryType StringToCacheEntryType(const char*);
  49. static const char* CacheEntryTypeToString(cmStateEnums::CacheEntryType);
  50. static bool IsCacheEntryType(std::string const& key);
  51. bool LoadCache(const std::string& path, bool internal,
  52. std::set<std::string>& excludes,
  53. std::set<std::string>& includes);
  54. bool SaveCache(const std::string& path, cmMessenger* messenger);
  55. bool DeleteCache(const std::string& path);
  56. std::vector<std::string> GetCacheEntryKeys() const;
  57. const char* GetCacheEntryValue(std::string const& key) const;
  58. const char* GetInitializedCacheValue(std::string const& key) const;
  59. cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) const;
  60. void SetCacheEntryValue(std::string const& key, std::string const& value);
  61. void SetCacheValue(std::string const& key, std::string const& value);
  62. void RemoveCacheEntry(std::string const& key);
  63. void SetCacheEntryProperty(std::string const& key,
  64. std::string const& propertyName,
  65. std::string const& value);
  66. void SetCacheEntryBoolProperty(std::string const& key,
  67. std::string const& propertyName, bool value);
  68. std::vector<std::string> GetCacheEntryPropertyList(std::string const& key);
  69. const char* GetCacheEntryProperty(std::string const& key,
  70. std::string const& propertyName);
  71. bool GetCacheEntryPropertyAsBool(std::string const& key,
  72. std::string const& propertyName);
  73. void AppendCacheEntryProperty(std::string const& key,
  74. const std::string& property,
  75. const std::string& value,
  76. bool asString = false);
  77. void RemoveCacheEntryProperty(std::string const& key,
  78. std::string const& propertyName);
  79. ///! Break up a line like VAR:type="value" into var, type and value
  80. static bool ParseCacheEntry(const std::string& entry, std::string& var,
  81. std::string& value,
  82. cmStateEnums::CacheEntryType& type);
  83. cmStateSnapshot Reset();
  84. // Define a property
  85. void DefineProperty(const std::string& name, cmProperty::ScopeType scope,
  86. const char* ShortDescription,
  87. const char* FullDescription, bool chain = false);
  88. // get property definition
  89. cmPropertyDefinition const* GetPropertyDefinition(
  90. const std::string& name, cmProperty::ScopeType scope) const;
  91. // Is a property defined?
  92. bool IsPropertyDefined(const std::string& name,
  93. cmProperty::ScopeType scope) const;
  94. bool IsPropertyChained(const std::string& name,
  95. cmProperty::ScopeType scope) const;
  96. void SetLanguageEnabled(std::string const& l);
  97. bool GetLanguageEnabled(std::string const& l) const;
  98. std::vector<std::string> GetEnabledLanguages() const;
  99. void SetEnabledLanguages(std::vector<std::string> const& langs);
  100. void ClearEnabledLanguages();
  101. bool GetIsInTryCompile() const;
  102. void SetIsInTryCompile(bool b);
  103. bool GetIsGeneratorMultiConfig() const;
  104. void SetIsGeneratorMultiConfig(bool b);
  105. // Returns a command from its name, case insensitive, or nullptr
  106. cmCommand* GetCommand(std::string const& name) const;
  107. // Returns a command from its name, or nullptr
  108. cmCommand* GetCommandByExactName(std::string const& name) const;
  109. void AddBuiltinCommand(std::string const& name, cmCommand* command);
  110. void AddDisallowedCommand(std::string const& name, cmCommand* command,
  111. cmPolicies::PolicyID policy, const char* message);
  112. void AddUnexpectedCommand(std::string const& name, const char* error);
  113. void AddScriptedCommand(std::string const& name, cmCommand* command);
  114. void RemoveUserDefinedCommands();
  115. std::vector<std::string> GetCommandNames() const;
  116. void SetGlobalProperty(const std::string& prop, const char* value);
  117. void AppendGlobalProperty(const std::string& prop, const char* value,
  118. bool asString = false);
  119. const char* GetGlobalProperty(const std::string& prop);
  120. bool GetGlobalPropertyAsBool(const std::string& prop);
  121. std::string const& GetSourceDirectory() const;
  122. void SetSourceDirectory(std::string const& sourceDirectory);
  123. std::string const& GetBinaryDirectory() const;
  124. void SetBinaryDirectory(std::string const& binaryDirectory);
  125. void SetWindowsShell(bool windowsShell);
  126. bool UseWindowsShell() const;
  127. void SetWindowsVSIDE(bool windowsVSIDE);
  128. bool UseWindowsVSIDE() const;
  129. void SetWatcomWMake(bool watcomWMake);
  130. bool UseWatcomWMake() const;
  131. void SetMinGWMake(bool minGWMake);
  132. bool UseMinGWMake() const;
  133. void SetNMake(bool nMake);
  134. bool UseNMake() const;
  135. void SetMSYSShell(bool mSYSShell);
  136. bool UseMSYSShell() const;
  137. unsigned int GetCacheMajorVersion() const;
  138. unsigned int GetCacheMinorVersion() const;
  139. private:
  140. friend class cmake;
  141. void AddCacheEntry(const std::string& key, const char* value,
  142. const char* helpString,
  143. cmStateEnums::CacheEntryType type);
  144. bool DoWriteGlobVerifyTarget() const;
  145. std::string const& GetGlobVerifyScript() const;
  146. std::string const& GetGlobVerifyStamp() const;
  147. bool SaveVerificationScript(const std::string& path);
  148. void AddGlobCacheEntry(bool recurse, bool listDirectories,
  149. bool followSymlinks, const std::string& relative,
  150. const std::string& expression,
  151. const std::vector<std::string>& files,
  152. const std::string& variable,
  153. cmListFileBacktrace const& bt);
  154. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
  155. std::vector<std::string> EnabledLanguages;
  156. std::map<std::string, cmCommand*> BuiltinCommands;
  157. std::map<std::string, cmCommand*> ScriptedCommands;
  158. cmPropertyMap GlobalProperties;
  159. cmCacheManager* CacheManager;
  160. cmGlobVerificationManager* GlobVerificationManager;
  161. cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>
  162. BuildsystemDirectory;
  163. cmLinkedTree<std::string> ExecutionListFiles;
  164. cmLinkedTree<cmStateDetail::PolicyStackEntry> PolicyStack;
  165. cmLinkedTree<cmStateDetail::SnapshotDataType> SnapshotData;
  166. cmLinkedTree<cmDefinitions> VarTree;
  167. std::string SourceDirectory;
  168. std::string BinaryDirectory;
  169. bool IsInTryCompile;
  170. bool IsGeneratorMultiConfig;
  171. bool WindowsShell;
  172. bool WindowsVSIDE;
  173. bool WatcomWMake;
  174. bool MinGWMake;
  175. bool NMake;
  176. bool MSYSShell;
  177. };
  178. #endif