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
14 #include "cmListFileCache.h"
15 #include "cmLocalGenerator.h"
18 class cmCompiledGeneratorExpression
;
19 class cmGeneratorTarget
;
20 struct cmGeneratorExpressionDAGChecker
;
21 struct cmGeneratorExpressionEvaluator
;
23 /** \class cmGeneratorExpression
24 * \brief Evaluate generate-time query expression syntax.
26 * cmGeneratorExpression instances are used by build system generator
27 * implementations to evaluate the $<> generator expression syntax.
28 * Generator expressions are evaluated just before the generate step
29 * writes strings into the build system. They have knowledge of the
30 * build configuration which is not available at configure time.
32 class cmGeneratorExpression
36 cmGeneratorExpression(cmake
& cmakeInstance
,
37 cmListFileBacktrace backtrace
= cmListFileBacktrace());
38 ~cmGeneratorExpression();
40 cmGeneratorExpression(cmGeneratorExpression
const&) = delete;
41 cmGeneratorExpression
& operator=(cmGeneratorExpression
const&) = delete;
43 std::unique_ptr
<cmCompiledGeneratorExpression
> Parse(
44 std::string input
) const;
46 static std::string
Evaluate(
47 std::string input
, cmLocalGenerator
* lg
, const std::string
& config
,
48 cmGeneratorTarget
const* headTarget
= nullptr,
49 cmGeneratorExpressionDAGChecker
* dagChecker
= nullptr,
50 cmGeneratorTarget
const* currentTarget
= nullptr,
51 std::string
const& language
= std::string());
53 enum PreprocessContext
55 StripAllGeneratorExpressions
,
60 static std::string
Preprocess(const std::string
& input
,
61 PreprocessContext context
,
62 bool resolveRelative
= false);
64 static void Split(const std::string
& input
,
65 std::vector
<std::string
>& output
);
67 static std::string::size_type
Find(const std::string
& input
);
69 static bool IsValidTargetName(const std::string
& input
);
71 static std::string
StripEmptyListElements(const std::string
& input
);
73 static inline bool StartsWithGeneratorExpression(const std::string
& input
)
75 return input
.length() >= 2 && input
[0] == '$' && input
[1] == '<';
77 static inline bool StartsWithGeneratorExpression(const char* input
)
79 return input
!= nullptr && input
[0] == '$' && input
[1] == '<';
82 static void ReplaceInstallPrefix(std::string
& input
,
83 const std::string
& replacement
);
87 cmListFileBacktrace Backtrace
;
90 class cmCompiledGeneratorExpression
93 ~cmCompiledGeneratorExpression();
95 cmCompiledGeneratorExpression(cmCompiledGeneratorExpression
const&) = delete;
96 cmCompiledGeneratorExpression
& operator=(
97 cmCompiledGeneratorExpression
const&) = delete;
99 const std::string
& Evaluate(
100 cmLocalGenerator
* lg
, const std::string
& config
,
101 cmGeneratorTarget
const* headTarget
= nullptr,
102 cmGeneratorExpressionDAGChecker
* dagChecker
= nullptr,
103 cmGeneratorTarget
const* currentTarget
= nullptr,
104 std::string
const& language
= std::string()) const;
106 /** Get set of targets found during evaluations. */
107 std::set
<cmGeneratorTarget
*> const& GetTargets() const
109 return this->DependTargets
;
112 std::set
<std::string
> const& GetSeenTargetProperties() const
114 return this->SeenTargetProperties
;
117 std::set
<cmGeneratorTarget
const*> const& GetAllTargetsSeen() const
119 return this->AllTargetsSeen
;
122 std::string
const& GetInput() const { return this->Input
; }
124 cmListFileBacktrace
GetBacktrace() const { return this->Backtrace
; }
125 bool GetHadContextSensitiveCondition() const
127 return this->HadContextSensitiveCondition
;
129 bool GetHadHeadSensitiveCondition() const
131 return this->HadHeadSensitiveCondition
;
133 bool GetHadLinkLanguageSensitiveCondition() const
135 return this->HadLinkLanguageSensitiveCondition
;
137 std::set
<cmGeneratorTarget
const*> GetSourceSensitiveTargets() const
139 return this->SourceSensitiveTargets
;
142 void SetEvaluateForBuildsystem(bool eval
)
144 this->EvaluateForBuildsystem
= eval
;
147 void SetQuiet(bool quiet
) { this->Quiet
= quiet
; }
149 void GetMaxLanguageStandard(cmGeneratorTarget
const* tgt
,
150 std::map
<std::string
, std::string
>& mapping
);
153 cmCompiledGeneratorExpression(cmake
& cmakeInstance
,
154 cmListFileBacktrace backtrace
,
157 friend class cmGeneratorExpression
;
159 cmListFileBacktrace Backtrace
;
160 std::vector
<std::unique_ptr
<cmGeneratorExpressionEvaluator
>> Evaluators
;
161 const std::string Input
;
162 bool NeedsEvaluation
;
163 bool EvaluateForBuildsystem
= false;
166 mutable std::set
<cmGeneratorTarget
*> DependTargets
;
167 mutable std::set
<cmGeneratorTarget
const*> AllTargetsSeen
;
168 mutable std::set
<std::string
> SeenTargetProperties
;
169 mutable std::map
<cmGeneratorTarget
const*,
170 std::map
<std::string
, std::string
>>
172 mutable std::string Output
;
173 mutable bool HadContextSensitiveCondition
= false;
174 mutable bool HadHeadSensitiveCondition
= false;
175 mutable bool HadLinkLanguageSensitiveCondition
= false;
176 mutable std::set
<cmGeneratorTarget
const*> SourceSensitiveTargets
;
179 class cmGeneratorExpressionInterpreter
182 cmGeneratorExpressionInterpreter(cmLocalGenerator
* localGenerator
,
184 cmGeneratorTarget
const* headTarget
,
185 std::string language
= std::string())
186 : GeneratorExpression(*localGenerator
->GetCMakeInstance())
187 , LocalGenerator(localGenerator
)
188 , Config(std::move(config
))
189 , HeadTarget(headTarget
)
190 , Language(std::move(language
))
194 cmGeneratorExpressionInterpreter(cmGeneratorExpressionInterpreter
const&) =
196 cmGeneratorExpressionInterpreter
& operator=(
197 cmGeneratorExpressionInterpreter
const&) = delete;
199 const std::string
& Evaluate(std::string expression
,
200 const std::string
& property
);
203 cmGeneratorExpression GeneratorExpression
;
204 std::unique_ptr
<cmCompiledGeneratorExpression
> CompiledGeneratorExpression
;
205 cmLocalGenerator
* LocalGenerator
= nullptr;
207 cmGeneratorTarget
const* HeadTarget
= nullptr;
208 std::string Language
;