From cd217739f7883e8cfcac965b1a6cd83d24222c39 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 25 Jul 2024 13:03:42 -0400 Subject: export: Refactor obtaining export information Refactor methods in the build and install export file generators to have the same, simplified API. Expose the resulting method as an abstract method on the base class, so that it can be called from mode-agnostic generators. While we're at it, refactor cmExportInstallFileGenerator's version to use std::any_of. --- Source/cmExportBuildFileGenerator.cxx | 18 +++++++--------- Source/cmExportBuildFileGenerator.h | 6 ++---- Source/cmExportFileGenerator.h | 7 +++++++ Source/cmExportInstallFileGenerator.cxx | 36 +++++++++++++++----------------- Source/cmExportInstallFileGenerator.h | 5 +---- Source/cmExportTryCompileFileGenerator.h | 5 +++++ 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index eefc516..a319f0c 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -138,11 +138,8 @@ void cmExportBuildFileGenerator::HandleMissingTarget( { // The target is not in the export. if (!this->AppendMode) { - std::string const& name = dependee->GetName(); - cmGlobalGenerator* gg = - dependee->GetLocalGenerator()->GetGlobalGenerator(); - auto exportInfo = this->FindBuildExportInfo(gg, name); - std::vector const& exportFiles = exportInfo.first; + auto const& exportInfo = this->FindExportInfo(dependee); + auto const& exportFiles = exportInfo.first; if (exportFiles.size() == 1) { std::string missingTarget = exportInfo.second; @@ -178,14 +175,15 @@ void cmExportBuildFileGenerator::GetTargets( targets = this->Targets; } -std::pair, std::string> -cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg, - std::string const& name) +cmExportFileGenerator::ExportInfo cmExportBuildFileGenerator::FindExportInfo( + cmGeneratorTarget const* target) const { std::vector exportFiles; std::string ns; - auto& exportSets = gg->GetBuildExportSets(); + auto const& name = target->GetName(); + auto& exportSets = + target->GetLocalGenerator()->GetGlobalGenerator()->GetBuildExportSets(); for (auto const& exp : exportSets) { auto const& exportSet = exp.second; @@ -199,7 +197,7 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg, } } - return { exportFiles, ns }; + return { exportFiles, exportFiles.size() == 1 ? ns : std::string{} }; } void cmExportBuildFileGenerator::ComplainAboutMissingTarget( diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h index a4f8c5f..dfd0416 100644 --- a/Source/cmExportBuildFileGenerator.h +++ b/Source/cmExportBuildFileGenerator.h @@ -16,7 +16,6 @@ class cmExportSet; class cmGeneratorTarget; -class cmGlobalGenerator; class cmLocalGenerator; /** \class cmExportBuildCMakeConfigGenerator @@ -82,7 +81,7 @@ protected: void ComplainAboutMissingTarget( cmGeneratorTarget const* depender, cmGeneratorTarget const* dependee, - std::vector const& namespaces) const; + std::vector const& exportFiles) const; void ComplainAboutDuplicateTarget( std::string const& targetName) const override; @@ -105,8 +104,7 @@ protected: return this->CxxModulesDirectory; } - std::pair, std::string> FindBuildExportInfo( - cmGlobalGenerator* gg, std::string const& name); + ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override; using cmExportFileGenerator::PopulateInterfaceProperties; bool PopulateInterfaceProperties(cmGeneratorTarget const* target, diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index 89295f5..f9ee73d 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -126,6 +127,12 @@ protected: virtual void ReportError(std::string const& errorMessage) const = 0; + using ExportInfo = std::pair, std::string>; + + /** Find the set of export files and the unique namespace (if any) for a + * target. */ + virtual ExportInfo FindExportInfo(cmGeneratorTarget const* target) const = 0; + enum FreeTargetsReplace { ReplaceFreeTargets, diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 8738938..5e17131 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -8,6 +8,7 @@ #include #include #include +#include #include "cmExportSet.h" #include "cmGeneratorTarget.h" @@ -204,10 +205,9 @@ void cmExportInstallFileGenerator::HandleMissingTarget( std::string& link_libs, cmGeneratorTarget const* depender, cmGeneratorTarget* dependee) { - std::string const& name = dependee->GetName(); - cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator(); - auto exportInfo = this->FindNamespaces(gg, name); - std::vector const& exportFiles = exportInfo.first; + auto const& exportInfo = this->FindExportInfo(dependee); + auto const& exportFiles = exportInfo.first; + if (exportFiles.size() == 1) { std::string missingTarget = exportInfo.second; @@ -221,26 +221,24 @@ void cmExportInstallFileGenerator::HandleMissingTarget( } } -std::pair, std::string> -cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, - std::string const& name) const +cmExportFileGenerator::ExportInfo cmExportInstallFileGenerator::FindExportInfo( + cmGeneratorTarget const* target) const { std::vector exportFiles; std::string ns; - cmExportSetMap const& exportSets = gg->GetExportSets(); - for (auto const& expIt : exportSets) { - cmExportSet const& exportSet = expIt.second; + auto const& name = target->GetName(); + auto& exportSets = + target->GetLocalGenerator()->GetGlobalGenerator()->GetExportSets(); - bool containsTarget = false; - for (auto const& target : exportSet.GetTargetExports()) { - if (name == target->TargetName) { - containsTarget = true; - break; - } - } + for (auto const& exp : exportSets) { + auto const& exportSet = exp.second; + auto const& targets = exportSet.GetTargetExports(); - if (containsTarget) { + if (std::any_of(targets.begin(), targets.end(), + [&name](std::unique_ptr const& te) { + return te->TargetName == name; + })) { std::vector const* installs = exportSet.GetInstallations(); for (cmInstallExportGenerator const* install : *installs) { @@ -250,7 +248,7 @@ cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, } } - return { exportFiles, ns }; + return { exportFiles, exportFiles.size() == 1 ? ns : std::string{} }; } void cmExportInstallFileGenerator::ComplainAboutMissingTarget( diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 24cda9d..a181b66 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -20,7 +19,6 @@ class cmExportSet; class cmGeneratorTarget; -class cmGlobalGenerator; class cmInstallTargetGenerator; class cmTargetExport; @@ -94,8 +92,7 @@ protected: void ComplainAboutDuplicateTarget( std::string const& targetName) const override; - std::pair, std::string> FindNamespaces( - cmGlobalGenerator* gg, std::string const& name) const; + ExportInfo FindExportInfo(cmGeneratorTarget const* target) const override; void ReportError(std::string const& errorMessage) const override; diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h index 4b290e6..58d1f5e 100644 --- a/Source/cmExportTryCompileFileGenerator.h +++ b/Source/cmExportTryCompileFileGenerator.h @@ -45,6 +45,11 @@ protected: { } + ExportInfo FindExportInfo(cmGeneratorTarget const* /*target*/) const override + { + return { {}, {} }; + } + void PopulateProperties(cmGeneratorTarget const* target, ImportPropertyMap& properties, std::set& emitted); -- cgit v0.12 From e5b73b60e385dbb37418f9707d8efd74fecd7cae Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Thu, 18 Jul 2024 11:20:58 -0400 Subject: export: Generalize GenerateImportFileConfig Move some logic that is specific to CMake-format exports from GenerateImportFileConfig to an overload of GenerateImportConfig, so that the former can be moved (back) to the generic base class. This will allow it to also be used for Common Package Specification exports. To facilitate this, also add a method to get the format-specific character used to separate the export file base name from the config suffix, so that the rest of the logic to determine the file name can be shared. --- Source/cmExportFileGenerator.h | 3 +- Source/cmExportInstallAndroidMKGenerator.h | 2 ++ Source/cmExportInstallCMakeConfigGenerator.cxx | 38 +++--------------------- Source/cmExportInstallCMakeConfigGenerator.h | 7 +++-- Source/cmExportInstallFileGenerator.cxx | 40 ++++++++++++++++++++++++++ Source/cmExportInstallFileGenerator.h | 4 +++ 6 files changed, 56 insertions(+), 38 deletions(-) diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index f9ee73d..f765493 100644 --- a/Source/cmExportFileGenerator.h +++ b/Source/cmExportFileGenerator.h @@ -87,7 +87,8 @@ protected: /** Generate per-configuration target information to the given output stream. */ - void GenerateImportConfig(std::ostream& os, std::string const& config); + virtual void GenerateImportConfig(std::ostream& os, + std::string const& config); /** Each subclass knows where the target files are located. */ virtual void GenerateImportTargetsConfig(std::ostream& os, diff --git a/Source/cmExportInstallAndroidMKGenerator.h b/Source/cmExportInstallAndroidMKGenerator.h index 8fa3d3e..1e1a5a8 100644 --- a/Source/cmExportInstallAndroidMKGenerator.h +++ b/Source/cmExportInstallAndroidMKGenerator.h @@ -40,6 +40,8 @@ public: protected: GenerateType GetGenerateType() const override { return INSTALL; } + char GetConfigFileNameSeparator() const override { return '-'; } + // Implement virtual methods from the superclass. void ReportDuplicateTarget(std::string const& targetName) const; bool GenerateMainFile(std::ostream& os) override; diff --git a/Source/cmExportInstallCMakeConfigGenerator.cxx b/Source/cmExportInstallCMakeConfigGenerator.cxx index e2185ed..e1b2285 100644 --- a/Source/cmExportInstallCMakeConfigGenerator.cxx +++ b/Source/cmExportInstallCMakeConfigGenerator.cxx @@ -13,6 +13,7 @@ #include #include +#include "cmExportFileGenerator.h" #include "cmExportSet.h" #include "cmFileSet.h" #include "cmGeneratedFileStream.h" @@ -224,48 +225,17 @@ void cmExportInstallCMakeConfigGenerator::LoadConfigFiles(std::ostream& os) /* clang-format on */ } -bool cmExportInstallCMakeConfigGenerator::GenerateImportFileConfig( - std::string const& config) +void cmExportInstallCMakeConfigGenerator::GenerateImportConfig( + std::ostream& os, std::string const& config) { - // Skip configurations not enabled for this export. - if (!this->IEGen->InstallsForConfig(config)) { - return true; - } - - // Construct the name of the file to generate. - std::string fileName = cmStrCat(this->FileDir, '/', this->FileBase, '-'); - if (!config.empty()) { - fileName += cmSystemTools::LowerCase(config); - } else { - fileName += "noconfig"; - } - fileName += this->FileExt; - - // Open the output file to generate it. - cmGeneratedFileStream exportFileStream(fileName, true); - if (!exportFileStream) { - std::string se = cmSystemTools::GetLastSystemError(); - std::ostringstream e; - e << "cannot write to file \"" << fileName << "\": " << se; - cmSystemTools::Error(e.str()); - return false; - } - exportFileStream.SetCopyIfDifferent(true); - std::ostream& os = exportFileStream; - // Start with the import file header. this->GenerateImportHeaderCode(os, config); // Generate the per-config target information. - this->GenerateImportConfig(os, config); + this->cmExportFileGenerator::GenerateImportConfig(os, config); // End with the import file footer. this->GenerateImportFooterCode(os); - - // Record this per-config import file. - this->ConfigImportFiles[config] = fileName; - - return true; } void cmExportInstallCMakeConfigGenerator::GenerateImportTargetsConfig( diff --git a/Source/cmExportInstallCMakeConfigGenerator.h b/Source/cmExportInstallCMakeConfigGenerator.h index 2ef9af0..e56836b 100644 --- a/Source/cmExportInstallCMakeConfigGenerator.h +++ b/Source/cmExportInstallCMakeConfigGenerator.h @@ -49,6 +49,10 @@ protected: bool GenerateMainFile(std::ostream& os) override; void GenerateImportTargetsConfig(std::ostream& os, std::string const& config, std::string const& suffix) override; + void GenerateImportConfig(std::ostream& os, + std::string const& config) override; + + char GetConfigFileNameSeparator() const override { return '-'; } /** Generate the relative import prefix. */ virtual void GenerateImportPrefix(std::ostream&); @@ -58,9 +62,6 @@ protected: virtual void CleanupTemporaryVariables(std::ostream&); - /** Generate a per-configuration file for the targets. */ - virtual bool GenerateImportFileConfig(std::string const& config); - std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet, cmTargetExport const* te) override; std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet, diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index 5e17131..e61e8c1 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -11,6 +11,7 @@ #include #include "cmExportSet.h" +#include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGenerator.h" #include "cmInstallTargetGenerator.h" @@ -98,6 +99,45 @@ std::string cmExportInstallFileGenerator::GetImportXcFrameworkLocation( return importedXcFrameworkLocation; } +bool cmExportInstallFileGenerator::GenerateImportFileConfig( + std::string const& config) +{ + // Skip configurations not enabled for this export. + if (!this->IEGen->InstallsForConfig(config)) { + return true; + } + + // Construct the name of the file to generate. + std::string fileName = cmStrCat(this->FileDir, '/', this->FileBase, + this->GetConfigFileNameSeparator()); + if (!config.empty()) { + fileName += cmSystemTools::LowerCase(config); + } else { + fileName += "noconfig"; + } + fileName += this->FileExt; + + // Open the output file to generate it. + cmGeneratedFileStream exportFileStream(fileName, true); + if (!exportFileStream) { + std::string se = cmSystemTools::GetLastSystemError(); + std::ostringstream e; + e << "cannot write to file \"" << fileName << "\": " << se; + cmSystemTools::Error(e.str()); + return false; + } + exportFileStream.SetCopyIfDifferent(true); + std::ostream& os = exportFileStream; + + // Generate the per-config target information. + this->GenerateImportConfig(os, config); + + // Record this per-config import file. + this->ConfigImportFiles[config] = fileName; + + return true; +} + void cmExportInstallFileGenerator::SetImportLocationProperty( std::string const& config, std::string const& suffix, cmInstallTargetGenerator* itgen, ImportPropertyMap& properties, diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index a181b66..86c9949 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -78,6 +78,7 @@ protected: cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash(); return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1); } + virtual char GetConfigFileNameSeparator() const = 0; void HandleMissingTarget(std::string& link_libs, cmGeneratorTarget const* depender, @@ -96,6 +97,9 @@ protected: void ReportError(std::string const& errorMessage) const override; + /** Generate a per-configuration file for the targets. */ + virtual bool GenerateImportFileConfig(std::string const& config); + /** Fill in properties indicating installed file locations. */ void SetImportLocationProperty(std::string const& config, std::string const& suffix, -- cgit v0.12 From 8178fd43e9480384d914bfb2e4bca19991125801 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Fri, 26 Jul 2024 16:40:03 -0400 Subject: export: Fix handling of import prefix Fix some additional places in export generation logic that were still hard-coding the import prefix. Change cmGeneratorExpression::Preprocess to take the desired prefix as an argument. (This replaces taking a boolean whether to resolve relative paths; if a non-empty prefix is given, that is used to resolve relative paths, otherwise relative paths are left alone.) This should ensure that import properties always spell the prefix according to the format being generated. --- Source/cmExportInstallFileGenerator.cxx | 41 +++++++++++++++++---------------- Source/cmExportInstallFileGenerator.h | 3 +++ Source/cmGeneratorExpression.cxx | 14 ++++++----- Source/cmGeneratorExpression.h | 4 +++- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index e61e8c1..7bd754a 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -83,7 +83,8 @@ std::string cmExportInstallFileGenerator::GetImportXcFrameworkLocation( if (!importedXcFrameworkLocation.empty()) { importedXcFrameworkLocation = cmGeneratorExpression::Preprocess( importedXcFrameworkLocation, - cmGeneratorExpression::PreprocessContext::InstallInterface, true); + cmGeneratorExpression::PreprocessContext::InstallInterface, + this->GetImportPrefixWithSlash()); importedXcFrameworkLocation = cmGeneratorExpression::Evaluate( importedXcFrameworkLocation, targetExport->Target->GetLocalGenerator(), config, targetExport->Target, nullptr, targetExport->Target); @@ -156,7 +157,7 @@ void cmExportInstallFileGenerator::SetImportLocationProperty( std::string value; if (!cmSystemTools::FileIsFullPath(dest)) { // The target is installed relative to the installation prefix. - value = "${_IMPORT_PREFIX}/"; + value = std::string{ this->GetImportPrefixWithSlash() }; } value += dest; value += "/"; @@ -399,10 +400,11 @@ bool isSubDirectory(std::string const& a, std::string const& b) return (cmSystemTools::ComparePath(a, b) || cmSystemTools::IsSubDirectory(a, b)); } +} -bool checkInterfaceDirs(std::string const& prepro, - cmGeneratorTarget const* target, - std::string const& prop) +bool cmExportInstallFileGenerator::CheckInterfaceDirs( + std::string const& prepro, cmGeneratorTarget const* target, + std::string const& prop) const { std::string const& installDir = target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); @@ -423,7 +425,7 @@ bool checkInterfaceDirs(std::string const& prepro, if (genexPos == 0) { continue; } - if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) { + if (cmHasPrefix(li, this->GetImportPrefixWithSlash())) { continue; } MessageType messageType = MessageType::FATAL_ERROR; @@ -521,7 +523,6 @@ bool checkInterfaceDirs(std::string const& prepro, } return !hadFatalError; } -} void cmExportInstallFileGenerator::PopulateSourcesInterface( cmGeneratorTarget const* gt, @@ -542,12 +543,12 @@ void cmExportInstallFileGenerator::PopulateSourcesInterface( return; } - std::string prepro = - cmGeneratorExpression::Preprocess(*input, preprocessRule, true); + std::string prepro = cmGeneratorExpression::Preprocess( + *input, preprocessRule, this->GetImportPrefixWithSlash()); if (!prepro.empty()) { this->ResolveTargetsInGeneratorExpressions(prepro, gt); - if (!checkInterfaceDirs(prepro, gt, propName)) { + if (!this->CheckInterfaceDirs(prepro, gt, propName)) { return; } properties[propName] = prepro; @@ -571,7 +572,7 @@ void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface( std::string dirs = cmGeneratorExpression::Preprocess( cmList::to_string(target->Target->GetInstallIncludeDirectoriesEntries(te)), - preprocessRule, true); + preprocessRule, this->GetImportPrefixWithSlash()); this->ReplaceInstallPrefix(dirs); std::unique_ptr cge = ge.Parse(dirs); std::string exportDirs = @@ -605,12 +606,12 @@ void cmExportInstallFileGenerator::PopulateIncludeDirectoriesInterface( std::string includes = (input ? *input : ""); char const* const sep = input ? ";" : ""; includes += sep + exportDirs; - std::string prepro = - cmGeneratorExpression::Preprocess(includes, preprocessRule, true); + std::string prepro = cmGeneratorExpression::Preprocess( + includes, preprocessRule, this->GetImportPrefixWithSlash()); if (!prepro.empty()) { this->ResolveTargetsInGeneratorExpressions(prepro, target); - if (!checkInterfaceDirs(prepro, target, propName)) { + if (!this->CheckInterfaceDirs(prepro, target, propName)) { return; } properties[propName] = prepro; @@ -636,12 +637,12 @@ void cmExportInstallFileGenerator::PopulateLinkDependsInterface( return; } - std::string prepro = - cmGeneratorExpression::Preprocess(*input, preprocessRule, true); + std::string prepro = cmGeneratorExpression::Preprocess( + *input, preprocessRule, this->GetImportPrefixWithSlash()); if (!prepro.empty()) { this->ResolveTargetsInGeneratorExpressions(prepro, gt); - if (!checkInterfaceDirs(prepro, gt, propName)) { + if (!this->CheckInterfaceDirs(prepro, gt, propName)) { return; } properties[propName] = prepro; @@ -667,12 +668,12 @@ void cmExportInstallFileGenerator::PopulateLinkDirectoriesInterface( return; } - std::string prepro = - cmGeneratorExpression::Preprocess(*input, preprocessRule, true); + std::string prepro = cmGeneratorExpression::Preprocess( + *input, preprocessRule, this->GetImportPrefixWithSlash()); if (!prepro.empty()) { this->ResolveTargetsInGeneratorExpressions(prepro, gt); - if (!checkInterfaceDirs(prepro, gt, propName)) { + if (!this->CheckInterfaceDirs(prepro, gt, propName)) { return; } properties[propName] = prepro; diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h index 86c9949..f33ecc1 100644 --- a/Source/cmExportInstallFileGenerator.h +++ b/Source/cmExportInstallFileGenerator.h @@ -145,6 +145,9 @@ protected: std::map> ConfigCxxModuleTargetFiles; private: + bool CheckInterfaceDirs(std::string const& prepro, + cmGeneratorTarget const* target, + std::string const& prop) const; void PopulateCompatibleInterfaceProperties(cmGeneratorTarget const* target, ImportPropertyMap& properties); void PopulateCustomTransitiveInterfaceProperties( diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx index 8e590fa..deb292d 100644 --- a/Source/cmGeneratorExpression.cxx +++ b/Source/cmGeneratorExpression.cxx @@ -7,6 +7,8 @@ #include #include +#include + #include "cmsys/RegularExpression.hxx" #include "cmGeneratorExpressionContext.h" @@ -193,7 +195,7 @@ static std::string stripAllGeneratorExpressions(const std::string& input) } static void prefixItems(const std::string& content, std::string& result, - const std::string& prefix) + const cm::string_view& prefix) { std::vector entries; cmGeneratorExpression::Split(content, entries); @@ -211,7 +213,7 @@ static void prefixItems(const std::string& content, std::string& result, static std::string stripExportInterface( const std::string& input, cmGeneratorExpression::PreprocessContext context, - bool resolveRelative) + cm::string_view importPrefix) { std::string result; @@ -268,8 +270,8 @@ static std::string stripExportInterface( } else if (context == cmGeneratorExpression::InstallInterface && foundGenex == FoundGenex::InstallInterface) { const std::string content = input.substr(pos, c - cStart); - if (resolveRelative) { - prefixItems(content, result, "${_IMPORT_PREFIX}/"); + if (!importPrefix.empty()) { + prefixItems(content, result, importPrefix); } else { result += content; } @@ -359,13 +361,13 @@ void cmGeneratorExpression::Split(const std::string& input, std::string cmGeneratorExpression::Preprocess(const std::string& input, PreprocessContext context, - bool resolveRelative) + cm::string_view importPrefix) { if (context == StripAllGeneratorExpressions) { return stripAllGeneratorExpressions(input); } if (context == BuildInterface || context == InstallInterface) { - return stripExportInterface(input, context, resolveRelative); + return stripExportInterface(input, context, importPrefix); } assert(false && diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h index 71855c9..0abd968 100644 --- a/Source/cmGeneratorExpression.h +++ b/Source/cmGeneratorExpression.h @@ -11,6 +11,8 @@ #include #include +#include + #include "cmListFileCache.h" #include "cmLocalGenerator.h" @@ -59,7 +61,7 @@ public: static std::string Preprocess(const std::string& input, PreprocessContext context, - bool resolveRelative = false); + cm::string_view importPrefix = {}); static void Split(const std::string& input, std::vector& output); -- cgit v0.12