2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2012-09-19 22:18:23 +00:00
|
|
|
#ifndef cmGeneratorExpression_h
|
|
|
|
#define cmGeneratorExpression_h
|
|
|
|
|
2017-08-25 18:39:02 +00:00
|
|
|
#include "cmConfigure.h" // IWYU pragma: keep
|
2016-09-01 18:05:48 +00:00
|
|
|
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <map>
|
2019-07-10 15:38:48 +00:00
|
|
|
#include <memory>
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2019-01-21 16:15:21 +00:00
|
|
|
#include <utility>
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <vector>
|
2009-08-11 13:54:56 +00:00
|
|
|
|
2019-09-30 14:46:28 +00:00
|
|
|
#include "cmListFileCache.h"
|
|
|
|
|
2016-09-01 18:59:28 +00:00
|
|
|
class cmCompiledGeneratorExpression;
|
2015-09-16 02:38:52 +00:00
|
|
|
class cmGeneratorTarget;
|
2015-07-25 14:56:52 +00:00
|
|
|
class cmLocalGenerator;
|
2015-02-22 20:30:44 +00:00
|
|
|
struct cmGeneratorExpressionContext;
|
2012-09-18 11:42:23 +00:00
|
|
|
struct cmGeneratorExpressionDAGChecker;
|
2016-09-01 18:59:28 +00:00
|
|
|
struct cmGeneratorExpressionEvaluator;
|
2012-09-12 13:11:25 +00:00
|
|
|
|
2009-08-11 13:54:56 +00:00
|
|
|
/** \class cmGeneratorExpression
|
|
|
|
* \brief Evaluate generate-time query expression syntax.
|
|
|
|
*
|
|
|
|
* cmGeneratorExpression instances are used by build system generator
|
|
|
|
* implementations to evaluate the $<> generator expression syntax.
|
|
|
|
* Generator expressions are evaluated just before the generate step
|
|
|
|
* writes strings into the build system. They have knowledge of the
|
|
|
|
* build configuration which is not available at configure time.
|
|
|
|
*/
|
|
|
|
class cmGeneratorExpression
|
|
|
|
{
|
|
|
|
public:
|
2012-09-12 13:11:25 +00:00
|
|
|
/** Construct. */
|
2019-01-21 16:15:21 +00:00
|
|
|
cmGeneratorExpression(cmListFileBacktrace backtrace = cmListFileBacktrace());
|
2012-09-11 17:53:38 +00:00
|
|
|
~cmGeneratorExpression();
|
|
|
|
|
2019-01-23 19:30:01 +00:00
|
|
|
cmGeneratorExpression(cmGeneratorExpression const&) = delete;
|
|
|
|
cmGeneratorExpression& operator=(cmGeneratorExpression const&) = delete;
|
|
|
|
|
2017-09-21 21:06:05 +00:00
|
|
|
std::unique_ptr<cmCompiledGeneratorExpression> Parse(
|
2019-09-21 21:39:48 +00:00
|
|
|
std::string input) const;
|
|
|
|
std::unique_ptr<cmCompiledGeneratorExpression> Parse(
|
|
|
|
const char* input) const;
|
2012-09-12 13:11:25 +00:00
|
|
|
|
2019-09-22 07:53:44 +00:00
|
|
|
static std::string Evaluate(
|
|
|
|
std::string input, cmLocalGenerator* lg, const std::string& config,
|
|
|
|
cmGeneratorTarget const* headTarget = nullptr,
|
|
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
|
|
|
|
cmGeneratorTarget const* currentTarget = nullptr,
|
|
|
|
std::string const& language = std::string());
|
|
|
|
static std::string Evaluate(
|
|
|
|
const char* input, cmLocalGenerator* lg, const std::string& config,
|
|
|
|
cmGeneratorTarget const* headTarget = nullptr,
|
|
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
|
|
|
|
cmGeneratorTarget const* currentTarget = nullptr,
|
|
|
|
std::string const& language = std::string());
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
enum PreprocessContext
|
|
|
|
{
|
2012-09-23 11:16:44 +00:00
|
|
|
StripAllGeneratorExpressions,
|
|
|
|
BuildInterface,
|
|
|
|
InstallInterface
|
2012-10-15 08:27:42 +00:00
|
|
|
};
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
static std::string Preprocess(const std::string& input,
|
2013-07-25 07:05:03 +00:00
|
|
|
PreprocessContext context,
|
|
|
|
bool resolveRelative = false);
|
2012-10-15 08:27:42 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
static void Split(const std::string& input,
|
|
|
|
std::vector<std::string>& output);
|
|
|
|
|
|
|
|
static std::string::size_type Find(const std::string& input);
|
2012-12-10 11:00:34 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
static bool IsValidTargetName(const std::string& input);
|
2013-02-06 12:18:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
static std::string StripEmptyListElements(const std::string& input);
|
2013-02-06 12:32:15 +00:00
|
|
|
|
2018-09-22 12:25:21 +00:00
|
|
|
static inline bool StartsWithGeneratorExpression(const std::string& input)
|
|
|
|
{
|
|
|
|
return input.length() >= 2 && input[0] == '$' && input[1] == '<';
|
|
|
|
}
|
|
|
|
static inline bool StartsWithGeneratorExpression(const char* input)
|
|
|
|
{
|
|
|
|
return input != nullptr && input[0] == '$' && input[1] == '<';
|
|
|
|
}
|
|
|
|
|
2019-11-01 20:50:42 +00:00
|
|
|
static void ReplaceInstallPrefix(std::string& input,
|
|
|
|
const std::string& replacement);
|
|
|
|
|
2012-09-12 13:11:25 +00:00
|
|
|
private:
|
2015-07-08 21:52:51 +00:00
|
|
|
cmListFileBacktrace Backtrace;
|
2012-09-12 13:11:25 +00:00
|
|
|
};
|
2010-12-08 18:34:05 +00:00
|
|
|
|
2012-09-12 13:11:25 +00:00
|
|
|
class cmCompiledGeneratorExpression
|
|
|
|
{
|
|
|
|
public:
|
2019-01-23 19:30:01 +00:00
|
|
|
~cmCompiledGeneratorExpression();
|
|
|
|
|
|
|
|
cmCompiledGeneratorExpression(cmCompiledGeneratorExpression const&) = delete;
|
|
|
|
cmCompiledGeneratorExpression& operator=(
|
|
|
|
cmCompiledGeneratorExpression const&) = delete;
|
|
|
|
|
2018-08-09 18:50:17 +00:00
|
|
|
const std::string& Evaluate(
|
2019-09-21 21:39:48 +00:00
|
|
|
cmLocalGenerator* lg, const std::string& config,
|
2018-08-09 18:50:17 +00:00
|
|
|
cmGeneratorTarget const* headTarget = nullptr,
|
|
|
|
cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
|
2019-09-21 22:06:45 +00:00
|
|
|
cmGeneratorTarget const* currentTarget = nullptr,
|
2018-08-09 18:50:17 +00:00
|
|
|
std::string const& language = std::string()) const;
|
2012-09-11 17:53:38 +00:00
|
|
|
|
2010-12-08 18:34:05 +00:00
|
|
|
/** Get set of targets found during evaluations. */
|
2015-10-10 16:41:51 +00:00
|
|
|
std::set<cmGeneratorTarget*> const& GetTargets() const
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
return this->DependTargets;
|
|
|
|
}
|
2012-09-12 13:11:25 +00:00
|
|
|
|
2014-02-10 05:21:34 +00:00
|
|
|
std::set<std::string> const& GetSeenTargetProperties() const
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
return this->SeenTargetProperties;
|
|
|
|
}
|
2012-11-05 13:48:42 +00:00
|
|
|
|
2015-10-10 16:41:51 +00:00
|
|
|
std::set<cmGeneratorTarget const*> const& GetAllTargetsSeen() const
|
2016-05-16 14:34:04 +00:00
|
|
|
{
|
|
|
|
return this->AllTargetsSeen;
|
|
|
|
}
|
2013-02-09 10:12:20 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::string const& GetInput() const { return this->Input; }
|
2012-11-19 18:30:56 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmListFileBacktrace GetBacktrace() const { return this->Backtrace; }
|
2013-02-03 06:33:15 +00:00
|
|
|
bool GetHadContextSensitiveCondition() const
|
|
|
|
{
|
|
|
|
return this->HadContextSensitiveCondition;
|
|
|
|
}
|
2014-07-21 17:02:22 +00:00
|
|
|
bool GetHadHeadSensitiveCondition() const
|
|
|
|
{
|
|
|
|
return this->HadHeadSensitiveCondition;
|
|
|
|
}
|
2015-10-10 16:41:51 +00:00
|
|
|
std::set<cmGeneratorTarget const*> GetSourceSensitiveTargets() const
|
2014-11-04 22:24:54 +00:00
|
|
|
{
|
|
|
|
return this->SourceSensitiveTargets;
|
|
|
|
}
|
2012-12-18 15:16:14 +00:00
|
|
|
|
2014-03-20 14:37:12 +00:00
|
|
|
void SetEvaluateForBuildsystem(bool eval)
|
|
|
|
{
|
|
|
|
this->EvaluateForBuildsystem = eval;
|
|
|
|
}
|
|
|
|
|
2019-09-21 21:39:48 +00:00
|
|
|
void SetQuiet(bool quiet) { this->Quiet = quiet; }
|
|
|
|
|
2015-10-10 16:41:51 +00:00
|
|
|
void GetMaxLanguageStandard(cmGeneratorTarget const* tgt,
|
2016-05-16 14:34:04 +00:00
|
|
|
std::map<std::string, std::string>& mapping);
|
2014-05-15 09:32:30 +00:00
|
|
|
|
2009-08-11 13:54:56 +00:00
|
|
|
private:
|
2018-08-09 18:50:17 +00:00
|
|
|
const std::string& EvaluateWithContext(
|
2016-05-16 14:34:04 +00:00
|
|
|
cmGeneratorExpressionContext& context,
|
|
|
|
cmGeneratorExpressionDAGChecker* dagChecker) const;
|
2015-02-22 20:30:44 +00:00
|
|
|
|
2019-01-21 16:15:21 +00:00
|
|
|
cmCompiledGeneratorExpression(cmListFileBacktrace backtrace,
|
|
|
|
std::string input);
|
2012-09-11 17:53:38 +00:00
|
|
|
|
2012-09-12 13:11:25 +00:00
|
|
|
friend class cmGeneratorExpression;
|
|
|
|
|
2012-11-19 18:30:56 +00:00
|
|
|
cmListFileBacktrace Backtrace;
|
2019-12-05 15:09:27 +00:00
|
|
|
std::vector<std::unique_ptr<cmGeneratorExpressionEvaluator>> Evaluators;
|
2012-11-19 18:30:56 +00:00
|
|
|
const std::string Input;
|
2013-02-28 11:04:23 +00:00
|
|
|
bool NeedsEvaluation;
|
2019-09-21 21:39:48 +00:00
|
|
|
bool EvaluateForBuildsystem;
|
|
|
|
bool Quiet;
|
2012-09-11 17:53:38 +00:00
|
|
|
|
2015-10-10 16:41:51 +00:00
|
|
|
mutable std::set<cmGeneratorTarget*> DependTargets;
|
|
|
|
mutable std::set<cmGeneratorTarget const*> AllTargetsSeen;
|
2014-02-10 05:21:34 +00:00
|
|
|
mutable std::set<std::string> SeenTargetProperties;
|
2015-10-10 16:41:51 +00:00
|
|
|
mutable std::map<cmGeneratorTarget const*,
|
2017-08-25 21:25:09 +00:00
|
|
|
std::map<std::string, std::string>>
|
2016-05-16 14:34:04 +00:00
|
|
|
MaxLanguageStandard;
|
2012-09-12 13:11:25 +00:00
|
|
|
mutable std::string Output;
|
2013-02-03 06:33:15 +00:00
|
|
|
mutable bool HadContextSensitiveCondition;
|
2014-07-21 17:02:22 +00:00
|
|
|
mutable bool HadHeadSensitiveCondition;
|
2016-05-16 14:34:04 +00:00
|
|
|
mutable std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
|
2009-08-11 13:54:56 +00:00
|
|
|
};
|
2012-09-19 22:18:23 +00:00
|
|
|
|
2017-12-01 16:10:45 +00:00
|
|
|
class cmGeneratorExpressionInterpreter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
|
2019-01-21 16:15:21 +00:00
|
|
|
std::string config,
|
2018-09-06 20:49:34 +00:00
|
|
|
cmGeneratorTarget const* headTarget,
|
2019-09-21 21:39:48 +00:00
|
|
|
std::string language = std::string())
|
2017-12-01 16:10:45 +00:00
|
|
|
: LocalGenerator(localGenerator)
|
2019-01-21 16:15:21 +00:00
|
|
|
, Config(std::move(config))
|
2018-09-06 20:49:34 +00:00
|
|
|
, HeadTarget(headTarget)
|
2019-09-21 21:39:48 +00:00
|
|
|
, Language(std::move(language))
|
2017-12-13 15:34:11 +00:00
|
|
|
{
|
|
|
|
}
|
2017-12-01 16:10:45 +00:00
|
|
|
|
2019-01-23 19:30:01 +00:00
|
|
|
cmGeneratorExpressionInterpreter(cmGeneratorExpressionInterpreter const&) =
|
|
|
|
delete;
|
|
|
|
cmGeneratorExpressionInterpreter& operator=(
|
|
|
|
cmGeneratorExpressionInterpreter const&) = delete;
|
|
|
|
|
2019-09-21 21:39:48 +00:00
|
|
|
const std::string& Evaluate(std::string expression,
|
|
|
|
const std::string& property);
|
2018-08-25 23:57:00 +00:00
|
|
|
const std::string& Evaluate(const char* expression,
|
|
|
|
const std::string& property);
|
2017-12-01 16:10:45 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
cmGeneratorExpression GeneratorExpression;
|
|
|
|
std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
|
|
|
|
cmLocalGenerator* LocalGenerator = nullptr;
|
|
|
|
std::string Config;
|
2018-09-06 20:49:34 +00:00
|
|
|
cmGeneratorTarget const* HeadTarget = nullptr;
|
2017-12-13 15:34:11 +00:00
|
|
|
std::string Language;
|
2017-12-01 16:10:45 +00:00
|
|
|
};
|
|
|
|
|
2012-09-19 22:18:23 +00:00
|
|
|
#endif
|