/src/CMake/Source/cmState.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <functional> |
8 | | #include <memory> |
9 | | #include <set> |
10 | | #include <string> |
11 | | #include <unordered_map> |
12 | | #include <unordered_set> |
13 | | #include <utility> |
14 | | #include <vector> |
15 | | |
16 | | #include <cm/optional> |
17 | | |
18 | | #include "cmDefinitions.h" |
19 | | #include "cmDependencyProvider.h" |
20 | | #include "cmLinkedTree.h" |
21 | | #include "cmPolicies.h" |
22 | | #include "cmProperty.h" |
23 | | #include "cmPropertyDefinition.h" |
24 | | #include "cmPropertyMap.h" |
25 | | #include "cmStatePrivate.h" |
26 | | #include "cmStateTypes.h" |
27 | | #include "cmValue.h" |
28 | | |
29 | | class cmCacheManager; |
30 | | class cmGlobVerificationManager; |
31 | | class cmMakefile; |
32 | | class cmStateSnapshot; |
33 | | class cmMessenger; |
34 | | class cmExecutionStatus; |
35 | | class cmListFileBacktrace; |
36 | | struct cmGlobCacheEntry; |
37 | | struct cmListFileArgument; |
38 | | |
39 | | template <typename T> |
40 | | class BT; |
41 | | |
42 | | class cmState |
43 | | { |
44 | | friend class cmStateSnapshot; |
45 | | |
46 | | public: |
47 | | enum class Role |
48 | | { |
49 | | Internal, |
50 | | Project, |
51 | | Script, |
52 | | FindPackage, |
53 | | CTest, |
54 | | CPack, |
55 | | Help, |
56 | | }; |
57 | | |
58 | | enum class TryCompile |
59 | | { |
60 | | No, |
61 | | Yes, |
62 | | }; |
63 | | |
64 | | cmState(Role role, TryCompile isTryCompile = TryCompile::No); |
65 | | ~cmState(); |
66 | | |
67 | | cmState(cmState const&) = delete; |
68 | | cmState& operator=(cmState const&) = delete; |
69 | | |
70 | | static std::string const& GetTargetTypeName( |
71 | | cmStateEnums::TargetType targetType); |
72 | | |
73 | | cmStateSnapshot CreateBaseSnapshot(); |
74 | | cmStateSnapshot CreateBuildsystemDirectorySnapshot( |
75 | | cmStateSnapshot const& originSnapshot); |
76 | | cmStateSnapshot CreateDeferCallSnapshot( |
77 | | cmStateSnapshot const& originSnapshot, std::string const& fileName); |
78 | | cmStateSnapshot CreateFunctionCallSnapshot( |
79 | | cmStateSnapshot const& originSnapshot, std::string const& fileName); |
80 | | cmStateSnapshot CreateMacroCallSnapshot( |
81 | | cmStateSnapshot const& originSnapshot, std::string const& fileName); |
82 | | cmStateSnapshot CreateIncludeFileSnapshot( |
83 | | cmStateSnapshot const& originSnapshot, std::string const& fileName); |
84 | | cmStateSnapshot CreateVariableScopeSnapshot( |
85 | | cmStateSnapshot const& originSnapshot); |
86 | | cmStateSnapshot CreateInlineListFileSnapshot( |
87 | | cmStateSnapshot const& originSnapshot, std::string const& fileName); |
88 | | cmStateSnapshot CreatePolicyScopeSnapshot( |
89 | | cmStateSnapshot const& originSnapshot); |
90 | | cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot); |
91 | | |
92 | | static cmStateEnums::CacheEntryType StringToCacheEntryType( |
93 | | std::string const&); |
94 | | static bool StringToCacheEntryType(std::string const&, |
95 | | cmStateEnums::CacheEntryType& type); |
96 | | static std::string const& CacheEntryTypeToString( |
97 | | cmStateEnums::CacheEntryType); |
98 | | static bool IsCacheEntryType(std::string const& key); |
99 | | |
100 | | bool LoadCache(std::string const& path, bool internal, |
101 | | std::set<std::string>& excludes, |
102 | | std::set<std::string>& includes); |
103 | | |
104 | | bool SaveCache(std::string const& path, cmMessenger* messenger); |
105 | | |
106 | | bool DeleteCache(std::string const& path); |
107 | | |
108 | | bool IsCacheLoaded() const; |
109 | | |
110 | | std::vector<std::string> GetCacheEntryKeys() const; |
111 | | cmValue GetCacheEntryValue(std::string const& key) const; |
112 | | std::string GetSafeCacheEntryValue(std::string const& key) const; |
113 | | cmValue GetInitializedCacheValue(std::string const& key) const; |
114 | | cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) const; |
115 | | void SetCacheEntryValue(std::string const& key, std::string const& value); |
116 | | |
117 | | void RemoveCacheEntry(std::string const& key); |
118 | | |
119 | | void SetCacheEntryProperty(std::string const& key, |
120 | | std::string const& propertyName, |
121 | | std::string const& value); |
122 | | void SetCacheEntryBoolProperty(std::string const& key, |
123 | | std::string const& propertyName, bool value); |
124 | | std::vector<std::string> GetCacheEntryPropertyList(std::string const& key); |
125 | | cmValue GetCacheEntryProperty(std::string const& key, |
126 | | std::string const& propertyName); |
127 | | bool GetCacheEntryPropertyAsBool(std::string const& key, |
128 | | std::string const& propertyName); |
129 | | void AppendCacheEntryProperty(std::string const& key, |
130 | | std::string const& property, |
131 | | std::string const& value, |
132 | | bool asString = false); |
133 | | void RemoveCacheEntryProperty(std::string const& key, |
134 | | std::string const& propertyName); |
135 | | |
136 | | //! Break up a line like VAR:type="value" into var, type and value |
137 | | static bool ParseCacheEntry(std::string const& entry, std::string& var, |
138 | | std::string& value, |
139 | | cmStateEnums::CacheEntryType& type); |
140 | | |
141 | | cmStateSnapshot Reset(); |
142 | | // Define a property |
143 | | void DefineProperty(std::string const& name, cmProperty::ScopeType scope, |
144 | | std::string const& ShortDescription, |
145 | | std::string const& FullDescription, bool chain = false, |
146 | | std::string const& initializeFromVariable = ""); |
147 | | |
148 | | // get property definition |
149 | | cmPropertyDefinition const* GetPropertyDefinition( |
150 | | std::string const& name, cmProperty::ScopeType scope) const; |
151 | | |
152 | | cmPropertyDefinitionMap const& GetPropertyDefinitions() const |
153 | 0 | { |
154 | 0 | return this->PropertyDefinitions; |
155 | 0 | } |
156 | | |
157 | | bool IsPropertyChained(std::string const& name, |
158 | | cmProperty::ScopeType scope) const; |
159 | | |
160 | | void SetLanguageEnabled(std::string const& l); |
161 | | bool GetLanguageEnabled(std::string const& l) const; |
162 | | std::vector<std::string> GetEnabledLanguages() const; |
163 | | void SetEnabledLanguages(std::vector<std::string> const& langs); |
164 | | void ClearEnabledLanguages(); |
165 | | |
166 | | bool GetIsGeneratorMultiConfig() const; |
167 | | void SetIsGeneratorMultiConfig(bool b); |
168 | | |
169 | | using Command = std::function<bool(std::vector<cmListFileArgument> const&, |
170 | | cmExecutionStatus&)>; |
171 | | using BuiltinCommand = bool (*)(std::vector<std::string> const&, |
172 | | cmExecutionStatus&); |
173 | | |
174 | | // Returns a command from its name, case insensitive, or nullptr |
175 | | Command GetCommand(std::string const& name) const; |
176 | | // Returns a command from its name, or nullptr |
177 | | Command GetCommandByExactName(std::string const& name) const; |
178 | | |
179 | | void AddBuiltinCommand(std::string const& name, Command command); |
180 | | void AddBuiltinCommand(std::string const& name, BuiltinCommand command); |
181 | | void AddFlowControlCommand(std::string const& name, Command command); |
182 | | void AddFlowControlCommand(std::string const& name, BuiltinCommand command); |
183 | | void AddDisallowedCommand(std::string const& name, BuiltinCommand command, |
184 | | cmPolicies::PolicyID policy, char const* message, |
185 | | char const* additionalWarning = nullptr); |
186 | | void AddRemovedCommand(std::string const& name, std::string const& message); |
187 | | void AddUnexpectedCommand(std::string const& name, char const* error); |
188 | | void AddUnexpectedFlowControlCommand(std::string const& name, |
189 | | char const* error); |
190 | | bool AddScriptedCommand(std::string const& name, BT<Command> command, |
191 | | cmMakefile& mf); |
192 | | void RemoveBuiltinCommand(std::string const& name); |
193 | | void RemoveUserDefinedCommands(); |
194 | | std::vector<std::string> GetCommandNames() const; |
195 | | |
196 | | void SetGlobalProperty(std::string const& prop, std::string const& value); |
197 | | void SetGlobalProperty(std::string const& prop, cmValue value); |
198 | | void AppendGlobalProperty(std::string const& prop, std::string const& value, |
199 | | bool asString = false); |
200 | | cmValue GetGlobalProperty(std::string const& prop); |
201 | | bool GetGlobalPropertyAsBool(std::string const& prop); |
202 | | |
203 | | std::string const& GetSourceDirectory() const; |
204 | | void SetSourceDirectory(std::string const& sourceDirectory); |
205 | | std::string const& GetBinaryDirectory() const; |
206 | | void SetBinaryDirectory(std::string const& binaryDirectory); |
207 | | |
208 | | void SetWindowsShell(bool windowsShell); |
209 | | bool UseWindowsShell() const; |
210 | | void SetWindowsVSIDE(bool windowsVSIDE); |
211 | | bool UseWindowsVSIDE() const; |
212 | | void SetGhsMultiIDE(bool ghsMultiIDE); |
213 | | bool UseGhsMultiIDE() const; |
214 | | void SetBorlandMake(bool borlandMake); |
215 | | bool UseBorlandMake() const; |
216 | | void SetWatcomWMake(bool watcomWMake); |
217 | | bool UseWatcomWMake() const; |
218 | | void SetMinGWMake(bool minGWMake); |
219 | | bool UseMinGWMake() const; |
220 | | void SetNMake(bool nMake); |
221 | | bool UseNMake() const; |
222 | | void SetMSYSShell(bool mSYSShell); |
223 | | bool UseMSYSShell() const; |
224 | | void SetNinja(bool ninja); |
225 | | bool UseNinja() const; |
226 | | void SetNinjaMulti(bool ninjaMulti); |
227 | | bool UseNinjaMulti() const; |
228 | | void SetFastbuildMake(bool fastbuildMake); |
229 | | bool UseFastbuildMake() const; |
230 | | |
231 | | unsigned int GetCacheMajorVersion() const; |
232 | | unsigned int GetCacheMinorVersion() const; |
233 | | |
234 | | void SetRoleToProjectForCMakeBuildVsReconfigure(); |
235 | | void SetRoleToHelpForListPresets(); |
236 | | Role GetRole() const; |
237 | | std::string GetRoleString() const; |
238 | | |
239 | | static std::string RoleToString(Role role); |
240 | | |
241 | | TryCompile GetIsTryCompile() const; |
242 | | |
243 | 0 | void ClearDependencyProvider() { this->DependencyProvider.reset(); } |
244 | | void SetDependencyProvider(cmDependencyProvider provider) |
245 | 0 | { |
246 | 0 | this->DependencyProvider = std::move(provider); |
247 | 0 | } |
248 | | cm::optional<cmDependencyProvider> const& GetDependencyProvider() const |
249 | 0 | { |
250 | 0 | return this->DependencyProvider; |
251 | 0 | } |
252 | | Command GetDependencyProviderCommand( |
253 | | cmDependencyProvider::Method method) const; |
254 | | |
255 | | void SetInTopLevelIncludes(bool inTopLevelIncludes) |
256 | 0 | { |
257 | 0 | this->ProcessingTopLevelIncludes = inTopLevelIncludes; |
258 | 0 | } |
259 | 0 | bool InTopLevelIncludes() const { return this->ProcessingTopLevelIncludes; } |
260 | | |
261 | | private: |
262 | | friend class cmake; |
263 | | void AddCacheEntry(std::string const& key, cmValue value, |
264 | | std::string const& helpString, |
265 | | cmStateEnums::CacheEntryType type); |
266 | | |
267 | | bool DoWriteGlobVerifyTarget() const; |
268 | | std::string const& GetGlobVerifyScript() const; |
269 | | std::string const& GetGlobVerifyStamp() const; |
270 | | bool SaveVerificationScript(std::string const& path, cmMessenger* messenger); |
271 | | void AddGlobCacheEntry(cmGlobCacheEntry const& entry, |
272 | | std::string const& variable, |
273 | | cmListFileBacktrace const& bt, |
274 | | cmMessenger* messenger); |
275 | | std::vector<cmGlobCacheEntry> GetGlobCacheEntries() const; |
276 | | |
277 | | cmPropertyDefinitionMap PropertyDefinitions; |
278 | | std::vector<std::string> EnabledLanguages; |
279 | | std::unordered_map<std::string, Command> BuiltinCommands; |
280 | | std::unordered_map<std::string, Command> ScriptedCommands; |
281 | | std::unordered_set<std::string> FlowControlCommands; |
282 | | cmPropertyMap GlobalProperties; |
283 | | std::unique_ptr<cmCacheManager> CacheManager; |
284 | | std::unique_ptr<cmGlobVerificationManager> GlobVerificationManager; |
285 | | |
286 | | cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType> |
287 | | BuildsystemDirectory; |
288 | | |
289 | | cmLinkedTree<std::string> ExecutionListFiles; |
290 | | |
291 | | cmLinkedTree<cmStateDetail::PolicyStackEntry> PolicyStack; |
292 | | cmLinkedTree<cmStateDetail::SnapshotDataType> SnapshotData; |
293 | | cmLinkedTree<cmDefinitions> VarTree; |
294 | | |
295 | | std::string SourceDirectory; |
296 | | std::string BinaryDirectory; |
297 | | bool IsGeneratorMultiConfig = false; |
298 | | bool WindowsShell = false; |
299 | | bool WindowsVSIDE = false; |
300 | | bool GhsMultiIDE = false; |
301 | | bool BorlandMake = false; |
302 | | bool WatcomWMake = false; |
303 | | bool MinGWMake = false; |
304 | | bool NMake = false; |
305 | | bool MSYSShell = false; |
306 | | bool Ninja = false; |
307 | | bool NinjaMulti = false; |
308 | | bool FastbuildMake = false; |
309 | | Role StateRole = Role::Internal; |
310 | | TryCompile IsTryCompile = TryCompile::No; |
311 | | cm::optional<cmDependencyProvider> DependencyProvider; |
312 | | bool ProcessingTopLevelIncludes = false; |
313 | | }; |