/src/CMake/Source/cmInstallGetRuntimeDependenciesGenerator.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallGetRuntimeDependenciesGenerator.h" |
4 | | |
5 | | #include <memory> |
6 | | #include <ostream> |
7 | | #include <set> |
8 | | #include <string> |
9 | | #include <utility> |
10 | | #include <vector> |
11 | | |
12 | | #include <cm/optional> |
13 | | #include <cm/string_view> |
14 | | #include <cmext/string_view> |
15 | | |
16 | | #include "cmGeneratorExpression.h" |
17 | | #include "cmInstallRuntimeDependencySet.h" |
18 | | #include "cmListFileCache.h" |
19 | | #include "cmLocalGenerator.h" |
20 | | #include "cmMakefile.h" |
21 | | #include "cmOutputConverter.h" |
22 | | #include "cmPolicies.h" |
23 | | #include "cmScriptGenerator.h" |
24 | | #include "cmStringAlgorithms.h" |
25 | | |
26 | | namespace { |
27 | | template <typename T, typename F> |
28 | | void WriteMultiArgument(std::ostream& os, cm::string_view keyword, |
29 | | std::vector<T> const& list, |
30 | | cmScriptGeneratorIndent indent, F transform) |
31 | 0 | { |
32 | 0 | bool first = true; |
33 | 0 | for (auto const& item : list) { |
34 | 0 | cm::optional<std::string> result = transform(item); |
35 | 0 | if (result) { |
36 | 0 | if (first) { |
37 | 0 | os << indent << " " << keyword << "\n"; |
38 | 0 | first = false; |
39 | 0 | } |
40 | 0 | os << indent << " " << *result << "\n"; |
41 | 0 | } |
42 | 0 | } |
43 | 0 | } Unexecuted instantiation: cmInstallGetRuntimeDependenciesGenerator.cxx:void (anonymous namespace)::WriteMultiArgument<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> >, (anonymous namespace)::WriteFilesArgument(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> >, std::__1::allocator<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmScriptGeneratorIndent)::$_0>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> >, std::__1::allocator<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> > > > const&, cmScriptGeneratorIndent, (anonymous namespace)::WriteFilesArgument(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> >, std::__1::allocator<std::__1::unique_ptr<cmInstallRuntimeDependencySet::Item, std::__1::default_delete<cmInstallRuntimeDependencySet::Item> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmScriptGeneratorIndent)::$_0) Unexecuted instantiation: cmInstallGetRuntimeDependenciesGenerator.cxx:void (anonymous namespace)::WriteMultiArgument<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (anonymous namespace)::WriteGenexEvaluatorArgument(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmLocalGenerator*, cmScriptGeneratorIndent)::$_0>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmScriptGeneratorIndent, (anonymous namespace)::WriteGenexEvaluatorArgument(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmLocalGenerator*, cmScriptGeneratorIndent)::$_0) |
44 | | |
45 | | void WriteFilesArgument( |
46 | | std::ostream& os, cm::string_view keyword, |
47 | | std::vector<std::unique_ptr<cmInstallRuntimeDependencySet::Item>> const& |
48 | | items, |
49 | | std::string const& config, cmScriptGeneratorIndent indent) |
50 | 0 | { |
51 | 0 | WriteMultiArgument( |
52 | 0 | os, keyword, items, indent, |
53 | 0 | [config](std::unique_ptr<cmInstallRuntimeDependencySet::Item> const& i) |
54 | 0 | -> std::string { return cmStrCat('"', i->GetItemPath(config), '"'); }); |
55 | 0 | } |
56 | | |
57 | | void WriteGenexEvaluatorArgument(std::ostream& os, cm::string_view keyword, |
58 | | std::vector<std::string> const& genexes, |
59 | | std::string const& config, |
60 | | cmLocalGenerator* lg, |
61 | | cmScriptGeneratorIndent indent) |
62 | 0 | { |
63 | 0 | WriteMultiArgument( |
64 | 0 | os, keyword, genexes, indent, |
65 | 0 | [config, lg](std::string const& genex) -> cm::optional<std::string> { |
66 | 0 | std::string result = cmGeneratorExpression::Evaluate(genex, lg, config); |
67 | 0 | if (result.empty()) { |
68 | 0 | return cm::nullopt; |
69 | 0 | } |
70 | 0 | return cmOutputConverter::EscapeForCMake(result); |
71 | 0 | }); |
72 | 0 | } |
73 | | } |
74 | | |
75 | | cmInstallGetRuntimeDependenciesGenerator:: |
76 | | cmInstallGetRuntimeDependenciesGenerator( |
77 | | cmInstallRuntimeDependencySet* runtimeDependencySet, |
78 | | std::vector<std::string> directories, |
79 | | std::vector<std::string> preIncludeRegexes, |
80 | | std::vector<std::string> preExcludeRegexes, |
81 | | std::vector<std::string> postIncludeRegexes, |
82 | | std::vector<std::string> postExcludeRegexes, |
83 | | std::vector<std::string> postIncludeFiles, |
84 | | std::vector<std::string> postExcludeFiles, std::string libraryComponent, |
85 | | std::string frameworkComponent, bool noInstallRPath, char const* depsVar, |
86 | | char const* rpathPrefix, std::vector<std::string> const& configurations, |
87 | | MessageLevel message, bool exclude_from_all, cmListFileBacktrace backtrace, |
88 | | cmPolicies::PolicyStatus policyStatusCMP0207) |
89 | 0 | : cmInstallGenerator("", configurations, "", message, exclude_from_all, |
90 | 0 | false, std::move(backtrace)) |
91 | 0 | , RuntimeDependencySet(runtimeDependencySet) |
92 | 0 | , Directories(std::move(directories)) |
93 | 0 | , PreIncludeRegexes(std::move(preIncludeRegexes)) |
94 | 0 | , PreExcludeRegexes(std::move(preExcludeRegexes)) |
95 | 0 | , PostIncludeRegexes(std::move(postIncludeRegexes)) |
96 | 0 | , PostExcludeRegexes(std::move(postExcludeRegexes)) |
97 | 0 | , PostIncludeFiles(std::move(postIncludeFiles)) |
98 | 0 | , PostExcludeFiles(std::move(postExcludeFiles)) |
99 | 0 | , LibraryComponent(std::move(libraryComponent)) |
100 | 0 | , FrameworkComponent(std::move(frameworkComponent)) |
101 | 0 | , PolicyStatusCMP0207(policyStatusCMP0207) |
102 | 0 | , NoInstallRPath(noInstallRPath) |
103 | 0 | , DepsVar(depsVar) |
104 | 0 | , RPathPrefix(rpathPrefix) |
105 | 0 | { |
106 | 0 | this->ActionsPerConfig = true; |
107 | 0 | } |
108 | | |
109 | | bool cmInstallGetRuntimeDependenciesGenerator::Compute(cmLocalGenerator* lg) |
110 | 0 | { |
111 | 0 | this->LocalGenerator = lg; |
112 | 0 | return true; |
113 | 0 | } |
114 | | |
115 | | void cmInstallGetRuntimeDependenciesGenerator::GenerateScript(std::ostream& os) |
116 | 0 | { |
117 | | // Track indentation. |
118 | 0 | Indent indent; |
119 | | |
120 | | // Begin this block of installation. |
121 | 0 | os << indent << "if("; |
122 | 0 | if (this->FrameworkComponent.empty() || |
123 | 0 | this->FrameworkComponent == this->LibraryComponent) { |
124 | 0 | os << this->CreateComponentTest(this->LibraryComponent, |
125 | 0 | this->ExcludeFromAll); |
126 | 0 | } else { |
127 | 0 | os << this->CreateComponentTest(this->LibraryComponent, true) << " OR " |
128 | 0 | << this->CreateComponentTest(this->FrameworkComponent, |
129 | 0 | this->ExcludeFromAll); |
130 | 0 | } |
131 | 0 | os << ")\n"; |
132 | | |
133 | | // Generate the script possibly with per-configuration code. |
134 | 0 | this->GenerateScriptConfigs(os, indent.Next()); |
135 | | |
136 | | // End this block of installation. |
137 | 0 | os << indent << "endif()\n\n"; |
138 | 0 | } |
139 | | |
140 | | void cmInstallGetRuntimeDependenciesGenerator::GenerateScriptForConfig( |
141 | | std::ostream& os, std::string const& config, Indent indent) |
142 | 0 | { |
143 | 0 | std::string installNameTool = |
144 | 0 | this->LocalGenerator->GetMakefile()->GetSafeDefinition( |
145 | 0 | "CMAKE_INSTALL_NAME_TOOL"); |
146 | |
|
147 | 0 | Indent inputIndent = indent; |
148 | 0 | if (this->PolicyStatusCMP0207 != cmPolicies::WARN) { |
149 | 0 | indent = indent.Next(); |
150 | 0 | os << inputIndent << "block(SCOPE_FOR POLICIES)\n" |
151 | 0 | << indent << "cmake_policy(SET CMP0207 " |
152 | 0 | << (this->PolicyStatusCMP0207 == cmPolicies::NEW ? "NEW" : "OLD") |
153 | 0 | << ")\n"; |
154 | 0 | } |
155 | 0 | os << indent << "file(GET_RUNTIME_DEPENDENCIES\n" |
156 | 0 | << indent << " RESOLVED_DEPENDENCIES_VAR " << this->DepsVar << '\n'; |
157 | 0 | WriteFilesArgument(os, "EXECUTABLES"_s, |
158 | 0 | this->RuntimeDependencySet->GetExecutables(), config, |
159 | 0 | indent); |
160 | 0 | WriteFilesArgument(os, "LIBRARIES"_s, |
161 | 0 | this->RuntimeDependencySet->GetLibraries(), config, |
162 | 0 | indent); |
163 | 0 | WriteFilesArgument(os, "MODULES"_s, this->RuntimeDependencySet->GetModules(), |
164 | 0 | config, indent); |
165 | 0 | if (this->RuntimeDependencySet->GetBundleExecutable()) { |
166 | 0 | os << indent << " BUNDLE_EXECUTABLE \"" |
167 | 0 | << this->RuntimeDependencySet->GetBundleExecutable()->GetItemPath( |
168 | 0 | config) |
169 | 0 | << "\"\n"; |
170 | 0 | } |
171 | 0 | WriteGenexEvaluatorArgument(os, "DIRECTORIES"_s, this->Directories, config, |
172 | 0 | this->LocalGenerator, indent); |
173 | 0 | WriteGenexEvaluatorArgument(os, "PRE_INCLUDE_REGEXES"_s, |
174 | 0 | this->PreIncludeRegexes, config, |
175 | 0 | this->LocalGenerator, indent); |
176 | 0 | WriteGenexEvaluatorArgument(os, "PRE_EXCLUDE_REGEXES"_s, |
177 | 0 | this->PreExcludeRegexes, config, |
178 | 0 | this->LocalGenerator, indent); |
179 | 0 | WriteGenexEvaluatorArgument(os, "POST_INCLUDE_REGEXES"_s, |
180 | 0 | this->PostIncludeRegexes, config, |
181 | 0 | this->LocalGenerator, indent); |
182 | 0 | WriteGenexEvaluatorArgument(os, "POST_EXCLUDE_REGEXES"_s, |
183 | 0 | this->PostExcludeRegexes, config, |
184 | 0 | this->LocalGenerator, indent); |
185 | 0 | WriteGenexEvaluatorArgument(os, "POST_INCLUDE_FILES"_s, |
186 | 0 | this->PostIncludeFiles, config, |
187 | 0 | this->LocalGenerator, indent); |
188 | 0 | WriteGenexEvaluatorArgument(os, "POST_EXCLUDE_FILES"_s, |
189 | 0 | this->PostExcludeFiles, config, |
190 | 0 | this->LocalGenerator, indent); |
191 | |
|
192 | 0 | std::set<std::string> postExcludeFiles; |
193 | 0 | auto const addPostExclude = |
194 | 0 | [config, &postExcludeFiles, this]( |
195 | 0 | std::vector<std::unique_ptr<cmInstallRuntimeDependencySet::Item>> const& |
196 | 0 | tgts) { |
197 | 0 | for (auto const& item : tgts) { |
198 | 0 | item->AddPostExcludeFiles(config, postExcludeFiles, |
199 | 0 | this->RuntimeDependencySet); |
200 | 0 | } |
201 | 0 | }; |
202 | 0 | addPostExclude(this->RuntimeDependencySet->GetExecutables()); |
203 | 0 | addPostExclude(this->RuntimeDependencySet->GetLibraries()); |
204 | 0 | addPostExclude(this->RuntimeDependencySet->GetModules()); |
205 | 0 | bool first = true; |
206 | 0 | for (auto const& file : postExcludeFiles) { |
207 | 0 | if (first) { |
208 | 0 | os << indent << " POST_EXCLUDE_FILES_STRICT\n"; |
209 | 0 | first = false; |
210 | 0 | } |
211 | 0 | os << indent << " \"" << file << "\"\n"; |
212 | 0 | } |
213 | |
|
214 | 0 | if (!installNameTool.empty() && !this->NoInstallRPath) { |
215 | 0 | os << indent << " RPATH_PREFIX " << this->RPathPrefix << '\n'; |
216 | 0 | } |
217 | 0 | os << indent << " )\n"; |
218 | |
|
219 | 0 | if (this->PolicyStatusCMP0207 != cmPolicies::WARN) { |
220 | 0 | os << inputIndent << "endblock()\n"; |
221 | 0 | } |
222 | 0 | } |