/src/CMake/Source/cmMakefile.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 <cstddef> |
8 | | #include <deque> |
9 | | #include <functional> |
10 | | #include <map> |
11 | | #include <memory> |
12 | | #include <set> |
13 | | #include <stack> |
14 | | #include <string> |
15 | | #include <unordered_map> |
16 | | #include <utility> |
17 | | #include <vector> |
18 | | |
19 | | #include <cm/optional> |
20 | | #include <cm/string_view> |
21 | | |
22 | | #include "cmsys/RegularExpression.hxx" |
23 | | |
24 | | #include "cm_sys_stat.h" |
25 | | |
26 | | #include "cmAlgorithms.h" |
27 | | #include "cmCustomCommand.h" |
28 | | #include "cmDiagnostics.h" |
29 | | #include "cmFindPackageStack.h" |
30 | | #include "cmFunctionBlocker.h" |
31 | | #include "cmListFileCache.h" |
32 | | #include "cmMessageType.h" // IWYU pragma: keep |
33 | | #include "cmNewLineStyle.h" |
34 | | #include "cmPolicies.h" |
35 | | #include "cmSourceFileLocationKind.h" |
36 | | #include "cmStateSnapshot.h" |
37 | | #include "cmStateTypes.h" |
38 | | #include "cmValue.h" |
39 | | |
40 | | // IWYU does not see that 'std::unordered_map<std::string, cmTarget>' |
41 | | // will not compile without the complete type. |
42 | | #include "cmTarget.h" // IWYU pragma: keep |
43 | | |
44 | | #if !defined(CMAKE_BOOTSTRAP) |
45 | | # include "cmSourceGroup.h" |
46 | | #endif |
47 | | |
48 | | enum class cmCustomCommandType; |
49 | | enum class cmObjectLibraryCommands; |
50 | | |
51 | | class cmCompiledGeneratorExpression; |
52 | | class cmCustomCommandLines; |
53 | | class cmExecutionStatus; |
54 | | class cmExpandedCommandArgument; |
55 | | class cmExportBuildFileGenerator; |
56 | | class cmGeneratorExpressionEvaluationFile; |
57 | | class cmGlobalGenerator; |
58 | | class cmInstallGenerator; |
59 | | class cmLocalGenerator; |
60 | | class cmMessenger; |
61 | | class cmSourceFile; |
62 | | class cmState; |
63 | | class cmTest; |
64 | | class cmTestGenerator; |
65 | | class cmVariableWatch; |
66 | | class cmake; |
67 | | |
68 | | namespace cm { |
69 | | enum class PolicyScope : bool |
70 | | { |
71 | | None, |
72 | | Local, |
73 | | }; |
74 | | |
75 | | enum class DiagnosticScope : bool |
76 | | { |
77 | | None, |
78 | | Local, |
79 | | }; |
80 | | } |
81 | | |
82 | | /** A type-safe wrapper for a string representing a directory id. */ |
83 | | class cmDirectoryId |
84 | | { |
85 | | public: |
86 | | cmDirectoryId(std::string s); |
87 | | std::string String; |
88 | | }; |
89 | | |
90 | | /** \class cmMakefile |
91 | | * \brief Process the input CMakeLists.txt file. |
92 | | * |
93 | | * Process and store into memory the input CMakeLists.txt file. |
94 | | * Each CMakeLists.txt file is parsed and the commands found there |
95 | | * are added into the build process. |
96 | | */ |
97 | | class cmMakefile |
98 | | { |
99 | | public: |
100 | | /* Mark a variable as used */ |
101 | | void MarkVariableAsUsed(std::string const& var); |
102 | | /* return true if a variable has been initialized */ |
103 | | bool VariableInitialized(std::string const&) const; |
104 | | |
105 | | /** |
106 | | * Construct an empty makefile. |
107 | | */ |
108 | | cmMakefile(cmGlobalGenerator* globalGenerator, |
109 | | cmStateSnapshot const& snapshot); |
110 | | |
111 | | /** |
112 | | * Destructor. |
113 | | */ |
114 | | ~cmMakefile(); |
115 | | |
116 | | cmMakefile(cmMakefile const&) = delete; |
117 | | cmMakefile& operator=(cmMakefile const&) = delete; |
118 | | |
119 | | cmDirectoryId GetDirectoryId() const; |
120 | | |
121 | | bool ReadListFile(std::string const& filename); |
122 | | |
123 | | bool ReadListFileAsString(std::string const& content, |
124 | | std::string const& virtualFileName); |
125 | | |
126 | | bool ReadDependentFile( |
127 | | std::string const& filename, |
128 | | cm::PolicyScope policyScope = cm::PolicyScope::None, |
129 | | cm::DiagnosticScope DiagnosticScope = cm::DiagnosticScope::None); |
130 | | |
131 | | /** |
132 | | * Add a function blocker to this makefile |
133 | | */ |
134 | | void AddFunctionBlocker(std::unique_ptr<cmFunctionBlocker> fb); |
135 | | |
136 | | /// @return whether we are processing the top CMakeLists.txt file. |
137 | | bool IsRootMakefile() const; |
138 | | |
139 | | /** |
140 | | * Remove the function blocker whose scope ends with the given command. |
141 | | * This returns ownership of the function blocker object. |
142 | | */ |
143 | | std::unique_ptr<cmFunctionBlocker> RemoveFunctionBlocker(); |
144 | | |
145 | | /** |
146 | | * Try running cmake and building a file. This is used for dynamically |
147 | | * loaded commands, not as part of the usual build process. |
148 | | */ |
149 | | int TryCompile(std::string const& srcdir, std::string const& bindir, |
150 | | std::string const& projectName, std::string const& targetName, |
151 | | bool fast, int jobs, |
152 | | std::vector<std::string> const* cmakeArgs, |
153 | | std::string& output); |
154 | | |
155 | | bool GetIsSourceFileTryCompile() const; |
156 | | |
157 | | /** |
158 | | * Help enforce global target name uniqueness. |
159 | | */ |
160 | | bool EnforceUniqueName(std::string const& name, std::string& msg, |
161 | | bool isCustom = false) const; |
162 | | |
163 | | enum class GeneratorActionWhen |
164 | | { |
165 | | // Run after all CMake code has been parsed. |
166 | | AfterConfigure, |
167 | | // Run after generator targets have been constructed. |
168 | | AfterGeneratorTargets, |
169 | | }; |
170 | | |
171 | | class GeneratorAction |
172 | | { |
173 | | using ActionT = |
174 | | std::function<void(cmLocalGenerator&, cmListFileBacktrace const&)>; |
175 | | using CCActionT = |
176 | | std::function<void(cmLocalGenerator&, cmListFileBacktrace const&, |
177 | | std::unique_ptr<cmCustomCommand> cc)>; |
178 | | |
179 | | public: |
180 | | GeneratorAction( |
181 | | ActionT&& action, |
182 | | GeneratorActionWhen when = GeneratorActionWhen::AfterConfigure) |
183 | 0 | : When(when) |
184 | 0 | , Action(std::move(action)) |
185 | 0 | { |
186 | 0 | } |
187 | | |
188 | | GeneratorAction( |
189 | | std::unique_ptr<cmCustomCommand> tcc, CCActionT&& action, |
190 | | GeneratorActionWhen when = GeneratorActionWhen::AfterConfigure) |
191 | 0 | : When(when) |
192 | 0 | , CCAction(std::move(action)) |
193 | 0 | , cc(std::move(tcc)) |
194 | 0 | { |
195 | 0 | } |
196 | | |
197 | | void operator()(cmLocalGenerator& lg, cmListFileBacktrace const& lfbt, |
198 | | GeneratorActionWhen when); |
199 | | |
200 | | private: |
201 | | GeneratorActionWhen When; |
202 | | |
203 | | ActionT Action; |
204 | | |
205 | | // FIXME: Use std::variant |
206 | | CCActionT CCAction; |
207 | | std::unique_ptr<cmCustomCommand> cc; |
208 | | }; |
209 | | |
210 | | /** |
211 | | * Register an action that is executed during Generate |
212 | | */ |
213 | | void AddGeneratorAction(GeneratorAction&& action); |
214 | | |
215 | | /// Helper to insert the constructor GeneratorAction(args...) |
216 | | template <class... Args> |
217 | | void AddGeneratorAction(Args&&... args) |
218 | 0 | { |
219 | 0 | AddGeneratorAction(GeneratorAction(std::move(args)...)); |
220 | 0 | } Unexecuted instantiation: cmFLTKWrapUICommand.cxx:void cmMakefile::AddGeneratorAction<cmFLTKWrapUICommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0>(cmFLTKWrapUICommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0&&) Unexecuted instantiation: cmInstallFilesCommand.cxx:void cmMakefile::AddGeneratorAction<cmInstallFilesCommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0>(cmInstallFilesCommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0&&) Unexecuted instantiation: cmInstallProgramsCommand.cxx:void cmMakefile::AddGeneratorAction<cmInstallProgramsCommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0>(cmInstallProgramsCommand(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmExecutionStatus&)::$_0&&) Unexecuted instantiation: cmVariableWatchCommand.cxx:void cmMakefile::AddGeneratorAction<(anonymous namespace)::FinalAction>((anonymous namespace)::FinalAction&&) Unexecuted instantiation: void cmMakefile::AddGeneratorAction<std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, ModuleCompilationDatabaseCommandAction&, cmMakefile::GeneratorActionWhen>(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >&&, ModuleCompilationDatabaseCommandAction&, cmMakefile::GeneratorActionWhen&&) Unexecuted instantiation: void cmMakefile::AddGeneratorAction<std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, ModuleCompilationDatabaseTargetAction&>(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >&&, ModuleCompilationDatabaseTargetAction&) Unexecuted instantiation: cmMakefile.cxx:void cmMakefile::AddGeneratorAction<std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, cmMakefile::AddCustomCommandToTarget(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmCustomCommandType, std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >)::$_0>(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >&&, cmMakefile::AddCustomCommandToTarget(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmCustomCommandType, std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >)::$_0&&) Unexecuted instantiation: cmMakefile.cxx:void cmMakefile::AddGeneratorAction<std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, cmMakefile::AddCustomCommandToOutput(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, std::__1::function<void (cmSourceFile*)> const&, bool)::$_0>(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >&&, cmMakefile::AddCustomCommandToOutput(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, std::__1::function<void (cmSourceFile*)> const&, bool)::$_0&&) Unexecuted instantiation: cmMakefile.cxx:void cmMakefile::AddGeneratorAction<cmMakefile::AppendCustomCommandToOutput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmImplicitDependsList const&, cmCustomCommandLines const&)::$_0>(cmMakefile::AppendCustomCommandToOutput(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmImplicitDependsList const&, cmCustomCommandLines const&)::$_0&&) Unexecuted instantiation: cmMakefile.cxx:void cmMakefile::AddGeneratorAction<std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >, cmMakefile::AddUtilityCommand(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >)::$_0>(std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >&&, cmMakefile::AddUtilityCommand(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, std::__1::unique_ptr<cmCustomCommand, std::__1::default_delete<cmCustomCommand> >)::$_0&&) |
221 | | |
222 | | /** |
223 | | * Perform generate actions, Library dependency analysis etc before output of |
224 | | * the makefile. |
225 | | */ |
226 | | void Generate(cmLocalGenerator& lg); |
227 | | void GenerateAfterGeneratorTargets(cmLocalGenerator& lg); |
228 | | |
229 | | /** |
230 | | * Get the target for PRE_BUILD, PRE_LINK, or POST_BUILD commands. |
231 | | */ |
232 | | cmTarget* GetCustomCommandTarget(std::string const& target, |
233 | | cmObjectLibraryCommands objLibCommands, |
234 | | cmListFileBacktrace const& lfbt) const; |
235 | | |
236 | | /** |
237 | | * Dispatch adding a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a |
238 | | * target. |
239 | | */ |
240 | | cmTarget* AddCustomCommandToTarget(std::string const& target, |
241 | | cmCustomCommandType type, |
242 | | std::unique_ptr<cmCustomCommand> cc); |
243 | | |
244 | | /** |
245 | | * Called for each file with custom command. |
246 | | */ |
247 | | using CommandSourceCallback = std::function<void(cmSourceFile*)>; |
248 | | |
249 | | /** |
250 | | * Dispatch adding a custom command to a source file. |
251 | | */ |
252 | | void AddCustomCommandToOutput( |
253 | | std::unique_ptr<cmCustomCommand> cc, |
254 | | CommandSourceCallback const& callback = nullptr, bool replace = false); |
255 | | void AppendCustomCommandToOutput( |
256 | | std::string const& output, std::vector<std::string> const& depends, |
257 | | cmImplicitDependsList const& implicit_depends, |
258 | | cmCustomCommandLines const& commandLines); |
259 | | |
260 | | /** |
261 | | * Add a define flag to the build. |
262 | | */ |
263 | | void AddDefineFlag(std::string const& definition); |
264 | | void RemoveDefineFlag(std::string const& definition); |
265 | | void AddCompileDefinition(std::string const& definition); |
266 | | void AddCompileOption(std::string const& option); |
267 | | void AddLinkOption(std::string const& option); |
268 | | void AddLinkDirectory(std::string const& directory, bool before = false); |
269 | | |
270 | | /** Create a new imported target with the name and type given. */ |
271 | | cmTarget* AddImportedTarget(std::string const& name, |
272 | | cmStateEnums::TargetType type, bool global); |
273 | | |
274 | | cmTarget* AddForeignTarget(std::string const& origin, |
275 | | std::string const& name); |
276 | | |
277 | | std::pair<cmTarget&, bool> CreateNewTarget( |
278 | | std::string const& name, cmStateEnums::TargetType type, |
279 | | cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes, |
280 | | cmTarget::Visibility vis = cmTarget::Visibility::Normal); |
281 | | |
282 | | cmTarget* AddNewTarget(cmStateEnums::TargetType type, |
283 | | std::string const& name); |
284 | | cmTarget* AddSynthesizedTarget(cmStateEnums::TargetType type, |
285 | | std::string const& name); |
286 | | |
287 | | /** Create a target instance for the utility. */ |
288 | | cmTarget* AddNewUtilityTarget(std::string const& utilityName, |
289 | | bool excludeFromAll); |
290 | | |
291 | | /** |
292 | | * Add an executable to the build. |
293 | | */ |
294 | | cmTarget* AddExecutable(std::string const& exename, |
295 | | std::vector<std::string> const& srcs, |
296 | | bool excludeFromAll = false); |
297 | | |
298 | | /** |
299 | | * Dispatch adding a utility to the build. A utility target is a command |
300 | | * that is run every time the target is built. |
301 | | */ |
302 | | cmTarget* AddUtilityCommand(std::string const& utilityName, |
303 | | bool excludeFromAll, |
304 | | std::unique_ptr<cmCustomCommand> cc); |
305 | | |
306 | | /** |
307 | | * Add a subdirectory to the build. |
308 | | */ |
309 | | void AddSubDirectory(std::string const& fullSrcDir, |
310 | | std::string const& fullBinDir, bool excludeFromAll, |
311 | | bool immediate, bool system); |
312 | | |
313 | | void Configure(); |
314 | | |
315 | | /** |
316 | | * Configure a subdirectory |
317 | | */ |
318 | | void ConfigureSubDirectory(cmMakefile* mf); |
319 | | |
320 | | /** |
321 | | * Add an include directory to the build. |
322 | | */ |
323 | | void AddIncludeDirectories(std::vector<std::string> const& incs, |
324 | | bool before = false); |
325 | | |
326 | | /** |
327 | | * Add a variable definition to the build. This variable |
328 | | * can be used in CMake to refer to lists, directories, etc. |
329 | | */ |
330 | | void AddDefinition(std::string const& name, cm::string_view value); |
331 | | void AddDefinition(std::string const& name, cmValue value) |
332 | 0 | { |
333 | 0 | this->AddDefinition(name, *value); |
334 | 0 | } |
335 | | /** |
336 | | * Add bool variable definition to the build. |
337 | | */ |
338 | | void AddDefinitionBool(std::string const& name, bool); |
339 | | //! Add a definition to this makefile and the global cmake cache. |
340 | | void AddCacheDefinition(std::string const& name, cmValue value, cmValue doc, |
341 | | cmStateEnums::CacheEntryType type, |
342 | | bool force = false); |
343 | | void AddCacheDefinition(std::string const& name, cmValue value, |
344 | | std::string const& doc, |
345 | | cmStateEnums::CacheEntryType type, |
346 | | bool force = false) |
347 | 0 | { |
348 | 0 | this->AddCacheDefinition(name, value, cmValue{ doc }, type, force); |
349 | 0 | } |
350 | | void AddCacheDefinition(std::string const& name, std::string const& value, |
351 | | std::string const& doc, |
352 | | cmStateEnums::CacheEntryType type, |
353 | | bool force = false) |
354 | 0 | { |
355 | 0 | this->AddCacheDefinition(name, cmValue{ value }, cmValue{ doc }, type, |
356 | 0 | force); |
357 | 0 | } |
358 | | |
359 | | /** |
360 | | * Remove a variable definition from the build. This is not valid |
361 | | * for cache entries, and will only affect the current makefile. |
362 | | */ |
363 | | void RemoveDefinition(std::string const& name); |
364 | | //! Remove a definition from the cache. |
365 | | void RemoveCacheDefinition(std::string const& name) const; |
366 | | |
367 | | /** |
368 | | * Specify the name of the project for this build. |
369 | | */ |
370 | | void SetProjectName(std::string const& name); |
371 | | |
372 | | void InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault); |
373 | | |
374 | | /* Get the default configuration */ |
375 | | std::string GetDefaultConfiguration() const; |
376 | | |
377 | | enum GeneratorConfigQuery |
378 | | { |
379 | | IncludeEmptyConfig, // Include "" aka noconfig |
380 | | ExcludeEmptyConfig, // Exclude "" aka noconfig |
381 | | OnlyMultiConfig, |
382 | | }; |
383 | | |
384 | | /** Get the configurations for dependency checking. */ |
385 | | std::vector<std::string> GetGeneratorConfigs( |
386 | | GeneratorConfigQuery mode) const; |
387 | | |
388 | | /** |
389 | | * Set the name of the library. |
390 | | */ |
391 | | cmTarget* AddLibrary(std::string const& libname, |
392 | | cmStateEnums::TargetType type, |
393 | | std::vector<std::string> const& srcs, |
394 | | bool excludeFromAll = false); |
395 | | void AddAlias(std::string const& libname, std::string const& tgt, |
396 | | bool globallyVisible = true); |
397 | | |
398 | | //@{ |
399 | | /** |
400 | | * Set, Push, Pop policy values for CMake. |
401 | | */ |
402 | | bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status); |
403 | | bool SetPolicy(char const* id, cmPolicies::PolicyStatus status); |
404 | | cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id, |
405 | | bool parent_scope = false) const; |
406 | | bool SetPolicyVersion(std::string const& version_min, |
407 | | std::string const& version_max); |
408 | | void RecordPolicies(cmPolicies::PolicyMap& pm) const; |
409 | | //@} |
410 | | |
411 | | //@{ |
412 | | /** |
413 | | * Set, Push, Pop diagnostics for CMake. |
414 | | */ |
415 | | bool SetDiagnostic(cmDiagnosticCategory category, cmDiagnosticAction action, |
416 | | bool recursive = false); |
417 | | bool PromoteDiagnostic(cmDiagnosticCategory category, |
418 | | cmDiagnosticAction action, bool recursive = false); |
419 | | bool DemoteDiagnostic(cmDiagnosticCategory category, |
420 | | cmDiagnosticAction action, bool recursive = false); |
421 | | cmDiagnosticAction GetDiagnosticAction(cmDiagnosticCategory category) const; |
422 | | void RecordDiagnostics(cmDiagnostics::DiagnosticMap& dm) const; |
423 | | //@} |
424 | | |
425 | | /** Update CMAKE_PARENT_LIST_FILE based on CMP0198 policy status. */ |
426 | | void UpdateParentListFileVariable(); |
427 | | |
428 | | /** Helper class to push and pop policies automatically. */ |
429 | | class PolicyPushPop |
430 | | { |
431 | | public: |
432 | | PolicyPushPop(cmMakefile* m); |
433 | | ~PolicyPushPop(); |
434 | | |
435 | | PolicyPushPop(PolicyPushPop const&) = delete; |
436 | | PolicyPushPop& operator=(PolicyPushPop const&) = delete; |
437 | | |
438 | | private: |
439 | | cmMakefile* Makefile; |
440 | | }; |
441 | | friend class PolicyPushPop; |
442 | | |
443 | | /** Helper class to push and pop diagnostics automatically. */ |
444 | | class DiagnosticPushPop |
445 | | { |
446 | | public: |
447 | | DiagnosticPushPop(cmMakefile* m); |
448 | | ~DiagnosticPushPop(); |
449 | | |
450 | | DiagnosticPushPop(DiagnosticPushPop const&) = delete; |
451 | | DiagnosticPushPop& operator=(DiagnosticPushPop const&) = delete; |
452 | | |
453 | | private: |
454 | | cmMakefile* Makefile; |
455 | | }; |
456 | | friend class DiagnosticPushPop; |
457 | | |
458 | | /** Helper class to push and pop variables scopes automatically. */ |
459 | | class VariablePushPop |
460 | | { |
461 | | public: |
462 | | VariablePushPop(cmMakefile* m); |
463 | | ~VariablePushPop(); |
464 | | |
465 | | VariablePushPop(VariablePushPop const&) = delete; |
466 | | VariablePushPop& operator=(VariablePushPop const&) = delete; |
467 | | |
468 | | private: |
469 | | cmMakefile* Makefile; |
470 | | }; |
471 | | |
472 | | std::string const& GetHomeDirectory() const; |
473 | | std::string const& GetHomeOutputDirectory() const; |
474 | | |
475 | | /** |
476 | | * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script. |
477 | | */ |
478 | | void SetScriptModeFile(std::string const& scriptfile); |
479 | | |
480 | | /** |
481 | | * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables. |
482 | | */ |
483 | | void SetArgcArgv(std::vector<std::string> const& args); |
484 | | |
485 | | std::string const& GetCurrentSourceDirectory() const; |
486 | | std::string const& GetCurrentBinaryDirectory() const; |
487 | | |
488 | | //@} |
489 | | |
490 | | /** |
491 | | * Set a regular expression that include files must match |
492 | | * in order to be considered as part of the depend information. |
493 | | */ |
494 | | void SetIncludeRegularExpression(std::string const& regex) |
495 | 0 | { |
496 | 0 | this->SetProperty("INCLUDE_REGULAR_EXPRESSION", regex); |
497 | 0 | } |
498 | | std::string const& GetIncludeRegularExpression() const |
499 | 0 | { |
500 | 0 | return this->GetProperty("INCLUDE_REGULAR_EXPRESSION"); |
501 | 0 | } |
502 | | |
503 | | /** |
504 | | * Set a regular expression that include files that are not found |
505 | | * must match in order to be considered a problem. |
506 | | */ |
507 | | void SetComplainRegularExpression(std::string const& regex) |
508 | 0 | { |
509 | 0 | this->ComplainFileRegularExpression = regex; |
510 | 0 | } |
511 | | std::string const& GetComplainRegularExpression() const |
512 | 0 | { |
513 | 0 | return this->ComplainFileRegularExpression; |
514 | 0 | } |
515 | | |
516 | | // -- List of targets |
517 | | using cmTargetMap = std::unordered_map<std::string, cmTarget>; |
518 | | /** Get the target map */ |
519 | 0 | cmTargetMap& GetTargets() { return this->Targets; } |
520 | | /** Get the target map - const version */ |
521 | 0 | cmTargetMap const& GetTargets() const { return this->Targets; } |
522 | | |
523 | | std::vector<std::unique_ptr<cmTarget>> const& GetOwnedImportedTargets() const |
524 | 0 | { |
525 | 0 | return this->ImportedTargetsOwned; |
526 | 0 | } |
527 | | std::vector<cmTarget*> GetImportedTargets() const; |
528 | | |
529 | | cmTarget* FindImportedTarget(std::string const& name) const; |
530 | | |
531 | | cmTarget* FindLocalNonAliasTarget(std::string const& name) const; |
532 | | |
533 | | /** Find a target to use in place of the given name. The target |
534 | | returned may be imported or built within the project. */ |
535 | | cmTarget* FindTargetToUse(std::string const& name, |
536 | | cmStateEnums::TargetDomainSet domains = { |
537 | | cmStateEnums::TargetDomain::NATIVE, |
538 | | cmStateEnums::TargetDomain::ALIAS }) const; |
539 | | bool IsAlias(std::string const& name) const; |
540 | | |
541 | | std::map<std::string, std::string> GetAliasTargets() const |
542 | 0 | { |
543 | 0 | return this->AliasTargets; |
544 | 0 | } |
545 | | |
546 | | /** |
547 | | * Mark include directories as system directories. |
548 | | */ |
549 | | void AddSystemIncludeDirectories(std::set<std::string> const& incs); |
550 | | |
551 | | /** Get a cmSourceFile pointer for a given source name, if the name is |
552 | | * not found, then a null pointer is returned. |
553 | | */ |
554 | | cmSourceFile* GetSource( |
555 | | std::string const& sourceName, |
556 | | cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous) const; |
557 | | |
558 | | /** Create the source file and return it. generated |
559 | | * indicates if it is a generated file, this is used in determining |
560 | | * how to create the source file instance e.g. name |
561 | | */ |
562 | | cmSourceFile* CreateSource( |
563 | | std::string const& sourceName, bool generated = false, |
564 | | cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); |
565 | | |
566 | | /** Get a cmSourceFile pointer for a given source name, if the name is |
567 | | * not found, then create the source file and return it. generated |
568 | | * indicates if it is a generated file, this is used in determining |
569 | | * how to create the source file instance e.g. name |
570 | | */ |
571 | | cmSourceFile* GetOrCreateSource( |
572 | | std::string const& sourceName, bool generated = false, |
573 | | cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); |
574 | | |
575 | | /** Get a cmSourceFile pointer for a given source name and always mark the |
576 | | * file as generated, if the name is not found, then create the source file |
577 | | * and return it. |
578 | | */ |
579 | | cmSourceFile* GetOrCreateGeneratedSource(std::string const& sourceName); |
580 | | |
581 | | void AddTargetObject(std::string const& tgtName, std::string const& objFile); |
582 | | |
583 | | /** |
584 | | * Given a variable name, return its value (as a string). |
585 | | * If the variable is not found in this makefile instance, the |
586 | | * cache is then queried. |
587 | | */ |
588 | | cmValue GetDefinition(std::string const&) const; |
589 | | std::string const& GetSafeDefinition(std::string const&) const; |
590 | | std::string const& GetRequiredDefinition(std::string const& name) const; |
591 | | bool IsDefinitionSet(std::string const&) const; |
592 | | bool IsNormalDefinitionSet(std::string const&) const; |
593 | | /** |
594 | | * Get the list of all variables in the current space. If argument |
595 | | * cacheonly is specified and is greater than 0, then only cache |
596 | | * variables will be listed. |
597 | | */ |
598 | | std::vector<std::string> GetDefinitions() const; |
599 | | |
600 | | /** |
601 | | * Test a boolean variable to see if it is true or false. |
602 | | * If the variable is not found in this makefile instance, the |
603 | | * cache is then queried. |
604 | | * Returns false if no entry defined. |
605 | | */ |
606 | | bool IsOn(std::string const& name) const; |
607 | | bool IsSet(std::string const& name) const; |
608 | | |
609 | | /** Return whether the target platform is 32-bit. */ |
610 | | bool PlatformIs32Bit() const; |
611 | | |
612 | | /** Return whether the target platform is 64-bit. */ |
613 | | bool PlatformIs64Bit() const; |
614 | | /** Return whether the target platform is x32. */ |
615 | | bool PlatformIsx32() const; |
616 | | |
617 | | /** Apple SDK Type */ |
618 | | enum class AppleSDK |
619 | | { |
620 | | MacOS, |
621 | | IPhoneOS, |
622 | | IPhoneSimulator, |
623 | | AppleTVOS, |
624 | | AppleTVSimulator, |
625 | | WatchOS, |
626 | | WatchSimulator, |
627 | | XROS, |
628 | | XRSimulator, |
629 | | }; |
630 | | |
631 | | /** What SDK type points CMAKE_OSX_SYSROOT to? */ |
632 | | AppleSDK GetAppleSDKType() const; |
633 | | |
634 | | /** Return whether the target platform is Apple iOS. */ |
635 | | bool PlatformIsAppleEmbedded() const; |
636 | | |
637 | | /** Return whether the target platform is an Apple simulator. */ |
638 | | bool PlatformIsAppleSimulator() const; |
639 | | |
640 | | /** Return whether the target platform is an Apple catalyst. */ |
641 | | bool PlatformIsAppleCatalyst() const; |
642 | | |
643 | | /** Return whether the target platform supports generation of text base stubs |
644 | | (.tbd file) describing exports (Apple specific). */ |
645 | | bool PlatformSupportsAppleTextStubs() const; |
646 | | |
647 | | /** Retrieve soname flag for the specified language if supported */ |
648 | | char const* GetSONameFlag(std::string const& language) const; |
649 | | |
650 | | /** |
651 | | * Get a list of preprocessor define flags. |
652 | | */ |
653 | 0 | std::string GetDefineFlags() const { return this->DefineFlags; } |
654 | | |
655 | | /** |
656 | | * Make sure CMake can write this file |
657 | | */ |
658 | | bool CanIWriteThisFile(std::string const& fileName) const; |
659 | | |
660 | | #if !defined(CMAKE_BOOTSTRAP) |
661 | | |
662 | | /** |
663 | | * Resolve source group genex. |
664 | | */ |
665 | | void ResolveSourceGroupGenex(cmLocalGenerator* lg); |
666 | | |
667 | | /** |
668 | | * Get the vector source groups. |
669 | | */ |
670 | | SourceGroupVector const& GetSourceGroups() const |
671 | 0 | { |
672 | 0 | return this->SourceGroups; |
673 | 0 | } |
674 | | |
675 | | /** |
676 | | * Get the source group |
677 | | */ |
678 | | cmSourceGroup* GetSourceGroup(std::vector<std::string> const& name) const; |
679 | | |
680 | | /** |
681 | | * Add a root source group for consideration when adding a new source. |
682 | | */ |
683 | | void AddSourceGroup(std::string const& name, char const* regex = nullptr); |
684 | | |
685 | | /** |
686 | | * Add a source group for consideration when adding a new source. |
687 | | * name is tokenized. |
688 | | */ |
689 | | void AddSourceGroup(std::vector<std::string> const& name, |
690 | | char const* regex = nullptr); |
691 | | |
692 | | /** |
693 | | * Get and existing or create a new source group. |
694 | | */ |
695 | | cmSourceGroup* GetOrCreateSourceGroup( |
696 | | std::vector<std::string> const& folders); |
697 | | |
698 | | /** |
699 | | * Get and existing or create a new source group. |
700 | | * The name will be tokenized. |
701 | | */ |
702 | | cmSourceGroup* GetOrCreateSourceGroup(std::string const& name); |
703 | | #endif |
704 | | |
705 | | /** |
706 | | * Get the vector of list files on which this makefile depends |
707 | | */ |
708 | | std::vector<std::string> const& GetListFiles() const |
709 | 0 | { |
710 | 0 | return this->ListFiles; |
711 | 0 | } |
712 | | //! When the file changes cmake will be re-run from the build system. |
713 | | void AddCMakeDependFile(std::string const& file) |
714 | 0 | { |
715 | 0 | this->ListFiles.push_back(file); |
716 | 0 | } |
717 | | void AddCMakeDependFilesFromUser(); |
718 | | |
719 | | std::string FormatListFileStack() const; |
720 | | |
721 | | /** |
722 | | * Get the current context backtrace. |
723 | | */ |
724 | | cmListFileBacktrace GetBacktrace() const; |
725 | | |
726 | | /** |
727 | | * Get the current stack of find_package calls. |
728 | | */ |
729 | | cmFindPackageStack GetFindPackageStack() const; |
730 | | |
731 | | /** |
732 | | * Get the vector of files created by this makefile |
733 | | */ |
734 | | std::vector<std::string> const& GetOutputFiles() const |
735 | 0 | { |
736 | 0 | return this->OutputFiles; |
737 | 0 | } |
738 | | void AddCMakeOutputFile(std::string const& file) |
739 | 0 | { |
740 | 0 | this->OutputFiles.push_back(file); |
741 | 0 | } |
742 | | |
743 | | /** |
744 | | * Expand all defined variables in the string. |
745 | | * Defined variables come from the this->Definitions map. |
746 | | * They are expanded with ${var} where var is the |
747 | | * entry in the this->Definitions map. Also \@var\@ is |
748 | | * expanded to match autoconf style expansions. |
749 | | */ |
750 | | std::string const& ExpandVariablesInString(std::string& source) const; |
751 | | std::string const& ExpandVariablesInString( |
752 | | std::string& source, bool escapeQuotes, bool noEscapes, |
753 | | bool atOnly = false, char const* filename = nullptr, long line = -1, |
754 | | bool removeEmpty = false, bool replaceAt = false) const; |
755 | | |
756 | | /** |
757 | | * Remove any remaining variables in the string. Anything with ${var} or |
758 | | * \@var\@ will be removed. |
759 | | */ |
760 | | void RemoveVariablesInString(std::string& source, bool atOnly = false) const; |
761 | | |
762 | | /** |
763 | | * Replace variables and #cmakedefine lines in the given string. |
764 | | * See cmConfigureFileCommand for details. |
765 | | */ |
766 | | void ConfigureString(std::string const& input, std::string& output, |
767 | | bool atOnly, bool escapeQuotes) const; |
768 | | |
769 | | /** |
770 | | * Copy file but change lines according to ConfigureString |
771 | | */ |
772 | | int ConfigureFile(std::string const& infile, std::string const& outfile, |
773 | | bool copyonly, bool atOnly, bool escapeQuotes, |
774 | | mode_t permissions = 0, cmNewLineStyle = cmNewLineStyle()); |
775 | | |
776 | | enum class CommandMissingFromStack |
777 | | { |
778 | | No, |
779 | | Yes, |
780 | | }; |
781 | | |
782 | | /** |
783 | | * Print a command's invocation |
784 | | */ |
785 | | void PrintCommandTrace( |
786 | | cmListFileFunction const& lff, cmListFileBacktrace const& bt, |
787 | | CommandMissingFromStack missing = CommandMissingFromStack::No) const; |
788 | | |
789 | | /** |
790 | | * Set a callback that is invoked whenever ExecuteCommand is called. |
791 | | */ |
792 | | void OnExecuteCommand(std::function<void()> callback); |
793 | | |
794 | | /** |
795 | | * Execute a single CMake command. Returns true if the command |
796 | | * succeeded or false if it failed. |
797 | | */ |
798 | | bool ExecuteCommand(cmListFileFunction const& lff, cmExecutionStatus& status, |
799 | | cm::optional<std::string> deferId = {}); |
800 | | |
801 | | //! Enable support for named language, if nil then all languages are |
802 | | /// enabled. |
803 | | void EnableLanguage(std::vector<std::string> const& languages, |
804 | | bool optional); |
805 | | |
806 | | cmState* GetState() const; |
807 | | |
808 | | /** |
809 | | * Get the variable watch. This is used to determine when certain variables |
810 | | * are accessed. |
811 | | */ |
812 | | #ifndef CMAKE_BOOTSTRAP |
813 | | cmVariableWatch* GetVariableWatch() const; |
814 | | #endif |
815 | | |
816 | | //! Display progress or status message. |
817 | | void DisplayStatus(std::string const&, float) const; |
818 | | |
819 | | /** |
820 | | * Expand the given list file arguments into the full set after |
821 | | * variable replacement and list expansion. |
822 | | */ |
823 | | bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs, |
824 | | std::vector<std::string>& outArgs) const; |
825 | | bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs, |
826 | | std::vector<cmExpandedCommandArgument>& outArgs) const; |
827 | | |
828 | | /** |
829 | | * Get the instance |
830 | | */ |
831 | | cmake* GetCMakeInstance() const; |
832 | | cmMessenger* GetMessenger() const; |
833 | | cmGlobalGenerator* GetGlobalGenerator() const; |
834 | | |
835 | | /** |
836 | | * Get all the source files this makefile knows about |
837 | | */ |
838 | | std::vector<std::unique_ptr<cmSourceFile>> const& GetSourceFiles() const |
839 | 0 | { |
840 | 0 | return this->SourceFiles; |
841 | 0 | } |
842 | | |
843 | | std::vector<cmTarget*> const& GetOrderedTargets() const |
844 | 0 | { |
845 | 0 | return this->OrderedTargets; |
846 | 0 | } |
847 | | |
848 | | //! Add a new cmTest to the list of tests for this makefile. |
849 | | cmTest* CreateTest(std::string const& testName); |
850 | | |
851 | | /** Get a cmTest pointer for a given test name, if the name is |
852 | | * not found, then a null pointer is returned. |
853 | | */ |
854 | | cmTest* GetTest(std::string const& testName) const; |
855 | | |
856 | | /** |
857 | | * Get all tests that run under the given configuration. |
858 | | */ |
859 | | void GetTests(std::string const& config, std::vector<cmTest*>& tests) const; |
860 | | |
861 | | /** |
862 | | * Return a location of a file in cmake or custom modules directory |
863 | | */ |
864 | | std::string GetModulesFile(cm::string_view name) const |
865 | 0 | { |
866 | 0 | bool system; |
867 | 0 | std::string debugBuffer; |
868 | 0 | return this->GetModulesFile(name, system, false, debugBuffer); |
869 | 0 | } |
870 | | |
871 | | /** |
872 | | * Return a location of a file in cmake or custom modules directory |
873 | | */ |
874 | | std::string GetModulesFile(cm::string_view name, bool& system) const |
875 | 0 | { |
876 | 0 | std::string debugBuffer; |
877 | 0 | return this->GetModulesFile(name, system, false, debugBuffer); |
878 | 0 | } |
879 | | |
880 | | std::string GetModulesFile(cm::string_view name, bool& system, bool debug, |
881 | | std::string& debugBuffer) const; |
882 | | |
883 | | //! Set/Get a property of this directory |
884 | | void SetProperty(std::string const& prop, cmValue value); |
885 | | void SetProperty(std::string const& prop, std::nullptr_t) |
886 | 0 | { |
887 | 0 | this->SetProperty(prop, cmValue{ nullptr }); |
888 | 0 | } |
889 | | void SetProperty(std::string const& prop, std::string const& value) |
890 | 0 | { |
891 | 0 | this->SetProperty(prop, cmValue(value)); |
892 | 0 | } |
893 | | void AppendProperty(std::string const& prop, std::string const& value, |
894 | | bool asString = false); |
895 | | cmValue GetProperty(std::string const& prop) const; |
896 | | cmValue GetProperty(std::string const& prop, bool chain) const; |
897 | | bool GetPropertyAsBool(std::string const& prop) const; |
898 | | std::vector<std::string> GetPropertyKeys() const; |
899 | | |
900 | | //! Initialize a makefile from its parent |
901 | | void InitializeFromParent(cmMakefile* parent); |
902 | | |
903 | | bool ExplicitlyGeneratesSbom() const; |
904 | | void SetExplicitlyGeneratesSbom(bool status = true); |
905 | | |
906 | | void AddInstallGenerator(std::unique_ptr<cmInstallGenerator> g); |
907 | | |
908 | | std::vector<std::unique_ptr<cmInstallGenerator>>& GetInstallGenerators() |
909 | 0 | { |
910 | 0 | return this->InstallGenerators; |
911 | 0 | } |
912 | | std::vector<std::unique_ptr<cmInstallGenerator>> const& |
913 | | GetInstallGenerators() const |
914 | 0 | { |
915 | 0 | return this->InstallGenerators; |
916 | 0 | } |
917 | | |
918 | | void AddTestGenerator(std::unique_ptr<cmTestGenerator> g); |
919 | | |
920 | | std::vector<std::unique_ptr<cmTestGenerator>> const& GetTestGenerators() |
921 | | const |
922 | 0 | { |
923 | 0 | return this->TestGenerators; |
924 | 0 | } |
925 | | |
926 | | class FunctionPushPop |
927 | | { |
928 | | public: |
929 | | FunctionPushPop(cmMakefile* mf, std::string const& fileName, |
930 | | cmPolicies::PolicyMap const& pm, |
931 | | cmDiagnostics::DiagnosticMap dm); |
932 | | ~FunctionPushPop(); |
933 | | |
934 | | FunctionPushPop(FunctionPushPop const&) = delete; |
935 | | FunctionPushPop& operator=(FunctionPushPop const&) = delete; |
936 | | |
937 | 0 | void Quiet() { this->ReportError = false; } |
938 | | |
939 | | private: |
940 | | cmMakefile* Makefile; |
941 | | bool ReportError = true; |
942 | | }; |
943 | | |
944 | | class MacroPushPop |
945 | | { |
946 | | public: |
947 | | MacroPushPop(cmMakefile* mf, std::string const& fileName, |
948 | | cmPolicies::PolicyMap const& pm, |
949 | | cmDiagnostics::DiagnosticMap dm); |
950 | | ~MacroPushPop(); |
951 | | |
952 | | MacroPushPop(MacroPushPop const&) = delete; |
953 | | MacroPushPop& operator=(MacroPushPop const&) = delete; |
954 | | |
955 | 0 | void Quiet() { this->ReportError = false; } |
956 | | |
957 | | private: |
958 | | cmMakefile* Makefile; |
959 | | bool ReportError = true; |
960 | | }; |
961 | | |
962 | | void PushFunctionScope(std::string const& fileName, |
963 | | cmPolicies::PolicyMap const& pm, |
964 | | cmDiagnostics::DiagnosticMap dm); |
965 | | void PopFunctionScope(bool reportError); |
966 | | void PushMacroScope(std::string const& fileName, |
967 | | cmPolicies::PolicyMap const& pm, |
968 | | cmDiagnostics::DiagnosticMap dm); |
969 | | void PopMacroScope(bool reportError); |
970 | | void PushScope(); |
971 | | void PopScope(); |
972 | | void RaiseScope(std::string const& var, char const* value); |
973 | | void RaiseScope(std::string const& var, cmValue value) |
974 | 0 | { |
975 | 0 | this->RaiseScope(var, value.GetCStr()); |
976 | 0 | } |
977 | | void RaiseScope(std::vector<std::string> const& variables); |
978 | | |
979 | | // push and pop loop scopes |
980 | | void PushLoopBlockBarrier(); |
981 | | void PopLoopBlockBarrier(); |
982 | | |
983 | | bool IsImportedTargetGlobalScope() const; |
984 | | |
985 | | enum class ImportedTargetScope |
986 | | { |
987 | | Local, |
988 | | Global, |
989 | | }; |
990 | | |
991 | | /** Helper class to manage whether imported packages |
992 | | * should be globally scoped based off the find package command |
993 | | */ |
994 | | class SetGlobalTargetImportScope |
995 | | { |
996 | | public: |
997 | | SetGlobalTargetImportScope(cmMakefile* mk, ImportedTargetScope const scope) |
998 | 0 | : Makefile(mk) |
999 | 0 | { |
1000 | 0 | if (scope == ImportedTargetScope::Global && |
1001 | 0 | !this->Makefile->IsImportedTargetGlobalScope()) { |
1002 | 0 | this->Makefile->CurrentImportedTargetScope = scope; |
1003 | 0 | this->Set = true; |
1004 | 0 | } else { |
1005 | 0 | this->Set = false; |
1006 | 0 | } |
1007 | 0 | } |
1008 | | ~SetGlobalTargetImportScope() |
1009 | 0 | { |
1010 | 0 | if (this->Set) { |
1011 | 0 | this->Makefile->CurrentImportedTargetScope = |
1012 | 0 | ImportedTargetScope::Local; |
1013 | 0 | } |
1014 | 0 | } |
1015 | | |
1016 | | private: |
1017 | | cmMakefile* Makefile; |
1018 | | bool Set; |
1019 | | }; |
1020 | | |
1021 | | /** Helper class to push and pop scopes automatically. */ |
1022 | | class ScopePushPop |
1023 | | { |
1024 | | public: |
1025 | | ScopePushPop(cmMakefile* m) |
1026 | 0 | : Makefile(m) |
1027 | 0 | { |
1028 | 0 | this->Makefile->PushScope(); |
1029 | 0 | } |
1030 | | |
1031 | 0 | ~ScopePushPop() { this->Makefile->PopScope(); } |
1032 | | |
1033 | | ScopePushPop(ScopePushPop const&) = delete; |
1034 | | ScopePushPop& operator=(ScopePushPop const&) = delete; |
1035 | | |
1036 | | private: |
1037 | | cmMakefile* Makefile; |
1038 | | }; |
1039 | | |
1040 | | void IssueMessage(MessageType t, std::string const& text) const |
1041 | 0 | { |
1042 | 0 | this->IssueMessage(t, text, this->Backtrace); |
1043 | 0 | } |
1044 | | void IssueMessage(MessageType t, std::string const& text, |
1045 | | cmListFileBacktrace const& bt) const; |
1046 | | |
1047 | | void IssueDiagnostic(cmDiagnosticCategory category, |
1048 | | std::string const& text) const |
1049 | 0 | { |
1050 | 0 | this->IssueDiagnostic(category, text, this->Backtrace); |
1051 | 0 | } |
1052 | | void IssueDiagnostic(cmDiagnosticCategory category, std::string const& text, |
1053 | | cmListFileBacktrace const& bt) const; |
1054 | | Message::LogLevel GetCurrentLogLevel() const; |
1055 | | |
1056 | | /** Set whether or not to report a CMP0000 violation. */ |
1057 | 0 | void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; } |
1058 | | |
1059 | | void IssueInvalidTargetNameError(std::string const& targetName) const; |
1060 | | |
1061 | | cmBTStringRange GetIncludeDirectoriesEntries() const; |
1062 | | cmBTStringRange GetCompileOptionsEntries() const; |
1063 | | cmBTStringRange GetCompileDefinitionsEntries() const; |
1064 | | cmBTStringRange GetLinkOptionsEntries() const; |
1065 | | cmBTStringRange GetLinkDirectoriesEntries() const; |
1066 | | |
1067 | | std::set<std::string> const& GetSystemIncludeDirectories() const |
1068 | 0 | { |
1069 | 0 | return this->SystemIncludeDirectories; |
1070 | 0 | } |
1071 | | |
1072 | | bool PolicyOptionalWarningEnabled(std::string const& var) const; |
1073 | | |
1074 | | void PushLoopBlock(); |
1075 | | void PopLoopBlock(); |
1076 | | bool IsLoopBlock() const; |
1077 | | |
1078 | | void ClearMatches(); |
1079 | | void StoreMatches(cmsys::RegularExpression& re); |
1080 | | |
1081 | | cmStateSnapshot GetStateSnapshot() const; |
1082 | | |
1083 | | void EnforceDirectoryLevelRules() const; |
1084 | | |
1085 | | void AddEvaluationFile( |
1086 | | std::string const& inputFile, std::string const& targetName, |
1087 | | std::unique_ptr<cmCompiledGeneratorExpression> outputName, |
1088 | | std::unique_ptr<cmCompiledGeneratorExpression> condition, |
1089 | | std::string const& newLineCharacter, mode_t permissions, |
1090 | | bool inputIsContent); |
1091 | | std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>> const& |
1092 | | GetEvaluationFiles() const; |
1093 | | |
1094 | | std::vector<std::unique_ptr<cmExportBuildFileGenerator>> const& |
1095 | | GetExportBuildFileGenerators() const; |
1096 | | void AddExportBuildFileGenerator( |
1097 | | std::unique_ptr<cmExportBuildFileGenerator> gen); |
1098 | | |
1099 | | // Maintain a stack of package roots to allow nested PACKAGE_ROOT_PATH |
1100 | | // searches |
1101 | | std::deque<std::vector<std::string>> FindPackageRootPathStack; |
1102 | | |
1103 | | /** |
1104 | | * RAII type to manage the find_package call stack. |
1105 | | */ |
1106 | | class FindPackageStackRAII |
1107 | | { |
1108 | | cmMakefile* Makefile; |
1109 | | |
1110 | | public: |
1111 | | FindPackageStackRAII(cmMakefile* mf, std::string const& pkg, |
1112 | | std::shared_ptr<cmPackageInformation const> pkgInfo); |
1113 | | ~FindPackageStackRAII(); |
1114 | | |
1115 | | FindPackageStackRAII(FindPackageStackRAII const&) = delete; |
1116 | | FindPackageStackRAII& operator=(FindPackageStackRAII const&) = delete; |
1117 | | }; |
1118 | | |
1119 | | class DebugFindPkgRAII |
1120 | | { |
1121 | | cmMakefile* Makefile; |
1122 | | bool OldValue; |
1123 | | |
1124 | | public: |
1125 | | DebugFindPkgRAII(cmMakefile* mf, std::string const& pkg); |
1126 | | ~DebugFindPkgRAII(); |
1127 | | |
1128 | | DebugFindPkgRAII(DebugFindPkgRAII const&) = delete; |
1129 | | DebugFindPkgRAII& operator=(DebugFindPkgRAII const&) = delete; |
1130 | | }; |
1131 | | |
1132 | | class CallRAII |
1133 | | { |
1134 | | public: |
1135 | | CallRAII(cmMakefile* mf, std::string const& file, |
1136 | | cmExecutionStatus& status); |
1137 | | ~CallRAII(); |
1138 | | |
1139 | | CallRAII(CallRAII const&) = delete; |
1140 | | CallRAII& operator=(CallRAII const&) = delete; |
1141 | | |
1142 | | protected: |
1143 | | CallRAII(cmMakefile* mf, cmListFileContext const& lfc, |
1144 | | cmExecutionStatus& status); |
1145 | | |
1146 | | cmMakefile* Detach(); |
1147 | | |
1148 | | cmMakefile* Makefile; |
1149 | | }; |
1150 | | |
1151 | | bool GetDebugFindPkgMode() const; |
1152 | | |
1153 | | void MaybeWarnCMP0074(std::string const& rootVar, cmValue rootDef, |
1154 | | cm::optional<std::string> const& rootEnv); |
1155 | | void MaybeWarnCMP0144(std::string const& rootVAR, cmValue rootDEF, |
1156 | | cm::optional<std::string> const& rootENV); |
1157 | | void MaybeWarnUninitialized(std::string const& variable, |
1158 | | char const* sourceFilename) const; |
1159 | | bool IsProjectFile(char const* filename) const; |
1160 | | |
1161 | | size_t GetRecursionDepthLimit() const; |
1162 | | |
1163 | | size_t GetRecursionDepth() const; |
1164 | | void SetRecursionDepth(size_t recursionDepth); |
1165 | | |
1166 | | std::string NewDeferId() const; |
1167 | | bool DeferCall(std::string id, std::string fileName, cmListFileFunction lff); |
1168 | | bool DeferCancelCall(std::string const& id); |
1169 | | cm::optional<std::string> DeferGetCallIds() const; |
1170 | | cm::optional<std::string> DeferGetCall(std::string const& id) const; |
1171 | | |
1172 | | protected: |
1173 | | // add link libraries and directories to the target |
1174 | | void AddGlobalLinkInformation(cmTarget& target); |
1175 | | |
1176 | | // libraries, classes, and executables |
1177 | | mutable cmTargetMap Targets; |
1178 | | std::map<std::string, std::string> AliasTargets; |
1179 | | |
1180 | | std::vector<cmTarget*> OrderedTargets; |
1181 | | |
1182 | | std::vector<std::unique_ptr<cmSourceFile>> SourceFiles; |
1183 | | |
1184 | | // Because cmSourceFile names are compared in a fuzzy way (see |
1185 | | // cmSourceFileLocation::Match()) we can't have a straight mapping from |
1186 | | // filename to cmSourceFile. To make lookups more efficient we store the |
1187 | | // Name portion of the cmSourceFileLocation and then compare on the list of |
1188 | | // cmSourceFiles that might match that name. Note that on platforms which |
1189 | | // have a case-insensitive filesystem we store the key in all lowercase. |
1190 | | using SourceFileMap = |
1191 | | std::unordered_map<std::string, std::vector<cmSourceFile*>>; |
1192 | | SourceFileMap SourceFileSearchIndex; |
1193 | | |
1194 | | // For "Known" paths we can store a direct filename to cmSourceFile map |
1195 | | std::unordered_map<std::string, cmSourceFile*> KnownFileSearchIndex; |
1196 | | |
1197 | | // Tests |
1198 | | std::map<std::string, std::unique_ptr<cmTest>> Tests; |
1199 | | |
1200 | | // The set of include directories that are marked as system include |
1201 | | // directories. |
1202 | | std::set<std::string> SystemIncludeDirectories; |
1203 | | |
1204 | | std::vector<std::string> ListFiles; |
1205 | | std::vector<std::string> OutputFiles; |
1206 | | |
1207 | | std::vector<std::unique_ptr<cmInstallGenerator>> InstallGenerators; |
1208 | | std::vector<std::unique_ptr<cmTestGenerator>> TestGenerators; |
1209 | | |
1210 | | std::string ComplainFileRegularExpression; |
1211 | | std::string DefineFlags; |
1212 | | |
1213 | | #if !defined(CMAKE_BOOTSTRAP) |
1214 | | SourceGroupVector SourceGroups; |
1215 | | size_t ObjectLibrariesSourceGroupIndex; |
1216 | | #endif |
1217 | | |
1218 | | cmGlobalGenerator* GlobalGenerator; |
1219 | | bool IsFunctionBlocked(cmListFileFunction const& lff, |
1220 | | cmExecutionStatus& status); |
1221 | | |
1222 | | private: |
1223 | | cmStateSnapshot StateSnapshot; |
1224 | | cmListFileBacktrace Backtrace; |
1225 | | size_t RecursionDepth = 0; |
1226 | | |
1227 | | struct DeferCommand |
1228 | | { |
1229 | | // Id is empty for an already-executed or canceled operation. |
1230 | | std::string Id; |
1231 | | std::string FilePath; |
1232 | | cmListFileFunction Command; |
1233 | | }; |
1234 | | struct DeferCommands |
1235 | | { |
1236 | | std::vector<DeferCommand> Commands; |
1237 | | }; |
1238 | | std::unique_ptr<DeferCommands> Defer; |
1239 | | bool DeferRunning = false; |
1240 | | |
1241 | | void DoGenerate(cmLocalGenerator& lg); |
1242 | | |
1243 | | void RunListFile(cmListFile const& listFile, |
1244 | | std::string const& filenametoread, |
1245 | | DeferCommands* defer = nullptr); |
1246 | | |
1247 | | bool ParseDefineFlag(std::string const& definition, bool remove); |
1248 | | |
1249 | | bool EnforceUniqueDir(std::string const& srcPath, |
1250 | | std::string const& binPath) const; |
1251 | | |
1252 | | std::function<void()> ExecuteCommandCallback; |
1253 | | using FunctionBlockerPtr = std::unique_ptr<cmFunctionBlocker>; |
1254 | | using FunctionBlockersType = |
1255 | | std::stack<FunctionBlockerPtr, std::vector<FunctionBlockerPtr>>; |
1256 | | FunctionBlockersType FunctionBlockers; |
1257 | | std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers; |
1258 | | void PushFunctionBlockerBarrier(); |
1259 | | void PopFunctionBlockerBarrier(bool reportError = true); |
1260 | | |
1261 | | std::stack<int> LoopBlockCounter; |
1262 | | |
1263 | | mutable cmsys::RegularExpression cmDefineRegex; |
1264 | | mutable cmsys::RegularExpression cmDefine01Regex; |
1265 | | mutable cmsys::RegularExpression cmNamedCurly; |
1266 | | |
1267 | | std::vector<cmMakefile*> UnConfiguredDirectories; |
1268 | | std::vector<std::unique_ptr<cmExportBuildFileGenerator>> |
1269 | | ExportBuildFileGenerators; |
1270 | | |
1271 | | std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>> |
1272 | | EvaluationFiles; |
1273 | | |
1274 | | class CallScope; |
1275 | | friend class CallScope; |
1276 | | |
1277 | | std::vector<cmExecutionStatus*> ExecutionStatusStack; |
1278 | | friend class cmParseFileScope; |
1279 | | |
1280 | | std::vector<std::unique_ptr<cmTarget>> ImportedTargetsOwned; |
1281 | | using TargetMap = std::unordered_map<std::string, cmTarget*>; |
1282 | | TargetMap ImportedTargets; |
1283 | | |
1284 | | // Internal policy stack management. |
1285 | | void PushPolicy(bool weak = false, cmPolicies::PolicyMap const& pm = {}); |
1286 | | void PopPolicy(); |
1287 | | friend bool cmCMakePolicyCommand(std::vector<std::string> const& args, |
1288 | | cmExecutionStatus& status); |
1289 | | |
1290 | | // Internal diagnostic stack management. |
1291 | | void PushDiagnostic(bool weak = false, cmDiagnostics::DiagnosticMap dm = {}); |
1292 | | void PopDiagnostic(); |
1293 | | friend bool cmCMakeDiagnosticCommand(std::vector<std::string> const& args, |
1294 | | cmExecutionStatus& status); |
1295 | | |
1296 | | void PopSnapshot(bool reportError = true); |
1297 | | |
1298 | | class IncludeScope; |
1299 | | friend class IncludeScope; |
1300 | | |
1301 | | class ListFileScope; |
1302 | | friend class ListFileScope; |
1303 | | |
1304 | | class DeferScope; |
1305 | | friend class DeferScope; |
1306 | | |
1307 | | class DeferCallScope; |
1308 | | friend class DeferCallScope; |
1309 | | |
1310 | | class BuildsystemFileScope; |
1311 | | friend class BuildsystemFileScope; |
1312 | | |
1313 | | MessageType ExpandVariablesInStringImpl(std::string& errorstr, |
1314 | | std::string& source, |
1315 | | bool escapeQuotes, bool noEscapes, |
1316 | | bool atOnly, char const* filename, |
1317 | | long line, bool replaceAt) const; |
1318 | | |
1319 | | bool ValidateCustomCommand(cmCustomCommandLines const& commandLines) const; |
1320 | | |
1321 | | void CreateGeneratedOutputs(std::vector<std::string> const& outputs); |
1322 | | |
1323 | | std::vector<BT<GeneratorAction>> GeneratorActions; |
1324 | | bool GeneratorActionsInvoked = false; |
1325 | | |
1326 | | cmFindPackageStack FindPackageStack; |
1327 | | unsigned int FindPackageStackNextIndex = 0; |
1328 | | |
1329 | | bool ExplicitSbomGenerator = false; |
1330 | | bool DebugFindPkg = false; |
1331 | | |
1332 | | bool CheckSystemVars; |
1333 | | bool CheckCMP0000; |
1334 | | std::set<std::string> WarnedCMP0074; |
1335 | | std::set<std::string> WarnedCMP0144; |
1336 | | bool IsSourceFileTryCompile; |
1337 | | ImportedTargetScope CurrentImportedTargetScope = ImportedTargetScope::Local; |
1338 | | }; |