cmState.h 9.3 KB

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