1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
15 #include <unordered_map>
19 #include <cm/optional>
20 #include <cm/string_view>
22 #include "cmsys/RegularExpression.hxx"
24 #include "cm_sys_stat.h"
26 #include "cmAlgorithms.h"
27 #include "cmCustomCommand.h"
28 #include "cmCustomCommandTypes.h"
29 #include "cmListFileCache.h"
30 #include "cmMessageType.h"
31 #include "cmNewLineStyle.h"
32 #include "cmPolicies.h"
33 #include "cmSourceFileLocationKind.h"
34 #include "cmStateSnapshot.h"
35 #include "cmStateTypes.h"
38 // IWYU does not see that 'std::unordered_map<std::string, cmTarget>'
39 // will not compile without the complete type.
40 #include "cmTarget.h" // IWYU pragma: keep
42 #if !defined(CMAKE_BOOTSTRAP)
43 # include "cmSourceGroup.h"
46 class cmCompiledGeneratorExpression;
47 class cmCustomCommandLines;
48 class cmExecutionStatus;
49 class cmExpandedCommandArgument;
50 class cmExportBuildFileGenerator;
51 class cmFunctionBlocker;
52 class cmGeneratorExpressionEvaluationFile;
53 class cmGlobalGenerator;
54 class cmInstallGenerator;
55 class cmLocalGenerator;
60 class cmTestGenerator;
61 class cmVariableWatch;
64 /** A type-safe wrapper for a string representing a directory id. */
68 cmDirectoryId(std::string s);
73 * \brief Process the input CMakeLists.txt file.
75 * Process and store into memory the input CMakeLists.txt file.
76 * Each CMakeLists.txt file is parsed and the commands found there
77 * are added into the build process.
82 /* Mark a variable as used */
83 void MarkVariableAsUsed(const std::string& var);
84 /* return true if a variable has been initialized */
85 bool VariableInitialized(const std::string&) const;
88 * Construct an empty makefile.
90 cmMakefile(cmGlobalGenerator* globalGenerator,
91 const cmStateSnapshot& snapshot);
98 cmMakefile(cmMakefile const&) = delete;
99 cmMakefile& operator=(cmMakefile const&) = delete;
101 cmDirectoryId GetDirectoryId() const;
103 bool ReadListFile(const std::string& filename);
105 bool ReadListFileAsString(const std::string& content,
106 const std::string& virtualFileName);
108 bool ReadDependentFile(const std::string& filename,
109 bool noPolicyScope = true);
112 * Add a function blocker to this makefile
114 void AddFunctionBlocker(std::unique_ptr<cmFunctionBlocker> fb);
116 /// @return whether we are processing the top CMakeLists.txt file.
117 bool IsRootMakefile() const;
120 * Remove the function blocker whose scope ends with the given command.
121 * This returns ownership of the function blocker object.
123 std::unique_ptr<cmFunctionBlocker> RemoveFunctionBlocker();
126 * Try running cmake and building a file. This is used for dynamically
127 * loaded commands, not as part of the usual build process.
129 int TryCompile(const std::string& srcdir, const std::string& bindir,
130 const std::string& projectName, const std::string& targetName,
132 const std::vector<std::string>* cmakeArgs,
133 std::string& output);
135 bool GetIsSourceFileTryCompile() const;
138 * Help enforce global target name uniqueness.
140 bool EnforceUniqueName(std::string const& name, std::string& msg,
141 bool isCustom = false) const;
143 class GeneratorAction
146 std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>;
148 std::function<void(cmLocalGenerator&, const cmListFileBacktrace&,
149 std::unique_ptr<cmCustomCommand> cc)>;
152 GeneratorAction(ActionT&& action)
153 : Action(std::move(action))
157 GeneratorAction(std::unique_ptr<cmCustomCommand> tcc, CCActionT&& action)
158 : CCAction(std::move(action))
163 void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt);
168 // FIXME: Use std::variant
170 std::unique_ptr<cmCustomCommand> cc;
174 * Register an action that is executed during Generate
176 void AddGeneratorAction(GeneratorAction&& action);
178 /// Helper to insert the constructor GeneratorAction(args...)
179 template <class... Args>
180 void AddGeneratorAction(Args&&... args)
182 AddGeneratorAction(GeneratorAction(std::move(args)...));
186 * Perform generate actions, Library dependency analysis etc before output of
189 void Generate(cmLocalGenerator& lg);
192 * Get the target for PRE_BUILD, PRE_LINK, or POST_BUILD commands.
194 cmTarget* GetCustomCommandTarget(const std::string& target,
195 cmObjectLibraryCommands objLibCommands,
196 const cmListFileBacktrace& lfbt) const;
199 * Dispatch adding a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a
202 cmTarget* AddCustomCommandToTarget(const std::string& target,
203 cmCustomCommandType type,
204 std::unique_ptr<cmCustomCommand> cc);
207 * Called for each file with custom command.
209 using CommandSourceCallback = std::function<void(cmSourceFile*)>;
212 * Dispatch adding a custom command to a source file.
214 void AddCustomCommandToOutput(
215 std::unique_ptr<cmCustomCommand> cc,
216 const CommandSourceCallback& callback = nullptr, bool replace = false);
217 void AddCustomCommandOldStyle(const std::string& target,
218 const std::vector<std::string>& outputs,
219 const std::vector<std::string>& depends,
220 const std::string& source,
221 const cmCustomCommandLines& commandLines,
222 const char* comment);
223 void AppendCustomCommandToOutput(
224 const std::string& output, const std::vector<std::string>& depends,
225 const cmImplicitDependsList& implicit_depends,
226 const cmCustomCommandLines& commandLines);
229 * Add a define flag to the build.
231 void AddDefineFlag(std::string const& definition);
232 void RemoveDefineFlag(std::string const& definition);
233 void AddCompileDefinition(std::string const& definition);
234 void AddCompileOption(std::string const& option);
235 void AddLinkOption(std::string const& option);
236 void AddLinkDirectory(std::string const& directory, bool before = false);
238 /** Create a new imported target with the name and type given. */
239 cmTarget* AddImportedTarget(const std::string& name,
240 cmStateEnums::TargetType type, bool global);
242 std::pair<cmTarget&, bool> CreateNewTarget(
243 const std::string& name, cmStateEnums::TargetType type,
244 cmTarget::PerConfig perConfig = cmTarget::PerConfig::Yes);
246 cmTarget* AddNewTarget(cmStateEnums::TargetType type,
247 const std::string& name);
249 /** Create a target instance for the utility. */
250 cmTarget* AddNewUtilityTarget(const std::string& utilityName,
251 bool excludeFromAll);
254 * Add an executable to the build.
256 cmTarget* AddExecutable(const std::string& exename,
257 const std::vector<std::string>& srcs,
258 bool excludeFromAll = false);
261 * Dispatch adding a utility to the build. A utility target is a command
262 * that is run every time the target is built.
264 cmTarget* AddUtilityCommand(const std::string& utilityName,
266 std::unique_ptr<cmCustomCommand> cc);
269 * Add a subdirectory to the build.
271 void AddSubDirectory(const std::string& fullSrcDir,
272 const std::string& fullBinDir, bool excludeFromAll,
278 * Configure a subdirectory
280 void ConfigureSubDirectory(cmMakefile* mf);
283 * Add an include directory to the build.
285 void AddIncludeDirectories(const std::vector<std::string>& incs,
286 bool before = false);
289 * Add a variable definition to the build. This variable
290 * can be used in CMake to refer to lists, directories, etc.
292 void AddDefinition(const std::string& name, cm::string_view value);
293 void AddDefinition(const std::string& name, cmValue value)
295 this->AddDefinition(name, *value);
298 * Add bool variable definition to the build.
300 void AddDefinitionBool(const std::string& name, bool);
301 //! Add a definition to this makefile and the global cmake cache.
302 void AddCacheDefinition(const std::string& name, const char* value,
303 const char* doc, cmStateEnums::CacheEntryType type,
305 void AddCacheDefinition(const std::string& name, const std::string& value,
306 const char* doc, cmStateEnums::CacheEntryType type,
309 this->AddCacheDefinition(name, value.c_str(), doc, type, force);
313 * Remove a variable definition from the build. This is not valid
314 * for cache entries, and will only affect the current makefile.
316 void RemoveDefinition(const std::string& name);
317 //! Remove a definition from the cache.
318 void RemoveCacheDefinition(const std::string& name) const;
321 * Specify the name of the project for this build.
323 void SetProjectName(std::string const& name);
325 void InitCMAKE_CONFIGURATION_TYPES(std::string const& genDefault);
327 /* Get the default configuration */
328 std::string GetDefaultConfiguration() const;
330 enum GeneratorConfigQuery
332 IncludeEmptyConfig, // Include "" aka noconfig
333 ExcludeEmptyConfig, // Exclude "" aka noconfig
337 /** Get the configurations for dependency checking. */
338 std::vector<std::string> GetGeneratorConfigs(
339 GeneratorConfigQuery mode) const;
342 * Set the name of the library.
344 cmTarget* AddLibrary(const std::string& libname,
345 cmStateEnums::TargetType type,
346 const std::vector<std::string>& srcs,
347 bool excludeFromAll = false);
348 void AddAlias(const std::string& libname, const std::string& tgt,
349 bool globallyVisible = true);
353 * Set, Push, Pop policy values for CMake.
355 bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
356 bool SetPolicy(const char* id, cmPolicies::PolicyStatus status);
357 cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id,
358 bool parent_scope = false) const;
359 bool SetPolicyVersion(std::string const& version_min,
360 std::string const& version_max);
361 void RecordPolicies(cmPolicies::PolicyMap& pm) const;
364 /** Helper class to push and pop policies automatically. */
368 PolicyPushPop(cmMakefile* m);
371 PolicyPushPop(const PolicyPushPop&) = delete;
372 PolicyPushPop& operator=(const PolicyPushPop&) = delete;
375 cmMakefile* Makefile;
377 friend class PolicyPushPop;
380 * Determine if the given context, name pair has already been reported
381 * in context of CMP0054.
383 bool HasCMP0054AlreadyBeenReported(const cmListFileContext& context) const;
385 bool IgnoreErrorsCMP0061() const;
387 std::string const& GetHomeDirectory() const;
388 std::string const& GetHomeOutputDirectory() const;
391 * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
393 void SetScriptModeFile(std::string const& scriptfile);
396 * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
398 void SetArgcArgv(const std::vector<std::string>& args);
400 std::string const& GetCurrentSourceDirectory() const;
401 std::string const& GetCurrentBinaryDirectory() const;
406 * Set a regular expression that include files must match
407 * in order to be considered as part of the depend information.
409 void SetIncludeRegularExpression(const std::string& regex)
411 this->SetProperty("INCLUDE_REGULAR_EXPRESSION", regex.c_str());
413 const std::string& GetIncludeRegularExpression() const
415 return this->GetProperty("INCLUDE_REGULAR_EXPRESSION");
419 * Set a regular expression that include files that are not found
420 * must match in order to be considered a problem.
422 void SetComplainRegularExpression(const std::string& regex)
424 this->ComplainFileRegularExpression = regex;
426 const std::string& GetComplainRegularExpression() const
428 return this->ComplainFileRegularExpression;
431 // -- List of targets
432 using cmTargetMap = std::unordered_map<std::string, cmTarget>;
433 /** Get the target map */
434 cmTargetMap& GetTargets() { return this->Targets; }
435 /** Get the target map - const version */
436 cmTargetMap const& GetTargets() const { return this->Targets; }
438 const std::vector<std::unique_ptr<cmTarget>>& GetOwnedImportedTargets() const
440 return this->ImportedTargetsOwned;
442 std::vector<cmTarget*> GetImportedTargets() const;
444 cmTarget* FindLocalNonAliasTarget(const std::string& name) const;
446 /** Find a target to use in place of the given name. The target
447 returned may be imported or built within the project. */
448 cmTarget* FindTargetToUse(const std::string& name,
449 bool excludeAliases = false) const;
450 bool IsAlias(const std::string& name) const;
452 std::map<std::string, std::string> GetAliasTargets() const
454 return this->AliasTargets;
458 * Mark include directories as system directories.
460 void AddSystemIncludeDirectories(const std::set<std::string>& incs);
462 /** Get a cmSourceFile pointer for a given source name, if the name is
463 * not found, then a null pointer is returned.
465 cmSourceFile* GetSource(
466 const std::string& sourceName,
467 cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous) const;
469 /** Create the source file and return it. generated
470 * indicates if it is a generated file, this is used in determining
471 * how to create the source file instance e.g. name
473 cmSourceFile* CreateSource(
474 const std::string& sourceName, bool generated = false,
475 cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
477 /** Get a cmSourceFile pointer for a given source name, if the name is
478 * not found, then create the source file and return it. generated
479 * indicates if it is a generated file, this is used in determining
480 * how to create the source file instance e.g. name
482 cmSourceFile* GetOrCreateSource(
483 const std::string& sourceName, bool generated = false,
484 cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
486 /** Get a cmSourceFile pointer for a given source name and always mark the
487 * file as generated, if the name is not found, then create the source file
490 cmSourceFile* GetOrCreateGeneratedSource(const std::string& sourceName);
492 void AddTargetObject(std::string const& tgtName, std::string const& objFile);
495 * Given a variable name, return its value (as a string).
496 * If the variable is not found in this makefile instance, the
497 * cache is then queried.
499 cmValue GetDefinition(const std::string&) const;
500 const std::string& GetSafeDefinition(const std::string&) const;
501 const std::string& GetRequiredDefinition(const std::string& name) const;
502 bool IsDefinitionSet(const std::string&) const;
503 bool IsNormalDefinitionSet(const std::string&) const;
504 bool GetDefExpandList(const std::string& name, std::vector<std::string>& out,
505 bool emptyArgs = false) const;
507 * Get the list of all variables in the current space. If argument
508 * cacheonly is specified and is greater than 0, then only cache
509 * variables will be listed.
511 std::vector<std::string> GetDefinitions() const;
514 * Test a boolean variable to see if it is true or false.
515 * If the variable is not found in this makefile instance, the
516 * cache is then queried.
517 * Returns false if no entry defined.
519 bool IsOn(const std::string& name) const;
520 bool IsSet(const std::string& name) const;
522 /** Return whether the target platform is 32-bit. */
523 bool PlatformIs32Bit() const;
525 /** Return whether the target platform is 64-bit. */
526 bool PlatformIs64Bit() const;
527 /** Return whether the target platform is x32. */
528 bool PlatformIsx32() const;
530 /** Apple SDK Type */
542 /** What SDK type points CMAKE_OSX_SYSROOT to? */
543 AppleSDK GetAppleSDKType() const;
545 /** Return whether the target platform is Apple iOS. */
546 bool PlatformIsAppleEmbedded() const;
548 /** Retrieve soname flag for the specified language if supported */
549 const char* GetSONameFlag(const std::string& language) const;
552 * Get a list of preprocessor define flags.
554 std::string GetDefineFlags() const { return this->DefineFlags; }
557 * Make sure CMake can write this file
559 bool CanIWriteThisFile(std::string const& fileName) const;
561 #if !defined(CMAKE_BOOTSTRAP)
563 * Get the vector source groups.
565 const std::vector<cmSourceGroup>& GetSourceGroups() const
567 return this->SourceGroups;
571 * Get the source group
573 cmSourceGroup* GetSourceGroup(const std::vector<std::string>& name) const;
576 * Add a root source group for consideration when adding a new source.
578 void AddSourceGroup(const std::string& name, const char* regex = nullptr);
581 * Add a source group for consideration when adding a new source.
584 void AddSourceGroup(const std::vector<std::string>& name,
585 const char* regex = nullptr);
588 * Get and existing or create a new source group.
590 cmSourceGroup* GetOrCreateSourceGroup(
591 const std::vector<std::string>& folders);
594 * Get and existing or create a new source group.
595 * The name will be tokenized.
597 cmSourceGroup* GetOrCreateSourceGroup(const std::string& name);
600 * find what source group this source is in
602 cmSourceGroup* FindSourceGroup(const std::string& source,
603 std::vector<cmSourceGroup>& groups) const;
607 * Get the vector of list files on which this makefile depends
609 const std::vector<std::string>& GetListFiles() const
611 return this->ListFiles;
613 //! When the file changes cmake will be re-run from the build system.
614 void AddCMakeDependFile(const std::string& file)
616 this->ListFiles.push_back(file);
618 void AddCMakeDependFilesFromUser();
620 std::string FormatListFileStack() const;
623 * Get the current context backtrace.
625 cmListFileBacktrace GetBacktrace() const;
628 * Get the vector of files created by this makefile
630 const std::vector<std::string>& GetOutputFiles() const
632 return this->OutputFiles;
634 void AddCMakeOutputFile(const std::string& file)
636 this->OutputFiles.push_back(file);
640 * Expand all defined variables in the string.
641 * Defined variables come from the this->Definitions map.
642 * They are expanded with ${var} where var is the
643 * entry in the this->Definitions map. Also \@var\@ is
644 * expanded to match autoconf style expansions.
646 const std::string& ExpandVariablesInString(std::string& source) const;
647 const std::string& ExpandVariablesInString(
648 std::string& source, bool escapeQuotes, bool noEscapes,
649 bool atOnly = false, const char* filename = nullptr, long line = -1,
650 bool removeEmpty = false, bool replaceAt = false) const;
653 * Remove any remaining variables in the string. Anything with ${var} or
654 * \@var\@ will be removed.
656 void RemoveVariablesInString(std::string& source, bool atOnly = false) const;
659 * Expand variables in the makefiles ivars such as link directories etc
661 void ExpandVariablesCMP0019();
664 * Replace variables and #cmakedefine lines in the given string.
665 * See cmConfigureFileCommand for details.
667 void ConfigureString(const std::string& input, std::string& output,
668 bool atOnly, bool escapeQuotes) const;
671 * Copy file but change lines according to ConfigureString
673 int ConfigureFile(const std::string& infile, const std::string& outfile,
674 bool copyonly, bool atOnly, bool escapeQuotes,
675 mode_t permissions = 0, cmNewLineStyle = cmNewLineStyle());
677 enum class CommandMissingFromStack
684 * Print a command's invocation
686 void PrintCommandTrace(
687 cmListFileFunction const& lff, cmListFileBacktrace const& bt,
688 CommandMissingFromStack missing = CommandMissingFromStack::No) const;
691 * Set a callback that is invoked whenever ExecuteCommand is called.
693 void OnExecuteCommand(std::function<void()> callback);
696 * Execute a single CMake command. Returns true if the command
697 * succeeded or false if it failed.
699 bool ExecuteCommand(const cmListFileFunction& lff, cmExecutionStatus& status,
700 cm::optional<std::string> deferId = {});
702 //! Enable support for named language, if nil then all languages are
704 void EnableLanguage(std::vector<std::string> const& languages,
707 cmState* GetState() const;
710 * Get the variable watch. This is used to determine when certain variables
713 #ifndef CMAKE_BOOTSTRAP
714 cmVariableWatch* GetVariableWatch() const;
717 //! Display progress or status message.
718 void DisplayStatus(const std::string&, float) const;
721 * Expand the given list file arguments into the full set after
722 * variable replacement and list expansion.
724 bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
725 std::vector<std::string>& outArgs) const;
726 bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
727 std::vector<cmExpandedCommandArgument>& outArgs) const;
732 cmake* GetCMakeInstance() const;
733 cmMessenger* GetMessenger() const;
734 cmGlobalGenerator* GetGlobalGenerator() const;
737 * Get all the source files this makefile knows about
739 const std::vector<std::unique_ptr<cmSourceFile>>& GetSourceFiles() const
741 return this->SourceFiles;
744 std::vector<cmTarget*> const& GetOrderedTargets() const
746 return this->OrderedTargets;
749 //! Add a new cmTest to the list of tests for this makefile.
750 cmTest* CreateTest(const std::string& testName);
752 /** Get a cmTest pointer for a given test name, if the name is
753 * not found, then a null pointer is returned.
755 cmTest* GetTest(const std::string& testName) const;
758 * Get all tests that run under the given configuration.
760 void GetTests(const std::string& config, std::vector<cmTest*>& tests) const;
763 * Return a location of a file in cmake or custom modules directory
765 std::string GetModulesFile(const std::string& name) const
768 std::string debugBuffer;
769 return this->GetModulesFile(name, system, false, debugBuffer);
773 * Return a location of a file in cmake or custom modules directory
775 std::string GetModulesFile(const std::string& name, bool& system) const
777 std::string debugBuffer;
778 return this->GetModulesFile(name, system, false, debugBuffer);
781 std::string GetModulesFile(const std::string& name, bool& system, bool debug,
782 std::string& debugBuffer) const;
784 //! Set/Get a property of this directory
785 void SetProperty(const std::string& prop, const char* value);
786 void SetProperty(const std::string& prop, cmValue value);
787 void SetProperty(const std::string& prop, const std::string& value)
789 this->SetProperty(prop, cmValue(value));
791 void AppendProperty(const std::string& prop, const std::string& value,
792 bool asString = false);
793 cmValue GetProperty(const std::string& prop) const;
794 cmValue GetProperty(const std::string& prop, bool chain) const;
795 bool GetPropertyAsBool(const std::string& prop) const;
796 std::vector<std::string> GetPropertyKeys() const;
798 //! Initialize a makefile from its parent
799 void InitializeFromParent(cmMakefile* parent);
801 void AddInstallGenerator(std::unique_ptr<cmInstallGenerator> g);
803 std::vector<std::unique_ptr<cmInstallGenerator>>& GetInstallGenerators()
805 return this->InstallGenerators;
807 const std::vector<std::unique_ptr<cmInstallGenerator>>&
808 GetInstallGenerators() const
810 return this->InstallGenerators;
813 void AddTestGenerator(std::unique_ptr<cmTestGenerator> g);
815 const std::vector<std::unique_ptr<cmTestGenerator>>& GetTestGenerators()
818 return this->TestGenerators;
821 class FunctionPushPop
824 FunctionPushPop(cmMakefile* mf, std::string const& fileName,
825 cmPolicies::PolicyMap const& pm);
828 FunctionPushPop(const FunctionPushPop&) = delete;
829 FunctionPushPop& operator=(const FunctionPushPop&) = delete;
831 void Quiet() { this->ReportError = false; }
834 cmMakefile* Makefile;
835 bool ReportError = true;
841 MacroPushPop(cmMakefile* mf, std::string const& fileName,
842 cmPolicies::PolicyMap const& pm);
845 MacroPushPop(const MacroPushPop&) = delete;
846 MacroPushPop& operator=(const MacroPushPop&) = delete;
848 void Quiet() { this->ReportError = false; }
851 cmMakefile* Makefile;
852 bool ReportError = true;
855 void PushFunctionScope(std::string const& fileName,
856 cmPolicies::PolicyMap const& pm);
857 void PopFunctionScope(bool reportError);
858 void PushMacroScope(std::string const& fileName,
859 cmPolicies::PolicyMap const& pm);
860 void PopMacroScope(bool reportError);
863 void RaiseScope(const std::string& var, const char* value);
865 // push and pop loop scopes
866 void PushLoopBlockBarrier();
867 void PopLoopBlockBarrier();
869 bool IsImportedTargetGlobalScope() const;
871 enum class ImportedTargetScope
877 /** Helper class to manage whether imported packages
878 * should be globally scoped based off the find package command
880 class SetGlobalTargetImportScope
883 SetGlobalTargetImportScope(cmMakefile* mk, ImportedTargetScope const scope)
886 if (scope == ImportedTargetScope::Global &&
887 !this->Makefile->IsImportedTargetGlobalScope()) {
888 this->Makefile->CurrentImportedTargetScope = scope;
894 ~SetGlobalTargetImportScope()
897 this->Makefile->CurrentImportedTargetScope =
898 ImportedTargetScope::Local;
903 cmMakefile* Makefile;
907 /** Helper class to push and pop scopes automatically. */
911 ScopePushPop(cmMakefile* m)
914 this->Makefile->PushScope();
917 ~ScopePushPop() { this->Makefile->PopScope(); }
919 ScopePushPop(ScopePushPop const&) = delete;
920 ScopePushPop& operator=(ScopePushPop const&) = delete;
923 cmMakefile* Makefile;
926 void IssueMessage(MessageType t, std::string const& text) const;
928 /** Set whether or not to report a CMP0000 violation. */
929 void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
931 bool CheckCMP0037(std::string const& targetName,
932 cmStateEnums::TargetType targetType) const;
934 cmBTStringRange GetIncludeDirectoriesEntries() const;
935 cmBTStringRange GetCompileOptionsEntries() const;
936 cmBTStringRange GetCompileDefinitionsEntries() const;
937 cmBTStringRange GetLinkOptionsEntries() const;
938 cmBTStringRange GetLinkDirectoriesEntries() const;
940 std::set<std::string> const& GetSystemIncludeDirectories() const
942 return this->SystemIncludeDirectories;
945 bool PolicyOptionalWarningEnabled(std::string const& var) const;
947 void PushLoopBlock();
949 bool IsLoopBlock() const;
952 void StoreMatches(cmsys::RegularExpression& re);
954 cmStateSnapshot GetStateSnapshot() const;
956 const char* GetDefineFlagsCMP0059() const;
958 void EnforceDirectoryLevelRules() const;
960 void AddEvaluationFile(
961 const std::string& inputFile, const std::string& targetName,
962 std::unique_ptr<cmCompiledGeneratorExpression> outputName,
963 std::unique_ptr<cmCompiledGeneratorExpression> condition,
964 const std::string& newLineCharacter, mode_t permissions,
965 bool inputIsContent);
966 const std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>>&
967 GetEvaluationFiles() const;
969 std::vector<std::unique_ptr<cmExportBuildFileGenerator>> const&
970 GetExportBuildFileGenerators() const;
971 void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
972 void AddExportBuildFileGenerator(
973 std::unique_ptr<cmExportBuildFileGenerator> gen);
975 // Maintain a stack of package roots to allow nested PACKAGE_ROOT_PATH
977 std::deque<std::vector<std::string>> FindPackageRootPathStack;
979 class DebugFindPkgRAII
981 cmMakefile* Makefile;
985 DebugFindPkgRAII(cmMakefile* mf, std::string const& pkg);
989 bool GetDebugFindPkgMode() const;
991 void MaybeWarnCMP0074(std::string const& pkg);
992 void MaybeWarnUninitialized(std::string const& variable,
993 const char* sourceFilename) const;
994 bool IsProjectFile(const char* filename) const;
996 int GetRecursionDepth() const;
997 void SetRecursionDepth(int recursionDepth);
999 std::string NewDeferId() const;
1000 bool DeferCall(std::string id, std::string fileName, cmListFileFunction lff);
1001 bool DeferCancelCall(std::string const& id);
1002 cm::optional<std::string> DeferGetCallIds() const;
1003 cm::optional<std::string> DeferGetCall(std::string const& id) const;
1006 // add link libraries and directories to the target
1007 void AddGlobalLinkInformation(cmTarget& target);
1009 mutable std::set<cmListFileContext> CMP0054ReportedIds;
1011 // libraries, classes, and executables
1012 mutable cmTargetMap Targets;
1013 std::map<std::string, std::string> AliasTargets;
1015 std::vector<cmTarget*> OrderedTargets;
1017 std::vector<std::unique_ptr<cmSourceFile>> SourceFiles;
1019 // Because cmSourceFile names are compared in a fuzzy way (see
1020 // cmSourceFileLocation::Match()) we can't have a straight mapping from
1021 // filename to cmSourceFile. To make lookups more efficient we store the
1022 // Name portion of the cmSourceFileLocation and then compare on the list of
1023 // cmSourceFiles that might match that name. Note that on platforms which
1024 // have a case-insensitive filesystem we store the key in all lowercase.
1025 using SourceFileMap =
1026 std::unordered_map<std::string, std::vector<cmSourceFile*>>;
1027 SourceFileMap SourceFileSearchIndex;
1029 // For "Known" paths we can store a direct filename to cmSourceFile map
1030 std::unordered_map<std::string, cmSourceFile*> KnownFileSearchIndex;
1033 std::map<std::string, std::unique_ptr<cmTest>> Tests;
1035 // The set of include directories that are marked as system include
1037 std::set<std::string> SystemIncludeDirectories;
1039 std::vector<std::string> ListFiles;
1040 std::vector<std::string> OutputFiles;
1042 std::vector<std::unique_ptr<cmInstallGenerator>> InstallGenerators;
1043 std::vector<std::unique_ptr<cmTestGenerator>> TestGenerators;
1045 std::string ComplainFileRegularExpression;
1046 std::string DefineFlags;
1048 // Track the value of the computed DEFINITIONS property.
1049 std::string DefineFlagsOrig;
1051 #if !defined(CMAKE_BOOTSTRAP)
1052 std::vector<cmSourceGroup> SourceGroups;
1053 size_t ObjectLibrariesSourceGroupIndex;
1056 cmGlobalGenerator* GlobalGenerator;
1057 bool IsFunctionBlocked(const cmListFileFunction& lff,
1058 cmExecutionStatus& status);
1061 cmStateSnapshot StateSnapshot;
1062 cmListFileBacktrace Backtrace;
1067 // Id is empty for an already-executed or canceled operation.
1069 std::string FilePath;
1070 cmListFileFunction Command;
1072 struct DeferCommands
1074 std::vector<DeferCommand> Commands;
1076 std::unique_ptr<DeferCommands> Defer;
1077 bool DeferRunning = false;
1079 void DoGenerate(cmLocalGenerator& lg);
1081 void RunListFile(cmListFile const& listFile,
1082 const std::string& filenametoread,
1083 DeferCommands* defer = nullptr);
1085 bool ParseDefineFlag(std::string const& definition, bool remove);
1087 bool EnforceUniqueDir(const std::string& srcPath,
1088 const std::string& binPath) const;
1090 std::function<void()> ExecuteCommandCallback;
1091 using FunctionBlockerPtr = std::unique_ptr<cmFunctionBlocker>;
1092 using FunctionBlockersType =
1093 std::stack<FunctionBlockerPtr, std::vector<FunctionBlockerPtr>>;
1094 FunctionBlockersType FunctionBlockers;
1095 std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
1096 void PushFunctionBlockerBarrier();
1097 void PopFunctionBlockerBarrier(bool reportError = true);
1099 std::stack<int> LoopBlockCounter;
1101 mutable cmsys::RegularExpression cmDefineRegex;
1102 mutable cmsys::RegularExpression cmDefine01Regex;
1103 mutable cmsys::RegularExpression cmAtVarRegex;
1104 mutable cmsys::RegularExpression cmNamedCurly;
1106 std::vector<cmMakefile*> UnConfiguredDirectories;
1107 std::vector<std::unique_ptr<cmExportBuildFileGenerator>>
1108 ExportBuildFileGenerators;
1110 std::vector<std::unique_ptr<cmGeneratorExpressionEvaluationFile>>
1113 std::vector<cmExecutionStatus*> ExecutionStatusStack;
1114 friend class cmMakefileCall;
1115 friend class cmParseFileScope;
1117 std::vector<std::unique_ptr<cmTarget>> ImportedTargetsOwned;
1118 using TargetMap = std::unordered_map<std::string, cmTarget*>;
1119 TargetMap ImportedTargets;
1121 // Internal policy stack management.
1122 void PushPolicy(bool weak = false,
1123 cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
1125 void PopSnapshot(bool reportError = true);
1126 friend bool cmCMakePolicyCommand(std::vector<std::string> const& args,
1127 cmExecutionStatus& status);
1129 friend class IncludeScope;
1131 class ListFileScope;
1132 friend class ListFileScope;
1135 friend class DeferScope;
1137 class DeferCallScope;
1138 friend class DeferCallScope;
1140 class BuildsystemFileScope;
1141 friend class BuildsystemFileScope;
1144 MessageType ExpandVariablesInStringOld(std::string& errorstr,
1145 std::string& source,
1146 bool escapeQuotes, bool noEscapes,
1147 bool atOnly, const char* filename,
1148 long line, bool removeEmpty,
1149 bool replaceAt) const;
1151 MessageType ExpandVariablesInStringNew(std::string& errorstr,
1152 std::string& source,
1153 bool escapeQuotes, bool noEscapes,
1154 bool atOnly, const char* filename,
1155 long line, bool replaceAt) const;
1157 bool ValidateCustomCommand(const cmCustomCommandLines& commandLines) const;
1159 void CreateGeneratedOutputs(const std::vector<std::string>& outputs);
1161 std::vector<BT<GeneratorAction>> GeneratorActions;
1162 bool GeneratorActionsInvoked = false;
1164 bool DebugFindPkg = false;
1166 bool CheckSystemVars;
1168 std::set<std::string> WarnedCMP0074;
1169 bool IsSourceFileTryCompile;
1170 mutable bool SuppressSideEffects;
1171 ImportedTargetScope CurrentImportedTargetScope = ImportedTargetScope::Local;