mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 10:50:16 -06:00
cmExportBuildFileGenerator: Add structs for target exports
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user