export: Factor out CMake-specific export generation (2/2)

In order to support generation of Common Package Specifications, the
mechanisms CMake uses to export package information need to be made more
abstract. The prior commits began this refactoring; this continues by
(actually) restructuring the classes used to generate the actual export files.
To minimize churn, this introduces virtual base classes and
diamond inheritance in order to separate logic which is format-agnostic
but depends on the export mode (build-tree versus install-tree) from
logic which is format-specific but mode-agnostic.

This could probably be refactored further to use helper classes instead,
and a future commit may do that, however an initial attempt to do that
was proving even more invasive, such that this approach was deemed more
manageable.

While we're at it, add 'const' in more places where possible.
This commit is contained in:
Matthew Woehlke
2024-07-18 12:07:26 -04:00
parent 6c66340a64
commit 20fa4ce8d8
30 changed files with 1106 additions and 4517 deletions

View File

@@ -9,7 +9,7 @@
#include <string>
#include <vector>
#include "cmExportFileGenerator.h"
#include "cmExportCMakeConfigGenerator.h"
class cmFileSet;
class cmGeneratorTarget;
@@ -17,7 +17,7 @@ class cmGlobalGenerator;
class cmMakefile;
class cmTargetExport;
class cmExportTryCompileFileGenerator : public cmExportFileGenerator
class cmExportTryCompileFileGenerator : public cmExportCMakeConfigGenerator
{
public:
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
@@ -30,6 +30,10 @@ public:
protected:
// Implement virtual methods from the superclass.
void ComplainAboutDuplicateTarget(
std::string const& /*targetName*/) const override{};
void ReportError(std::string const& errorMessage) const override;
bool GenerateMainFile(std::ostream& os) override;
void GenerateImportTargetsConfig(std::ostream&, std::string const&,
@@ -50,10 +54,10 @@ protected:
std::string GetFileSetDirectories(cmGeneratorTarget* target,
cmFileSet* fileSet,
cmTargetExport* te) override;
cmTargetExport const* te) override;
std::string GetFileSetFiles(cmGeneratorTarget* target, cmFileSet* fileSet,
cmTargetExport* te) override;
cmTargetExport const* te) override;
std::string GetCxxModulesDirectory() const override { return {}; }
void GenerateCxxModuleConfigInformation(std::string const&,