cmGeneratorExpression: Require cmake instance

This commit is contained in:
Kyle Edwards 2022-11-11 11:44:47 -05:00
parent 553794e987
commit 09d7f947d6
19 changed files with 92 additions and 59 deletions

View File

@ -172,7 +172,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(
};
}
cmGeneratorExpression ge(cc.GetBacktrace());
cmGeneratorExpression ge(*lg->GetCMakeInstance(), cc.GetBacktrace());
cmGeneratorTarget const* target{ lg->FindGeneratorTargetToUse(
this->Target) };
@ -417,7 +417,8 @@ std::string cmCustomCommandGenerator::GetDepfile() const
return "";
}
cmGeneratorExpression ge(this->CC->GetBacktrace());
cmGeneratorExpression ge(*this->LG->GetCMakeInstance(),
this->CC->GetBacktrace());
return EvaluateDepfile(depfile, ge, this->LG, this->OutputConfig);
}

View File

@ -379,7 +379,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
const char* propName = "INTERFACE_INCLUDE_DIRECTORIES";
cmValue input = target->GetProperty(propName);
cmGeneratorExpression ge;
cmGeneratorExpression ge(*target->Makefile->GetCMakeInstance());
std::string dirs = cmGeneratorExpression::Preprocess(
cmJoin(target->Target->GetInstallIncludeDirectoriesEntries(te), ";"),

View File

@ -570,7 +570,7 @@ std::string cmExportInstallFileGenerator::GetFileSetDirectories(
auto configs =
gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
cmGeneratorExpression ge;
cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance());
auto cge = ge.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());
for (auto const& config : configs) {
@ -617,7 +617,7 @@ std::string cmExportInstallFileGenerator::GetFileSetFiles(
auto fileEntries = fileSet->CompileFileEntries();
auto directoryEntries = fileSet->CompileDirectoryEntries();
cmGeneratorExpression destGe;
cmGeneratorExpression destGe(*gte->Makefile->GetCMakeInstance());
auto destCge =
destGe.Parse(te->FileSetGenerators.at(fileSet)->GetDestination());

View File

@ -70,7 +70,7 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
return std::string();
}
cmGeneratorExpression ge;
cmGeneratorExpression ge(*tgt->Makefile->GetCMakeInstance());
std::unique_ptr<cmGeneratorExpressionDAGChecker> parentDagChecker;
if (propName == "INTERFACE_LINK_OPTIONS") {

View File

@ -2462,11 +2462,13 @@ void AddEvaluationFile(const std::string& inputName,
{
cmListFileBacktrace lfbt = status.GetMakefile().GetBacktrace();
cmGeneratorExpression outputGe(lfbt);
cmGeneratorExpression outputGe(*status.GetMakefile().GetCMakeInstance(),
lfbt);
std::unique_ptr<cmCompiledGeneratorExpression> outputCge =
outputGe.Parse(outputExpr);
cmGeneratorExpression conditionGe(lfbt);
cmGeneratorExpression conditionGe(*status.GetMakefile().GetCMakeInstance(),
lfbt);
std::unique_ptr<cmCompiledGeneratorExpression> conditionCge =
conditionGe.Parse(condition);

View File

@ -78,9 +78,10 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis)
return false;
}
cmFileSet::cmFileSet(std::string name, std::string type,
cmFileSet::cmFileSet(cmake& cmakeInstance, std::string name, std::string type,
cmFileSetVisibility visibility)
: Name(std::move(name))
: CMakeInstance(cmakeInstance)
, Name(std::move(name))
, Type(std::move(type))
, Visibility(visibility)
{
@ -113,7 +114,7 @@ cmFileSet::CompileFileEntries() const
for (auto const& entry : this->FileEntries) {
for (auto const& ex : cmExpandedList(entry.Value)) {
cmGeneratorExpression ge(entry.Backtrace);
cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace);
auto cge = ge.Parse(ex);
result.push_back(std::move(cge));
}
@ -129,7 +130,7 @@ cmFileSet::CompileDirectoryEntries() const
for (auto const& entry : this->DirectoryEntries) {
for (auto const& ex : cmExpandedList(entry.Value)) {
cmGeneratorExpression ge(entry.Backtrace);
cmGeneratorExpression ge(this->CMakeInstance, entry.Backtrace);
auto cge = ge.Parse(ex);
result.push_back(std::move(cge));
}

View File

@ -17,6 +17,7 @@ struct cmGeneratorExpressionDAGChecker;
class cmGeneratorTarget;
class cmLocalGenerator;
class cmMakefile;
class cmake;
enum class cmFileSetVisibility
{
@ -33,7 +34,7 @@ bool cmFileSetVisibilityIsForInterface(cmFileSetVisibility vis);
class cmFileSet
{
public:
cmFileSet(std::string name, std::string type,
cmFileSet(cmake& cmakeInstance, std::string name, std::string type,
cmFileSetVisibility visibility);
const std::string& GetName() const { return this->Name; }
@ -77,6 +78,7 @@ public:
static bool IsValidName(const std::string& name);
private:
cmake& CMakeInstance;
std::string Name;
std::string Type;
cmFileSetVisibility Visibility;

View File

@ -13,11 +13,14 @@
#include "cmGeneratorExpressionEvaluator.h"
#include "cmGeneratorExpressionLexer.h"
#include "cmGeneratorExpressionParser.h"
#include "cmLocalGenerator.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
cmGeneratorExpression::cmGeneratorExpression(cmListFileBacktrace backtrace)
: Backtrace(std::move(backtrace))
cmGeneratorExpression::cmGeneratorExpression(cmake& cmakeInstance,
cmListFileBacktrace backtrace)
: CMakeInstance(cmakeInstance)
, Backtrace(std::move(backtrace))
{
}
@ -29,7 +32,8 @@ std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
std::string input) const
{
return std::unique_ptr<cmCompiledGeneratorExpression>(
new cmCompiledGeneratorExpression(this->Backtrace, std::move(input)));
new cmCompiledGeneratorExpression(this->CMakeInstance, this->Backtrace,
std::move(input)));
}
std::string cmGeneratorExpression::Evaluate(
@ -39,7 +43,8 @@ std::string cmGeneratorExpression::Evaluate(
cmGeneratorTarget const* currentTarget, std::string const& language)
{
if (Find(input) != std::string::npos) {
cmCompiledGeneratorExpression cge(cmListFileBacktrace(), std::move(input));
cmCompiledGeneratorExpression cge(*lg->GetCMakeInstance(),
cmListFileBacktrace(), std::move(input));
return cge.Evaluate(lg, config, headTarget, dagChecker, currentTarget,
language);
}
@ -97,7 +102,7 @@ const std::string& cmCompiledGeneratorExpression::EvaluateWithContext(
}
cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
cmListFileBacktrace backtrace, std::string input)
cmake& /*cmakeInstance*/, cmListFileBacktrace backtrace, std::string input)
: Backtrace(std::move(backtrace))
, Input(std::move(input))
{

View File

@ -12,10 +12,11 @@
#include <vector>
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
class cmake;
class cmCompiledGeneratorExpression;
class cmGeneratorTarget;
class cmLocalGenerator;
struct cmGeneratorExpressionContext;
struct cmGeneratorExpressionDAGChecker;
struct cmGeneratorExpressionEvaluator;
@ -33,7 +34,8 @@ class cmGeneratorExpression
{
public:
/** Construct. */
cmGeneratorExpression(cmListFileBacktrace backtrace = cmListFileBacktrace());
cmGeneratorExpression(cmake& cmakeInstance,
cmListFileBacktrace backtrace = cmListFileBacktrace());
~cmGeneratorExpression();
cmGeneratorExpression(cmGeneratorExpression const&) = delete;
@ -82,6 +84,7 @@ public:
const std::string& replacement);
private:
cmake& CMakeInstance;
cmListFileBacktrace Backtrace;
};
@ -152,7 +155,8 @@ private:
cmGeneratorExpressionContext& context,
cmGeneratorExpressionDAGChecker* dagChecker) const;
cmCompiledGeneratorExpression(cmListFileBacktrace backtrace,
cmCompiledGeneratorExpression(cmake& cmakeInstance,
cmListFileBacktrace backtrace,
std::string input);
friend class cmGeneratorExpression;
@ -184,7 +188,8 @@ public:
std::string config,
cmGeneratorTarget const* headTarget,
std::string language = std::string())
: LocalGenerator(localGenerator)
: GeneratorExpression(*localGenerator->GetCMakeInstance())
, LocalGenerator(localGenerator)
, Config(std::move(config))
, HeadTarget(headTarget)
, Language(std::move(language))

View File

@ -165,7 +165,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
}
cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace();
cmGeneratorExpression contentGE(lfbt);
cmGeneratorExpression contentGE(*lg->GetCMakeInstance(), lfbt);
std::unique_ptr<cmCompiledGeneratorExpression> inputExpression =
contentGE.Parse(inputContent);

View File

@ -57,7 +57,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
cmGeneratorExpressionDAGChecker* dagChecker,
cmGeneratorTarget const* currentTarget)
{
cmGeneratorExpression ge(context->Backtrace);
cmGeneratorExpression ge(*lg->GetCMakeInstance(), context->Backtrace);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
cge->SetQuiet(context->Quiet);

View File

@ -241,15 +241,16 @@ private:
std::unique_ptr<
cmGeneratorTarget::
TargetPropertyEntry> static CreateTargetPropertyEntry(const BT<std::
string>&
TargetPropertyEntry> static CreateTargetPropertyEntry(cmake& cmakeInstance,
const BT<
std::string>&
propertyValue,
bool
evaluateForBuildsystem =
false)
{
if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) {
cmGeneratorExpression ge(propertyValue.Backtrace);
cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace);
std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(propertyValue.Value);
cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
@ -262,12 +263,13 @@ std::unique_ptr<
}
static void CreatePropertyGeneratorExpressions(
cmBTStringRange entries,
cmake& cmakeInstance, cmBTStringRange entries,
std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
bool evaluateForBuildsystem = false)
{
for (auto const& entry : entries) {
items.push_back(CreateTargetPropertyEntry(entry, evaluateForBuildsystem));
items.push_back(
CreateTargetPropertyEntry(cmakeInstance, entry, evaluateForBuildsystem));
}
}
@ -343,29 +345,36 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
this->GlobalGenerator->ComputeTargetObjectDirectory(this);
CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetIncludeDirectoriesEntries(),
this->IncludeDirectoriesEntries);
CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetCompileOptionsEntries(),
this->CompileOptionsEntries);
CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetCompileFeaturesEntries(),
this->CompileFeaturesEntries);
CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetCompileDefinitionsEntries(),
this->CompileDefinitionsEntries);
CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetLinkOptionsEntries(),
this->LinkOptionsEntries);
CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetLinkDirectoriesEntries(),
this->LinkDirectoriesEntries);
CreatePropertyGeneratorExpressions(t->GetPrecompileHeadersEntries(),
CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
t->GetPrecompileHeadersEntries(),
this->PrecompileHeadersEntries);
CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
this->SourceEntries, true);
CreatePropertyGeneratorExpressions(
*lg->GetCMakeInstance(), t->GetSourceEntries(), this->SourceEntries, true);
this->PolicyMap = t->GetPolicyMap();
@ -753,6 +762,7 @@ void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
this->SourceEntries.insert(
before ? this->SourceEntries.begin() : this->SourceEntries.end(),
CreateTargetPropertyEntry(
*this->LocalGenerator->GetCMakeInstance(),
BT<std::string>(src, this->Makefile->GetBacktrace()), true));
this->ClearSourcesCache();
}
@ -780,6 +790,7 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
before ? this->IncludeDirectoriesEntries.begin()
: this->IncludeDirectoriesEntries.end(),
CreateTargetPropertyEntry(
*this->Makefile->GetCMakeInstance(),
BT<std::string>(src, this->Makefile->GetBacktrace()), true));
}
@ -1653,7 +1664,8 @@ void AddObjectEntries(cmGeneratorTarget const* headTarget,
headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
lib.Target);
std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
cmGeneratorExpression ge(lib.Backtrace);
cmGeneratorExpression ge(*headTarget->Makefile->GetCMakeInstance(),
lib.Backtrace);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
cge->SetEvaluateForBuildsystem(true);
@ -4192,7 +4204,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
}
case cmPolicies::OLD: {
std::unique_ptr<TargetPropertyEntry> entry =
CreateTargetPropertyEntry(*configProp);
CreateTargetPropertyEntry(
*this->LocalGenerator->GetCMakeInstance(), *configProp);
entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
this, config, language, &dagChecker, *entry));
} break;
@ -4778,8 +4791,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
std::vector<std::string> options = cmExpandedList(*linkOptions);
for (const auto& option : options) {
std::unique_ptr<TargetPropertyEntry> entry =
CreateTargetPropertyEntry(option);
std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
*this->LocalGenerator->GetCMakeInstance(), option);
entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
this, config, language, &dagChecker, *entry));
}
@ -4931,8 +4944,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
std::vector<std::string> depends = cmExpandedList(*linkDepends);
for (const auto& depend : depends) {
std::unique_ptr<TargetPropertyEntry> entry =
CreateTargetPropertyEntry(depend);
std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
*this->LocalGenerator->GetCMakeInstance(), depend);
entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
this, config, language, &dagChecker, *entry));
}
@ -6756,7 +6769,8 @@ void cmGeneratorTarget::ExpandLinkItems(
cmMakefile const* mf = this->LocalGenerator->GetMakefile();
LookupLinkItemScope scope{ this->LocalGenerator };
for (BT<std::string> const& entry : entries) {
cmGeneratorExpression ge(entry.Backtrace);
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
entry.Backtrace);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(entry.Value);
cge->SetEvaluateForBuildsystem(true);
std::vector<std::string> libs = cmExpandedList(
@ -8195,7 +8209,8 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
break;
}
}
cmGeneratorExpression ge(entry.Backtrace);
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
entry.Backtrace);
std::unique_ptr<cmCompiledGeneratorExpression> const cge =
ge.Parse(entry.Value);
cge->SetEvaluateForBuildsystem(true);

View File

@ -21,7 +21,7 @@ cmInstalledFile::Property::~Property() = default;
void cmInstalledFile::SetName(cmMakefile* mf, const std::string& name)
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
cmGeneratorExpression ge(backtrace);
cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
this->Name = name;
this->NameExpression = ge.Parse(name);
@ -56,7 +56,7 @@ void cmInstalledFile::AppendProperty(cmMakefile const* mf,
bool /*asString*/)
{
cmListFileBacktrace backtrace = mf->GetBacktrace();
cmGeneratorExpression ge(backtrace);
cmGeneratorExpression ge(*mf->GetCMakeInstance(), backtrace);
Property& property = this->Properties[prop];
property.ValueExpressions.push_back(ge.Parse(value));

View File

@ -4503,7 +4503,7 @@ std::vector<std::string> cmLocalGenerator::ExpandCustomCommandOutputGenex(
std::string const& o, cmListFileBacktrace const& bt)
{
std::vector<std::string> allConfigOutputs;
cmGeneratorExpression ge(bt);
cmGeneratorExpression ge(*this->GetCMakeInstance(), bt);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(o);
std::vector<std::string> configs =
this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);

View File

@ -701,7 +701,7 @@ bool cmLocalNinjaGenerator::HasUniqueByproducts(
{
std::vector<std::string> configs =
this->GetMakefile()->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
cmGeneratorExpression ge(bt);
cmGeneratorExpression ge(*this->GetCMakeInstance(), bt);
for (std::string const& p : byproducts) {
if (cmGeneratorExpression::Find(p) == std::string::npos) {
return false;

View File

@ -2095,7 +2095,7 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
// Evaluate generator expression
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(lfbt);
cmGeneratorExpression ge(*this->Makefile->GetCMakeInstance(), lfbt);
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(val);
genVars.Executable = cge->Evaluate(this->LocalGen, "");
}

View File

@ -2656,8 +2656,9 @@ cmFileSet* cmTarget::GetFileSet(const std::string& name)
std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
const std::string& name, const std::string& type, cmFileSetVisibility vis)
{
auto result = this->impl->FileSets.emplace(
std::make_pair(name, cmFileSet(name, type, vis)));
auto result = this->impl->FileSets.emplace(std::make_pair(
name,
cmFileSet(*this->GetMakefile()->GetCMakeInstance(), name, type, vis)));
if (result.second) {
auto bt = this->impl->Makefile->GetBacktrace();
if (type == this->impl->HeadersFileSets.TypeName) {

View File

@ -127,7 +127,8 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
this->TestGenerated = true;
// Set up generator expression evaluation context.
cmGeneratorExpression ge(this->Test->GetBacktrace());
cmGeneratorExpression ge(*this->Test->GetMakefile()->GetCMakeInstance(),
this->Test->GetBacktrace());
// Determine if policy CMP0110 is set to NEW.
const bool quote_test_name =

View File

@ -2090,7 +2090,7 @@ void cmVisualStudio10TargetGenerator::ParseSettingsProperty(
const std::string& settingsPropertyValue, ConfigToSettings& toolSettings)
{
if (!settingsPropertyValue.empty()) {
cmGeneratorExpression ge;
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(settingsPropertyValue);
@ -2190,7 +2190,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
}
// Figure out if there's any additional flags to use
if (cmValue saf = sf->GetProperty("VS_SHADER_FLAGS")) {
cmGeneratorExpression ge;
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*saf);
for (const std::string& config : this->Configurations) {
@ -2203,7 +2203,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
}
// Figure out if debug information should be generated
if (cmValue sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
cmGeneratorExpression ge;
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sed);
for (const std::string& config : this->Configurations) {
@ -2217,7 +2217,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
}
// Figure out if optimizations should be disabled
if (cmValue sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
cmGeneratorExpression ge;
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*sdo);
for (const std::string& config : this->Configurations) {
@ -2331,7 +2331,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(
this->FinishWritingSource(e2, toolSettings);
if (!deployContent.empty()) {
cmGeneratorExpression ge;
cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(deployContent);
// Deployment location cannot be set on a configuration basis