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