resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmExportSet.cxx
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"
4
5 #include <algorithm>
6 #include <tuple>
7 #include <utility>
8
9 #include "cmGeneratorTarget.h"
10 #include "cmLocalGenerator.h"
11 #include "cmMessageType.h"
12 #include "cmStringAlgorithms.h"
13 #include "cmTarget.h"
14 #include "cmTargetExport.h"
15
16 cmExportSet::cmExportSet(std::string name)
17   : Name(std::move(name))
18 {
19 }
20
21 cmExportSet::~cmExportSet() = default;
22
23 bool cmExportSet::Compute(cmLocalGenerator* lg)
24 {
25   for (std::unique_ptr<cmTargetExport>& tgtExport : this->TargetExports) {
26     tgtExport->Target = lg->FindGeneratorTargetToUse(tgtExport->TargetName);
27
28     auto const interfaceFileSets =
29       tgtExport->Target->Target->GetAllInterfaceFileSets();
30     auto const fileSetInTargetExport =
31       [&tgtExport, lg](const std::string& fileSetName) -> bool {
32       auto* fileSet = tgtExport->Target->Target->GetFileSet(fileSetName);
33
34       if (!tgtExport->FileSetGenerators.count(fileSet)) {
35         lg->IssueMessage(MessageType::FATAL_ERROR,
36                          cmStrCat("File set \"", fileSetName,
37                                   "\" is listed in interface file sets of ",
38                                   tgtExport->Target->GetName(),
39                                   " but has not been exported"));
40         return false;
41       }
42       return true;
43     };
44
45     if (!std::all_of(interfaceFileSets.begin(), interfaceFileSets.end(),
46                      fileSetInTargetExport)) {
47       return false;
48     }
49   }
50
51   return true;
52 }
53
54 void cmExportSet::AddTargetExport(std::unique_ptr<cmTargetExport> te)
55 {
56   this->TargetExports.emplace_back(std::move(te));
57 }
58
59 void cmExportSet::AddInstallation(cmInstallExportGenerator const* installation)
60 {
61   this->Installations.push_back(installation);
62 }
63
64 cmExportSet& cmExportSetMap::operator[](const std::string& name)
65 {
66   auto it = this->find(name);
67   if (it == this->end()) // Export set not found
68   {
69     auto tup_name = std::make_tuple(name);
70     it = this->emplace(std::piecewise_construct, tup_name, tup_name).first;
71   }
72   return it->second;
73 }