resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmInstallRuntimeDependencySet.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 "cmInstallRuntimeDependencySet.h"
4
5 #include <set>
6 #include <string>
7 #include <utility>
8
9 #include "cmGeneratorTarget.h"
10 #include "cmGlobalGenerator.h"
11 #include "cmInstallImportedRuntimeArtifactsGenerator.h"
12 #include "cmInstallTargetGenerator.h"
13 #include "cmStateTypes.h"
14 #include "cmTargetDepend.h"
15
16 cmInstallRuntimeDependencySet::cmInstallRuntimeDependencySet(std::string name)
17   : Name(std::move(name))
18 {
19 }
20
21 void cmInstallRuntimeDependencySet::AddExecutable(
22   std::unique_ptr<Item> executable)
23 {
24   this->Executables.push_back(std::move(executable));
25 }
26
27 void cmInstallRuntimeDependencySet::AddLibrary(std::unique_ptr<Item> library)
28 {
29   this->Libraries.push_back(std::move(library));
30 }
31
32 void cmInstallRuntimeDependencySet::AddModule(std::unique_ptr<Item> module)
33 {
34   this->Modules.push_back(std::move(module));
35 }
36
37 bool cmInstallRuntimeDependencySet::AddBundleExecutable(
38   std::unique_ptr<Item> bundleExecutable)
39 {
40   if (this->BundleExecutable) {
41     return false;
42   }
43   this->BundleExecutable = bundleExecutable.get();
44   this->AddExecutable(std::move(bundleExecutable));
45   return true;
46 }
47
48 std::string cmInstallRuntimeDependencySet::TargetItem::GetItemPath(
49   const std::string& config) const
50 {
51   return this->Target->GetTarget()->GetFullPath(config);
52 }
53
54 namespace {
55 const std::set<const cmGeneratorTarget*>& GetTargetDependsClosure(
56   std::map<const cmGeneratorTarget*, std::set<const cmGeneratorTarget*>>&
57     targetDepends,
58   const cmGeneratorTarget* tgt)
59 {
60   auto it = targetDepends.insert({ tgt, {} });
61   auto& retval = it.first->second;
62   if (it.second) {
63     auto const& deps = tgt->GetGlobalGenerator()->GetTargetDirectDepends(tgt);
64     for (auto const& dep : deps) {
65       if (!dep.IsCross() && dep.IsLink()) {
66         auto type = dep->GetType();
67         if (type == cmStateEnums::EXECUTABLE ||
68             type == cmStateEnums::SHARED_LIBRARY ||
69             type == cmStateEnums::MODULE_LIBRARY) {
70           retval.insert(dep);
71         }
72         auto const& depDeps = GetTargetDependsClosure(targetDepends, dep);
73         retval.insert(depDeps.begin(), depDeps.end());
74       }
75     }
76   }
77   return retval;
78 }
79 }
80
81 void cmInstallRuntimeDependencySet::TargetItem::AddPostExcludeFiles(
82   const std::string& config, std::set<std::string>& files,
83   cmInstallRuntimeDependencySet* set) const
84 {
85   for (auto const* dep : GetTargetDependsClosure(set->TargetDepends,
86                                                  this->Target->GetTarget())) {
87     files.insert(dep->GetFullPath(config));
88   }
89 }
90
91 std::string cmInstallRuntimeDependencySet::ImportedTargetItem::GetItemPath(
92   const std::string& config) const
93 {
94   return this->Target->GetTarget()->GetFullPath(config);
95 }