Merge branch 'release-3.29'
[kiteware-cmake.git] / Source / cmExportSet.cxx
blobb32bb8dc092b90998901995f5fb82a218f4e9813
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmExportSet.h" // IWYU pragma: associated
5 #include <algorithm>
6 #include <tuple>
7 #include <utility>
9 #include "cmGeneratorTarget.h"
10 #include "cmLocalGenerator.h"
11 #include "cmMessageType.h"
12 #include "cmStringAlgorithms.h"
13 #include "cmTarget.h"
14 #include "cmTargetExport.h" // IWYU pragma: associated
16 cmExportSet::cmExportSet(std::string name)
17 : Name(std::move(name))
21 cmExportSet::~cmExportSet() = default;
23 cmExportSet::PackageDependency& cmExportSet::GetPackageDependencyForSetup(
24 const std::string& name)
26 auto& dep = this->PackageDependencies[name];
27 if (!dep.SpecifiedIndex) {
28 dep.SpecifiedIndex = this->NextPackageDependencyIndex;
29 this->NextPackageDependencyIndex++;
31 return dep;
34 bool cmExportSet::Compute(cmLocalGenerator* lg)
36 for (std::unique_ptr<cmTargetExport>& tgtExport : this->TargetExports) {
37 tgtExport->Target = lg->FindGeneratorTargetToUse(tgtExport->TargetName);
39 auto const interfaceFileSets =
40 tgtExport->Target->Target->GetAllInterfaceFileSets();
41 auto const fileSetInTargetExport =
42 [&tgtExport, lg](const std::string& fileSetName) -> bool {
43 auto* fileSet = tgtExport->Target->Target->GetFileSet(fileSetName);
45 if (!tgtExport->FileSetGenerators.count(fileSet)) {
46 lg->IssueMessage(MessageType::FATAL_ERROR,
47 cmStrCat("File set \"", fileSetName,
48 "\" is listed in interface file sets of ",
49 tgtExport->Target->GetName(),
50 " but has not been exported"));
51 return false;
53 return true;
56 if (!std::all_of(interfaceFileSets.begin(), interfaceFileSets.end(),
57 fileSetInTargetExport)) {
58 return false;
62 return true;
65 void cmExportSet::AddTargetExport(std::unique_ptr<cmTargetExport> te)
67 this->TargetExports.emplace_back(std::move(te));
70 void cmExportSet::AddInstallation(cmInstallExportGenerator const* installation)
72 this->Installations.push_back(installation);
75 void cmExportSet::SetXcFrameworkLocation(const std::string& name,
76 const std::string& location)
78 for (auto& te : this->TargetExports) {
79 if (name == te->TargetName) {
80 te->XcFrameworkLocation = location;
85 cmExportSet& cmExportSetMap::operator[](const std::string& name)
87 auto it = this->find(name);
88 if (it == this->end()) // Export set not found
90 auto tup_name = std::make_tuple(name);
91 it = this->emplace(std::piecewise_construct, tup_name, tup_name).first;
93 return it->second;