summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2023-11-09 21:02:40 (GMT)
committerKyle Edwards <kyle.edwards@kitware.com>2023-11-14 14:22:53 (GMT)
commita90968e044d04839e610da9a1adf7b6f390e144a (patch)
tree049c33f6312950d7191790e8eaf6ead9f4ce7a28 /Source
parentf22ecbacb6824881e755b19f498607793e19969c (diff)
downloadCMake-a90968e044d04839e610da9a1adf7b6f390e144a.zip
CMake-a90968e044d04839e610da9a1adf7b6f390e144a.tar.gz
CMake-a90968e044d04839e610da9a1adf7b6f390e144a.tar.bz2
cmExportBuildFileGenerator: Add structs for target exports
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDyndepCollation.cxx6
-rw-r--r--Source/cmExportBuildFileGenerator.cxx26
-rw-r--r--Source/cmExportBuildFileGenerator.h30
-rw-r--r--Source/cmExportCommand.cxx4
4 files changed, 46 insertions, 20 deletions
diff --git a/Source/cmDyndepCollation.cxx b/Source/cmDyndepCollation.cxx
index 75f88b2..e9f7be3 100644
--- a/Source/cmDyndepCollation.cxx
+++ b/Source/cmDyndepCollation.cxx
@@ -242,14 +242,16 @@ Json::Value CollationInformationExports(cmGeneratorTarget const* gt)
auto const& all_build_exports = gt->Makefile->GetExportBuildFileGenerators();
for (auto const& exp : all_build_exports) {
- std::vector<std::string> targets;
+ std::vector<cmExportBuildFileGenerator::TargetExport> targets;
exp->GetTargets(targets);
// Ignore exports sets which are not for this target.
auto const& name = gt->GetName();
bool has_current_target =
std::any_of(targets.begin(), targets.end(),
- [name](std::string const& tname) { return tname == name; });
+ [name](cmExportBuildFileGenerator::TargetExport const& te) {
+ return te.Name == name;
+ });
if (!has_current_target) {
continue;
}
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index eae3a74..291619f 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -10,7 +10,6 @@
#include <utility>
#include <cm/string_view>
-#include <cmext/algorithm>
#include <cmext/string_view>
#include "cmExportSet.h"
@@ -54,15 +53,15 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
{
std::string expectedTargets;
std::string sep;
- std::vector<std::string> targets;
+ std::vector<TargetExport> targets;
bool generatedInterfaceRequired = false;
this->GetTargets(targets);
- for (std::string const& tei : targets) {
- cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei);
+ for (auto const& tei : targets) {
+ cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei.Name);
expectedTargets += sep + this->Namespace + te->GetExportName();
sep = " ";
if (this->ExportedTargets.insert(te).second) {
- this->Exports.push_back(te);
+ this->Exports.emplace_back(te);
} else {
std::ostringstream e;
e << "given target \"" << te->GetName() << "\" more than once.";
@@ -82,7 +81,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
}
// Create all the imported targets.
- for (cmGeneratorTarget* gte : this->Exports) {
+ for (auto const& exp : this->Exports) {
+ cmGeneratorTarget* gte = exp.Target;
this->GenerateImportTargetCode(os, gte, this->GetExportTargetType(gte));
gte->Target->AppendBuildInterfaceIncludes();
@@ -176,7 +176,9 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
std::ostream& os, const std::string& config, std::string const& suffix)
{
- for (cmGeneratorTarget* target : this->Exports) {
+ for (auto const& exp : this->Exports) {
+ cmGeneratorTarget* target = exp.Target;
+
// Collect import properties for this target.
ImportPropertyMap properties;
@@ -308,7 +310,7 @@ void cmExportBuildFileGenerator::HandleMissingTarget(
}
void cmExportBuildFileGenerator::GetTargets(
- std::vector<std::string>& targets) const
+ std::vector<TargetExport>& targets) const
{
if (this->ExportSet) {
for (std::unique_ptr<cmTargetExport> const& te :
@@ -316,7 +318,7 @@ void cmExportBuildFileGenerator::GetTargets(
if (te->NamelinkOnly) {
continue;
}
- targets.push_back(te->TargetName);
+ targets.emplace_back(te->TargetName);
}
return;
}
@@ -334,9 +336,11 @@ cmExportBuildFileGenerator::FindBuildExportInfo(cmGlobalGenerator* gg,
for (auto const& exp : exportSets) {
const auto& exportSet = exp.second;
- std::vector<std::string> targets;
+ std::vector<TargetExport> targets;
exportSet->GetTargets(targets);
- if (cm::contains(targets, name)) {
+ if (std::any_of(
+ targets.begin(), targets.end(),
+ [&name](const TargetExport& te) { return te.Name == name; })) {
exportFiles.push_back(exp.first);
ns = exportSet->GetNamespace();
}
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index c5bb0df..2ac8fba 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -33,15 +33,25 @@ class cmTargetExport;
class cmExportBuildFileGenerator : public cmExportFileGenerator
{
public:
+ struct TargetExport
+ {
+ TargetExport(std::string name)
+ : Name(std::move(name))
+ {
+ }
+
+ std::string Name;
+ };
+
cmExportBuildFileGenerator();
/** Set the list of targets to export. */
- void SetTargets(std::vector<std::string> const& targets)
+ void SetTargets(std::vector<TargetExport> const& targets)
{
this->Targets = targets;
}
- void GetTargets(std::vector<std::string>& targets) const;
- void AppendTargets(std::vector<std::string> const& targets)
+ void GetTargets(std::vector<TargetExport>& targets) const;
+ void AppendTargets(std::vector<TargetExport> const& targets)
{
cm::append(this->Targets, targets);
}
@@ -99,9 +109,19 @@ protected:
std::pair<std::vector<std::string>, std::string> FindBuildExportInfo(
cmGlobalGenerator* gg, const std::string& name);
- std::vector<std::string> Targets;
+ struct TargetExportPrivate
+ {
+ TargetExportPrivate(cmGeneratorTarget* target)
+ : Target(target)
+ {
+ }
+
+ cmGeneratorTarget* Target;
+ };
+
+ std::vector<TargetExport> Targets;
cmExportSet* ExportSet;
- std::vector<cmGeneratorTarget*> Exports;
+ std::vector<TargetExportPrivate> Exports;
cmLocalGenerator* LG;
// The directory for C++ module information.
std::string CxxModulesDirectory;
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index cf1f4ad..e7a69b0 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -204,7 +204,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
fname = dir + "/" + fname;
}
- std::vector<std::string> targets;
+ std::vector<cmExportBuildFileGenerator::TargetExport> targets;
cmGlobalGenerator* gg = mf.GetGlobalGenerator();
@@ -242,7 +242,7 @@ bool cmExportCommand(std::vector<std::string> const& args,
status.SetError(e.str());
return false;
}
- targets.push_back(currentTarget);
+ targets.emplace_back(currentTarget);
}
if (arguments.Append) {
if (cmExportBuildFileGenerator* ebfg =