mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
genex: Simplify cmGeneratorExpressionInterpreter
All callers were constructing with a non-empty target name using the target whose pointer was passed anyway. Drop this argument. Simplify logic accordingly. Re-order constructor arguments to match the cmCompiledGeneratorExpression::Evaluate arguments. Also remove unnecessary getters.
This commit is contained in:
@@ -354,8 +354,8 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
|
||||
lg->GetTargetCompileFlags(gtgt, config, language, flags);
|
||||
|
||||
// Add source file specific flags.
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, gtgt, config,
|
||||
gtgt->GetName(), language);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gtgt,
|
||||
language);
|
||||
|
||||
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
|
||||
if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
|
||||
@@ -381,8 +381,8 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines(
|
||||
cmMakefile* makefile = lg->GetMakefile();
|
||||
const std::string& language = source->GetLanguage();
|
||||
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
lg, target, config, target->GetName(), language);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
|
||||
language);
|
||||
|
||||
// Add the export symbol definition for shared library objects.
|
||||
if (const char* exportMacro = target->GetExportMacro()) {
|
||||
@@ -419,8 +419,8 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes(
|
||||
cmMakefile* makefile = lg->GetMakefile();
|
||||
const std::string& language = source->GetLanguage();
|
||||
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
lg, target, config, target->GetName(), language);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
|
||||
language);
|
||||
|
||||
// Add include directories for this source file
|
||||
const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "cmGeneratorExpressionEvaluator.h"
|
||||
#include "cmGeneratorExpressionLexer.h"
|
||||
#include "cmGeneratorExpressionParser.h"
|
||||
#include "cmGeneratorTarget.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
cmGeneratorExpression::cmGeneratorExpression(
|
||||
@@ -389,14 +390,16 @@ void cmCompiledGeneratorExpression::GetMaxLanguageStandard(
|
||||
const std::string& cmGeneratorExpressionInterpreter::Evaluate(
|
||||
const char* expression, const std::string& property)
|
||||
{
|
||||
if (this->Target.empty()) {
|
||||
return this->EvaluateExpression(expression);
|
||||
}
|
||||
this->CompiledGeneratorExpression =
|
||||
this->GeneratorExpression.Parse(expression);
|
||||
|
||||
// Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS
|
||||
cmGeneratorExpressionDAGChecker dagChecker(
|
||||
this->Target, property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property,
|
||||
nullptr, nullptr);
|
||||
this->HeadTarget->GetName(),
|
||||
property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, nullptr,
|
||||
nullptr);
|
||||
|
||||
return this->EvaluateExpression(expression, &dagChecker);
|
||||
return this->CompiledGeneratorExpression->Evaluate(
|
||||
this->LocalGenerator, this->Config, false, this->HeadTarget, &dagChecker,
|
||||
this->Language);
|
||||
}
|
||||
|
||||
@@ -160,24 +160,15 @@ class cmGeneratorExpressionInterpreter
|
||||
|
||||
public:
|
||||
cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
|
||||
cmGeneratorTarget* generatorTarget,
|
||||
const std::string& config,
|
||||
const std::string& target,
|
||||
const std::string& lang)
|
||||
std::string const& config,
|
||||
cmGeneratorTarget const* headTarget,
|
||||
std::string const& lang = std::string())
|
||||
: LocalGenerator(localGenerator)
|
||||
, GeneratorTarget(generatorTarget)
|
||||
, Config(config)
|
||||
, Target(target)
|
||||
, HeadTarget(headTarget)
|
||||
, Language(lang)
|
||||
{
|
||||
}
|
||||
cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
|
||||
cmGeneratorTarget* generatorTarget,
|
||||
const std::string& config)
|
||||
: cmGeneratorExpressionInterpreter(localGenerator, generatorTarget, config,
|
||||
std::string(), std::string())
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& Evaluate(const char* expression,
|
||||
const std::string& property);
|
||||
@@ -188,47 +179,11 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
cmGeneratorExpression& GetGeneratorExpression()
|
||||
{
|
||||
return this->GeneratorExpression;
|
||||
}
|
||||
|
||||
cmCompiledGeneratorExpression& GetCompiledGeneratorExpression()
|
||||
{
|
||||
return *(this->CompiledGeneratorExpression);
|
||||
}
|
||||
|
||||
cmLocalGenerator* GetLocalGenerator() { return this->LocalGenerator; }
|
||||
|
||||
cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
|
||||
|
||||
const std::string& GetTargetName() const { return this->Target; }
|
||||
const std::string& GetLanguage() const { return this->Language; }
|
||||
|
||||
const std::string& EvaluateExpression(
|
||||
const char* expression,
|
||||
cmGeneratorExpressionDAGChecker* dagChecker = nullptr)
|
||||
{
|
||||
this->CompiledGeneratorExpression =
|
||||
this->GeneratorExpression.Parse(expression);
|
||||
|
||||
if (dagChecker == nullptr) {
|
||||
return this->CompiledGeneratorExpression->Evaluate(
|
||||
this->LocalGenerator, this->Config, false, this->GeneratorTarget);
|
||||
}
|
||||
|
||||
return this->CompiledGeneratorExpression->Evaluate(
|
||||
this->LocalGenerator, this->Config, false, this->GeneratorTarget,
|
||||
dagChecker, this->Language);
|
||||
}
|
||||
|
||||
private:
|
||||
cmGeneratorExpression GeneratorExpression;
|
||||
std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
|
||||
cmLocalGenerator* LocalGenerator = nullptr;
|
||||
cmGeneratorTarget* GeneratorTarget = nullptr;
|
||||
std::string Config;
|
||||
std::string Target;
|
||||
cmGeneratorTarget const* HeadTarget = nullptr;
|
||||
std::string Language;
|
||||
};
|
||||
|
||||
|
||||
@@ -751,11 +751,10 @@ class XCodeGeneratorExpressionInterpreter
|
||||
public:
|
||||
XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile,
|
||||
cmLocalGenerator* localGenerator,
|
||||
cmGeneratorTarget* generatorTarget,
|
||||
cmGeneratorTarget* headTarget,
|
||||
const std::string& lang)
|
||||
: cmGeneratorExpressionInterpreter(localGenerator, generatorTarget,
|
||||
"NO-PER-CONFIG-SUPPORT-IN-XCODE",
|
||||
generatorTarget->GetName(), lang)
|
||||
: cmGeneratorExpressionInterpreter(
|
||||
localGenerator, "NO-PER-CONFIG-SUPPORT-IN-XCODE", headTarget, lang)
|
||||
, SourceFile(sourceFile)
|
||||
{
|
||||
}
|
||||
@@ -767,8 +766,7 @@ public:
|
||||
{
|
||||
const std::string& processed =
|
||||
this->cmGeneratorExpressionInterpreter::Evaluate(expression, property);
|
||||
if (this->GetCompiledGeneratorExpression()
|
||||
.GetHadContextSensitiveCondition()) {
|
||||
if (this->CompiledGeneratorExpression->GetHadContextSensitiveCondition()) {
|
||||
std::ostringstream e;
|
||||
/* clang-format off */
|
||||
e <<
|
||||
@@ -777,7 +775,7 @@ public:
|
||||
"specified for source:\n"
|
||||
" " << this->SourceFile->GetFullPath() << "\n";
|
||||
/* clang-format on */
|
||||
this->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||
}
|
||||
|
||||
return processed;
|
||||
|
||||
@@ -1497,8 +1497,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
|
||||
lang = sourceLang;
|
||||
}
|
||||
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, gt, *i,
|
||||
gt->GetName(), lang);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, *i, gt, lang);
|
||||
|
||||
bool needfc = false;
|
||||
if (!objectName.empty()) {
|
||||
|
||||
@@ -434,8 +434,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
|
||||
std::string config = this->LocalGenerator->GetConfigName();
|
||||
std::string configUpper = cmSystemTools::UpperCase(config);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
this->LocalGenerator, this->GeneratorTarget, config,
|
||||
this->GeneratorTarget->GetName(), lang);
|
||||
this->LocalGenerator, config, this->GeneratorTarget, lang);
|
||||
|
||||
// Add Fortran format flags.
|
||||
if (lang == "Fortran") {
|
||||
|
||||
@@ -136,9 +136,8 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
|
||||
|
||||
// Add source file specific flags.
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
this->LocalGenerator, this->GeneratorTarget,
|
||||
this->LocalGenerator->GetConfigName(), this->GeneratorTarget->GetName(),
|
||||
language);
|
||||
this->LocalGenerator, this->LocalGenerator->GetConfigName(),
|
||||
this->GeneratorTarget, language);
|
||||
|
||||
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
|
||||
if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
|
||||
@@ -188,8 +187,7 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
|
||||
std::set<std::string> defines;
|
||||
const std::string config = this->LocalGenerator->GetConfigName();
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
this->LocalGenerator, this->GeneratorTarget, config,
|
||||
this->GeneratorTarget->GetName(), language);
|
||||
this->LocalGenerator, config, this->GeneratorTarget, language);
|
||||
|
||||
const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
|
||||
if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
|
||||
@@ -217,8 +215,7 @@ std::string cmNinjaTargetGenerator::ComputeIncludes(
|
||||
std::vector<std::string> includes;
|
||||
const std::string config = this->LocalGenerator->GetConfigName();
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
this->LocalGenerator, this->GeneratorTarget, config,
|
||||
this->GeneratorTarget->GetName(), language);
|
||||
this->LocalGenerator, config, this->GeneratorTarget, language);
|
||||
|
||||
const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
|
||||
if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
|
||||
|
||||
@@ -722,8 +722,8 @@ static void PopulateFileGroupData(
|
||||
? languageDataMap.at(kInterfaceSourcesLanguageDataKey)
|
||||
: languageDataMap.at(fileData.Language);
|
||||
cmLocalGenerator* lg = target->GetLocalGenerator();
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
lg, target, config, target->GetName(), fileData.Language);
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
|
||||
fileData.Language);
|
||||
|
||||
std::string compileFlags = ld.Flags;
|
||||
const std::string COMPILE_FLAGS("COMPILE_FLAGS");
|
||||
@@ -817,7 +817,7 @@ static Json::Value DumpSourceFilesList(
|
||||
auto targetProp = target->Target->GetProperty("INTERFACE_SOURCES");
|
||||
if (targetProp != nullptr) {
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
target->GetLocalGenerator(), target, config, target->GetName(), "");
|
||||
target->GetLocalGenerator(), config, target);
|
||||
|
||||
auto evaluatedSources = cmsys::SystemTools::SplitString(
|
||||
genexInterpreter.Evaluate(targetProp, "INTERFACE_SOURCES"), ';');
|
||||
@@ -977,8 +977,7 @@ static void CreateInterfaceSourcesEntry(
|
||||
LanguageData& ld = languageDataMap[kInterfaceSourcesLanguageDataKey];
|
||||
ld.Language = "";
|
||||
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, target, config,
|
||||
target->GetName(), "");
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target);
|
||||
std::vector<std::string> propertyValue;
|
||||
GetTargetProperty(genexInterpreter, target, "INTERFACE_INCLUDE_DIRECTORIES",
|
||||
propertyValue);
|
||||
|
||||
@@ -2117,8 +2117,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
flagtable = gg->GetCSharpFlagTable();
|
||||
}
|
||||
cmGeneratorExpressionInterpreter genexInterpreter(
|
||||
this->LocalGenerator, this->GeneratorTarget, config,
|
||||
this->GeneratorTarget->GetName(), lang);
|
||||
this->LocalGenerator, config, this->GeneratorTarget, lang);
|
||||
cmVS10GeneratorOptions clOptions(
|
||||
this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
|
||||
flagtable, this);
|
||||
|
||||
Reference in New Issue
Block a user