diff --git a/Source/cmExportInstallCMakeConfigGenerator.cxx b/Source/cmExportInstallCMakeConfigGenerator.cxx index eae42b6ee5..2e2f2c66b5 100644 --- a/Source/cmExportInstallCMakeConfigGenerator.cxx +++ b/Source/cmExportInstallCMakeConfigGenerator.cxx @@ -284,23 +284,20 @@ std::string cmExportInstallCMakeConfigGenerator::GetFileSetDirectories( auto configs = gte->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); - cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance()); - auto cge = - ge.Parse(te->FileSetGenerators.at(fileSet->GetName())->GetDestination()); - for (auto const& config : configs) { - auto unescapedDest = cge->Evaluate(gte->LocalGenerator, config, gte); + auto result = te->FileSetGenerators.at(fileSet->GetName()) + ->GetDestination(gte, config); + auto dest = cmOutputConverter::EscapeForCMake( - unescapedDest, cmOutputConverter::WrapQuotes::NoWrap); - if (!cmSystemTools::FileIsFullPath(unescapedDest)) { + result.unescapedDestination, cmOutputConverter::WrapQuotes::NoWrap); + if (!cmSystemTools::FileIsFullPath(result.unescapedDestination)) { dest = cmStrCat("${_IMPORT_PREFIX}/", dest); } auto const& type = fileSet->GetType(); // C++ modules do not support interface file sets which are dependent upon // the configuration. - if (cge->GetHadContextSensitiveCondition() && - type == cm::FileSetMetadata::CXX_MODULES) { + if (result.isConfigDependent && type == cm::FileSetMetadata::CXX_MODULES) { auto* mf = this->IEGen->GetLocalGenerator()->GetMakefile(); std::ostringstream e; e << "The \"" << gte->GetName() << "\" target's interface file set \"" @@ -311,7 +308,7 @@ std::string cmExportInstallCMakeConfigGenerator::GetFileSetDirectories( return std::string{}; } - if (cge->GetHadContextSensitiveCondition() && configs.size() != 1) { + if (result.isConfigDependent && configs.size() != 1) { resultVector.push_back( cmStrCat("\"$<$:", dest, ">\"")); } else { diff --git a/Source/cmExportInstallPackageInfoGenerator.cxx b/Source/cmExportInstallPackageInfoGenerator.cxx index 78eb146299..dd824ab61e 100644 --- a/Source/cmExportInstallPackageInfoGenerator.cxx +++ b/Source/cmExportInstallPackageInfoGenerator.cxx @@ -224,18 +224,14 @@ cmExportInstallPackageInfoGenerator::GetFileSetDirectory( cmGeneratorTarget* gte, cmTargetExport const* te, cmGeneratorFileSet const* fileSet, cm::optional const& config) { - cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance()); - auto cge = - ge.Parse(te->FileSetGenerators.at(fileSet->GetName())->GetDestination()); + auto config_value = config.value_or(""); + auto result = te->FileSetGenerators.at(fileSet->GetName()) + ->GetDestination(gte, config_value); - std::string const unescapedDest = - cge->Evaluate(gte->LocalGenerator, config.value_or(""), gte); - bool const isConfigDependent = cge->GetHadContextSensitiveCondition(); - - if (config && !isConfigDependent) { + if (config && !result.isConfigDependent) { return {}; } - if (!config && isConfigDependent) { + if (!config && result.isConfigDependent) { this->RequiresConfigFiles = true; return {}; } @@ -255,9 +251,9 @@ cmExportInstallPackageInfoGenerator::GetFileSetDirectory( } cm::optional dest = cmOutputConverter::EscapeForCMake( - unescapedDest, cmOutputConverter::WrapQuotes::NoWrap); + result.unescapedDestination, cmOutputConverter::WrapQuotes::NoWrap); - if (!cmSystemTools::FileIsFullPath(unescapedDest)) { + if (!cmSystemTools::FileIsFullPath(result.unescapedDestination)) { dest = cmStrCat("@prefix@/"_s, *dest); } diff --git a/Source/cmExportInstallSbomGenerator.cxx b/Source/cmExportInstallSbomGenerator.cxx index d944383902..3f5f172fd7 100644 --- a/Source/cmExportInstallSbomGenerator.cxx +++ b/Source/cmExportInstallSbomGenerator.cxx @@ -216,15 +216,11 @@ cm::optional cmExportInstallSbomGenerator::GetFileSetDirectory( cmGeneratorTarget* gte, cmTargetExport const* te, cmGeneratorFileSet const* fileSet, cm::optional const& config) { - cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance()); - auto cge = - ge.Parse(te->FileSetGenerators.at(fileSet->GetName())->GetDestination()); + auto config_value = config.value_or(""); + auto result = te->FileSetGenerators.at(fileSet->GetName()) + ->GetDestination(gte, config_value); - std::string const unescapedDest = - cge->Evaluate(gte->LocalGenerator, config.value_or(""), gte); - bool const isConfigDependent = cge->GetHadContextSensitiveCondition(); - - if (config && !isConfigDependent) { + if (config && !result.isConfigDependent) { return {}; } @@ -241,9 +237,9 @@ cm::optional cmExportInstallSbomGenerator::GetFileSetDirectory( } cm::optional dest = cmOutputConverter::EscapeForCMake( - unescapedDest, cmOutputConverter::WrapQuotes::NoWrap); + result.unescapedDestination, cmOutputConverter::WrapQuotes::NoWrap); - if (!cmSystemTools::FileIsFullPath(unescapedDest)) { + if (!cmSystemTools::FileIsFullPath(result.unescapedDestination)) { dest = cmStrCat("@prefix@/"_s, *dest); } diff --git a/Source/cmInstallFileSetGenerator.cxx b/Source/cmInstallFileSetGenerator.cxx index 85b8275ca3..cbe55136e5 100644 --- a/Source/cmInstallFileSetGenerator.cxx +++ b/Source/cmInstallFileSetGenerator.cxx @@ -21,6 +21,7 @@ #include "cmList.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" +#include "cmMakefile.h" #include "cmMessageType.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" @@ -91,11 +92,26 @@ bool cmInstallFileSetGenerator::Compute(cmLocalGenerator* lg) return true; } +std::string cmInstallFileSetGenerator::GetDestination() const +{ + return this->Destination; +} + std::string cmInstallFileSetGenerator::GetDestination( std::string const& config) const { - return cmGeneratorExpression::Evaluate(this->Destination, - this->LocalGenerator, config); + return this->GetDestination(this->Target, config).unescapedDestination; +} + +cmInstallFileSetGenerator::DestinationContext +cmInstallFileSetGenerator::GetDestination(cmGeneratorTarget* gte, + std::string const& config) const +{ + cmGeneratorExpression ge(*gte->Makefile->GetCMakeInstance()); + auto cge = ge.Parse(this->Destination); + + std::string const dest = cge->Evaluate(gte->LocalGenerator, config, gte); + return { dest, cge->GetHadContextSensitiveCondition() }; } void cmInstallFileSetGenerator::GenerateScriptForConfig( diff --git a/Source/cmInstallFileSetGenerator.h b/Source/cmInstallFileSetGenerator.h index ff562011f8..82fe47074c 100644 --- a/Source/cmInstallFileSetGenerator.h +++ b/Source/cmInstallFileSetGenerator.h @@ -9,8 +9,9 @@ #include "cmInstallGenerator.h" -class cmGeneratorTarget; +class cmExportInstallCMakeConfigGenerator; class cmGeneratorFileSet; +class cmGeneratorTarget; class cmListFileBacktrace; class cmLocalGenerator; @@ -28,14 +29,23 @@ public: bool Compute(cmLocalGenerator* lg) override; + struct DestinationContext + { + std::string unescapedDestination; + bool isConfigDependent; + }; std::string GetDestination(std::string const& config) const; - std::string GetDestination() const { return this->Destination; } + DestinationContext GetDestination(cmGeneratorTarget* gt, + std::string const& config) const; bool GetOptional() const { return this->Optional; } std::string GetFileSetName() const { return this->FileSetName; } cmGeneratorFileSet const* GetFileSet() const { return this->FileSet; }; cmGeneratorTarget* GetTarget() const { return this->Target; } protected: + friend cmExportInstallCMakeConfigGenerator; + std::string GetDestination() const; + void GenerateScriptForConfig(std::ostream& os, std::string const& config, Indent indent) override;