diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h index f9ee73d982..f765493ac1 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 8fa3d3e8fe..1e1a5a81d6 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 e2185ed214..e1b22854d2 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 2ef9af0b42..e56836b0bb 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 5e17131b0d..e61e8c1e89 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 a181b6620d..86c99495c4 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,