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