Pārlūkot izejas kodu

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.
Matthew Woehlke 1 gadu atpakaļ
vecāks
revīzija
e5b73b60e3

+ 2 - 1
Source/cmExportFileGenerator.h

@@ -87,7 +87,8 @@ protected:
 
 
   /** Generate per-configuration target information to the given output
   /** Generate per-configuration target information to the given output
       stream.  */
       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.  */
   /** Each subclass knows where the target files are located.  */
   virtual void GenerateImportTargetsConfig(std::ostream& os,
   virtual void GenerateImportTargetsConfig(std::ostream& os,

+ 2 - 0
Source/cmExportInstallAndroidMKGenerator.h

@@ -40,6 +40,8 @@ public:
 protected:
 protected:
   GenerateType GetGenerateType() const override { return INSTALL; }
   GenerateType GetGenerateType() const override { return INSTALL; }
 
 
+  char GetConfigFileNameSeparator() const override { return '-'; }
+
   // Implement virtual methods from the superclass.
   // Implement virtual methods from the superclass.
   void ReportDuplicateTarget(std::string const& targetName) const;
   void ReportDuplicateTarget(std::string const& targetName) const;
   bool GenerateMainFile(std::ostream& os) override;
   bool GenerateMainFile(std::ostream& os) override;

+ 4 - 34
Source/cmExportInstallCMakeConfigGenerator.cxx

@@ -13,6 +13,7 @@
 #include <cm/string_view>
 #include <cm/string_view>
 #include <cmext/string_view>
 #include <cmext/string_view>
 
 
+#include "cmExportFileGenerator.h"
 #include "cmExportSet.h"
 #include "cmExportSet.h"
 #include "cmFileSet.h"
 #include "cmFileSet.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
@@ -224,48 +225,17 @@ void cmExportInstallCMakeConfigGenerator::LoadConfigFiles(std::ostream& os)
   /* clang-format on */
   /* 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.
   // Start with the import file header.
   this->GenerateImportHeaderCode(os, config);
   this->GenerateImportHeaderCode(os, config);
 
 
   // Generate the per-config target information.
   // Generate the per-config target information.
-  this->GenerateImportConfig(os, config);
+  this->cmExportFileGenerator::GenerateImportConfig(os, config);
 
 
   // End with the import file footer.
   // End with the import file footer.
   this->GenerateImportFooterCode(os);
   this->GenerateImportFooterCode(os);
-
-  // Record this per-config import file.
-  this->ConfigImportFiles[config] = fileName;
-
-  return true;
 }
 }
 
 
 void cmExportInstallCMakeConfigGenerator::GenerateImportTargetsConfig(
 void cmExportInstallCMakeConfigGenerator::GenerateImportTargetsConfig(

+ 4 - 3
Source/cmExportInstallCMakeConfigGenerator.h

@@ -49,6 +49,10 @@ protected:
   bool GenerateMainFile(std::ostream& os) override;
   bool GenerateMainFile(std::ostream& os) override;
   void GenerateImportTargetsConfig(std::ostream& os, std::string const& config,
   void GenerateImportTargetsConfig(std::ostream& os, std::string const& config,
                                    std::string const& suffix) override;
                                    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.  */
   /** Generate the relative import prefix.  */
   virtual void GenerateImportPrefix(std::ostream&);
   virtual void GenerateImportPrefix(std::ostream&);
@@ -58,9 +62,6 @@ protected:
 
 
   virtual void CleanupTemporaryVariables(std::ostream&);
   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,
   std::string GetFileSetDirectories(cmGeneratorTarget* gte, cmFileSet* fileSet,
                                     cmTargetExport const* te) override;
                                     cmTargetExport const* te) override;
   std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,
   std::string GetFileSetFiles(cmGeneratorTarget* gte, cmFileSet* fileSet,

+ 40 - 0
Source/cmExportInstallFileGenerator.cxx

@@ -11,6 +11,7 @@
 #include <utility>
 #include <utility>
 
 
 #include "cmExportSet.h"
 #include "cmExportSet.h"
+#include "cmGeneratedFileStream.h"
 #include "cmGeneratorTarget.h"
 #include "cmGeneratorTarget.h"
 #include "cmGlobalGenerator.h"
 #include "cmGlobalGenerator.h"
 #include "cmInstallTargetGenerator.h"
 #include "cmInstallTargetGenerator.h"
@@ -98,6 +99,45 @@ std::string cmExportInstallFileGenerator::GetImportXcFrameworkLocation(
   return importedXcFrameworkLocation;
   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(
 void cmExportInstallFileGenerator::SetImportLocationProperty(
   std::string const& config, std::string const& suffix,
   std::string const& config, std::string const& suffix,
   cmInstallTargetGenerator* itgen, ImportPropertyMap& properties,
   cmInstallTargetGenerator* itgen, ImportPropertyMap& properties,

+ 4 - 0
Source/cmExportInstallFileGenerator.h

@@ -78,6 +78,7 @@ protected:
     cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash();
     cm::string_view const& prefixWithSlash = this->GetImportPrefixWithSlash();
     return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
     return std::string(prefixWithSlash.data(), prefixWithSlash.length() - 1);
   }
   }
+  virtual char GetConfigFileNameSeparator() const = 0;
 
 
   void HandleMissingTarget(std::string& link_libs,
   void HandleMissingTarget(std::string& link_libs,
                            cmGeneratorTarget const* depender,
                            cmGeneratorTarget const* depender,
@@ -96,6 +97,9 @@ protected:
 
 
   void ReportError(std::string const& errorMessage) const override;
   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.  */
   /** Fill in properties indicating installed file locations.  */
   void SetImportLocationProperty(std::string const& config,
   void SetImportLocationProperty(std::string const& config,
                                  std::string const& suffix,
                                  std::string const& suffix,