1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-15 03:48:02 +08:00

export: Use std::all_of to collect exports

Rewrite cmExport{Build,Install}FileGenerator::CollectExports to use
std::all_of as recommended by clang-tidy.
This commit is contained in:
Matthew Woehlke
2024-07-18 12:44:12 -04:00
parent 20fa4ce8d8
commit ff24058e46
2 changed files with 20 additions and 15 deletions

View File

@@ -115,20 +115,21 @@ void cmExportBuildFileGenerator::SetImportLocationProperty(
bool cmExportBuildFileGenerator::CollectExports( bool cmExportBuildFileGenerator::CollectExports(
std::function<void(cmGeneratorTarget const*)> visitor) std::function<void(cmGeneratorTarget const*)> visitor)
{ {
std::vector<TargetExport> targets; auto pred = [&](cmExportBuildFileGenerator::TargetExport& tei) -> bool {
this->GetTargets(targets);
for (auto const& tei : targets) {
cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei.Name); cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei.Name);
if (this->ExportedTargets.insert(te).second) { if (this->ExportedTargets.insert(te).second) {
this->Exports.emplace_back(te, tei.XcFrameworkLocation); this->Exports.emplace_back(te, tei.XcFrameworkLocation);
visitor(te); visitor(te);
} else { return true;
this->ComplainAboutDuplicateTarget(te->GetName());
return false;
} }
}
return true; this->ComplainAboutDuplicateTarget(te->GetName());
return false;
};
std::vector<TargetExport> targets;
this->GetTargets(targets);
return std::all_of(targets.begin(), targets.end(), pred);
} }
void cmExportBuildFileGenerator::HandleMissingTarget( void cmExportBuildFileGenerator::HandleMissingTarget(

View File

@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportInstallFileGenerator.h" #include "cmExportInstallFileGenerator.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
@@ -313,18 +314,21 @@ std::string cmExportInstallFileGenerator::GetCxxModuleFile() const
bool cmExportInstallFileGenerator::CollectExports( bool cmExportInstallFileGenerator::CollectExports(
std::function<void(cmTargetExport const*)> const& visitor) std::function<void(cmTargetExport const*)> const& visitor)
{ {
for (auto const& te : this->GetExportSet()->GetTargetExports()) { auto pred = [&](std::unique_ptr<cmTargetExport> const& te) -> bool {
if (te->NamelinkOnly) { if (te->NamelinkOnly) {
continue; return true;
} }
if (this->ExportedTargets.insert(te->Target).second) { if (this->ExportedTargets.insert(te->Target).second) {
visitor(te.get()); visitor(te.get());
} else { return true;
this->ComplainAboutDuplicateTarget(te->Target->GetName());
return false;
} }
}
return true; this->ComplainAboutDuplicateTarget(te->Target->GetName());
return false;
};
auto const& targets = this->GetExportSet()->GetTargetExports();
return std::all_of(targets.begin(), targets.end(), pred);
} }
bool cmExportInstallFileGenerator::PopulateInterfaceProperties( bool cmExportInstallFileGenerator::PopulateInterfaceProperties(