diff options
author | Matthew Woehlke <matthew.woehlke@kitware.com> | 2024-07-25 17:03:42 (GMT) |
---|---|---|
committer | Matthew Woehlke <matthew.woehlke@kitware.com> | 2024-07-25 22:33:35 (GMT) |
commit | cd217739f7883e8cfcac965b1a6cd83d24222c39 (patch) | |
tree | c9d6f05413feb4fa36b1e8358982850841d94ae9 | |
parent | 262a89c92b4c736fd07268bf868779256afb0d9d (diff) | |
download | CMake-cd217739f7883e8cfcac965b1a6cd83d24222c39.zip CMake-cd217739f7883e8cfcac965b1a6cd83d24222c39.tar.gz CMake-cd217739f7883e8cfcac965b1a6cd83d24222c39.tar.bz2 |
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.
-rw-r--r-- | Source/cmExportBuildFileGenerator.cxx | 18 | ||||
-rw-r--r-- | Source/cmExportBuildFileGenerator.h | 6 | ||||
-rw-r--r-- | Source/cmExportFileGenerator.h | 7 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.cxx | 36 | ||||
-rw-r--r-- | Source/cmExportInstallFileGenerator.h | 5 | ||||
-rw-r--r-- | 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<std::string> 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::vector<std::string>, std::string> -cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg, - std::string const& name) +cmExportFileGenerator::ExportInfo cmExportBuildFileGenerator::FindExportInfo( + cmGeneratorTarget const* target) const { std::vector<std::string> 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<std::string> const& namespaces) const; + std::vector<std::string> const& exportFiles) const; void ComplainAboutDuplicateTarget( std::string const& targetName) const override; @@ -105,8 +104,7 @@ protected: return this->CxxModulesDirectory; } - std::pair<std::vector<std::string>, 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 <map> #include <set> #include <string> +#include <utility> #include <vector> #include <cm/string_view> @@ -126,6 +127,12 @@ protected: virtual void ReportError(std::string const& errorMessage) const = 0; + using ExportInfo = std::pair<std::vector<std::string>, 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 <memory> #include <set> #include <sstream> +#include <utility> #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<std::string> 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::vector<std::string>, std::string> -cmExportInstallFileGenerator::FindNamespaces(cmGlobalGenerator* gg, - std::string const& name) const +cmExportFileGenerator::ExportInfo cmExportInstallFileGenerator::FindExportInfo( + cmGeneratorTarget const* target) const { std::vector<std::string> 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<cmTargetExport> const& te) { + return te->TargetName == name; + })) { std::vector<cmInstallExportGenerator const*> 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 <map> #include <set> #include <string> -#include <utility> #include <vector> #include <cm/string_view> @@ -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::vector<std::string>, 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<cmGeneratorTarget const*>& emitted); |