/src/CMake/Source/cmInstallCommand.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 "cmInstallCommand.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <cassert> |
7 | | #include <cstddef> |
8 | | #include <iterator> |
9 | | #include <map> |
10 | | #include <set> |
11 | | #include <utility> |
12 | | |
13 | | #include <cm/memory> |
14 | | #include <cm/optional> |
15 | | #include <cm/string_view> |
16 | | #include <cmext/string_view> |
17 | | |
18 | | #include "cmsys/Glob.hxx" |
19 | | |
20 | | #include "cmArgumentParser.h" |
21 | | #include "cmArgumentParserTypes.h" |
22 | | #include "cmCMakePath.h" |
23 | | #include "cmDiagnostics.h" |
24 | | #include "cmExecutionStatus.h" |
25 | | #include "cmExperimental.h" |
26 | | #include "cmExportSet.h" |
27 | | #include "cmGeneratorExpression.h" |
28 | | #include "cmGlobalGenerator.h" |
29 | | #include "cmInstallAndroidMKExportGenerator.h" |
30 | | #include "cmInstallCMakeConfigExportGenerator.h" |
31 | | #include "cmInstallCommandArguments.h" |
32 | | #include "cmInstallCxxModuleBmiGenerator.h" |
33 | | #include "cmInstallDirectoryGenerator.h" |
34 | | #include "cmInstallDirs.h" |
35 | | #include "cmInstallFileSetGenerator.h" |
36 | | #include "cmInstallFilesGenerator.h" |
37 | | #include "cmInstallGenerator.h" |
38 | | #include "cmInstallGetRuntimeDependenciesGenerator.h" |
39 | | #include "cmInstallImportedRuntimeArtifactsGenerator.h" |
40 | | #include "cmInstallPackageInfoExportGenerator.h" |
41 | | #include "cmInstallRuntimeDependencySet.h" |
42 | | #include "cmInstallRuntimeDependencySetGenerator.h" |
43 | | #include "cmInstallSbomExportGenerator.h" |
44 | | #include "cmInstallScriptGenerator.h" |
45 | | #include "cmInstallTargetGenerator.h" |
46 | | #include "cmList.h" |
47 | | #include "cmMakefile.h" |
48 | | #include "cmMessageType.h" |
49 | | #include "cmPackageInfoArguments.h" |
50 | | #include "cmPolicies.h" |
51 | | #include "cmRange.h" |
52 | | #include "cmRuntimeDependencyArchive.h" |
53 | | #include "cmSbomArguments.h" |
54 | | #include "cmStateTypes.h" |
55 | | #include "cmStringAlgorithms.h" |
56 | | #include "cmSubcommandTable.h" |
57 | | #include "cmSystemTools.h" |
58 | | #include "cmTarget.h" |
59 | | #include "cmTargetExport.h" |
60 | | #include "cmValue.h" |
61 | | |
62 | | class cmListFileBacktrace; |
63 | | |
64 | | namespace { |
65 | | |
66 | | struct RuntimeDependenciesArgs |
67 | | { |
68 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> Directories; |
69 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PreIncludeRegexes; |
70 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PreExcludeRegexes; |
71 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeRegexes; |
72 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeRegexes; |
73 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PostIncludeFiles; |
74 | | ArgumentParser::MaybeEmpty<std::vector<std::string>> PostExcludeFiles; |
75 | | }; |
76 | | |
77 | | auto const RuntimeDependenciesArgHelper = |
78 | | cmArgumentParser<RuntimeDependenciesArgs>{} |
79 | | .Bind("DIRECTORIES"_s, &RuntimeDependenciesArgs::Directories) |
80 | | .Bind("PRE_INCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreIncludeRegexes) |
81 | | .Bind("PRE_EXCLUDE_REGEXES"_s, &RuntimeDependenciesArgs::PreExcludeRegexes) |
82 | | .Bind("POST_INCLUDE_REGEXES"_s, |
83 | | &RuntimeDependenciesArgs::PostIncludeRegexes) |
84 | | .Bind("POST_EXCLUDE_REGEXES"_s, |
85 | | &RuntimeDependenciesArgs::PostExcludeRegexes) |
86 | | .Bind("POST_INCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostIncludeFiles) |
87 | | .Bind("POST_EXCLUDE_FILES"_s, &RuntimeDependenciesArgs::PostExcludeFiles); |
88 | | |
89 | | class Helper |
90 | | { |
91 | | public: |
92 | | Helper(cmExecutionStatus& status) |
93 | 0 | : Status(status) |
94 | 0 | , Makefile(&status.GetMakefile()) |
95 | 0 | { |
96 | 0 | this->DefaultComponentName = this->Makefile->GetSafeDefinition( |
97 | 0 | "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"); |
98 | 0 | if (this->DefaultComponentName == "<PROJECT_NAME>") { |
99 | 0 | cmValue projectName = this->Makefile->GetDefinition("PROJECT_NAME"); |
100 | 0 | if (!projectName->empty()) { |
101 | 0 | this->DefaultComponentName = projectName; |
102 | 0 | } else { |
103 | 0 | this->DefaultComponentName = "Unspecified"; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | if (this->DefaultComponentName.empty()) { |
107 | 0 | this->DefaultComponentName = "Unspecified"; |
108 | 0 | } |
109 | 0 | } |
110 | | |
111 | 0 | void SetError(std::string const& err) { this->Status.SetError(err); } |
112 | | |
113 | | bool MakeFilesFullPath(char const* modeName, |
114 | | std::vector<std::string> const& relFiles, |
115 | | std::vector<std::string>& absFiles); |
116 | | bool MakeFilesFullPath(char const* modeName, std::string const& basePath, |
117 | | std::vector<std::string> const& relFiles, |
118 | | std::vector<std::string>& absFiles); |
119 | | |
120 | | std::string GetRuntimeDestination( |
121 | | cmInstallCommandArguments const* args) const; |
122 | | std::string GetArchiveDestination( |
123 | | cmInstallCommandArguments const* args) const; |
124 | | std::string GetLibraryDestination( |
125 | | cmInstallCommandArguments const* args) const; |
126 | | std::string GetCxxModulesBmiDestination( |
127 | | cmInstallCommandArguments const* args) const; |
128 | | std::string GetIncludeDestination( |
129 | | cmInstallCommandArguments const* args) const; |
130 | | std::string GetDestinationForType(cmInstallCommandArguments const* args, |
131 | | std::string const& type) const; |
132 | | |
133 | | cmExecutionStatus& Status; |
134 | | cmMakefile* Makefile; |
135 | | std::string DefaultComponentName; |
136 | | }; |
137 | | |
138 | | std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( |
139 | | cmTarget& target, cmInstallCommandArguments const& args, bool impLib, |
140 | | cmListFileBacktrace const& backtrace, std::string const& destination, |
141 | | bool forceOpt = false, bool namelink = false) |
142 | 0 | { |
143 | 0 | cmInstallGenerator::MessageLevel message = |
144 | 0 | cmInstallGenerator::SelectMessageLevel(target.GetMakefile()); |
145 | 0 | target.SetHaveInstallRule(true); |
146 | 0 | std::string const& component = |
147 | 0 | namelink ? args.GetNamelinkComponent() : args.GetComponent(); |
148 | 0 | auto g = cm::make_unique<cmInstallTargetGenerator>( |
149 | 0 | target.GetName(), destination, impLib, args.GetPermissions(), |
150 | 0 | args.GetConfigurations(), component, message, args.GetExcludeFromAll(), |
151 | 0 | args.GetOptional() || forceOpt, backtrace); |
152 | 0 | target.AddInstallGenerator(g.get()); |
153 | 0 | return g; |
154 | 0 | } |
155 | | |
156 | | std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( |
157 | | cmTarget& target, cmInstallCommandArguments const& args, bool impLib, |
158 | | cmListFileBacktrace const& backtrace, bool forceOpt = false, |
159 | | bool namelink = false) |
160 | 0 | { |
161 | 0 | return CreateInstallTargetGenerator(target, args, impLib, backtrace, |
162 | 0 | args.GetDestination(), forceOpt, |
163 | 0 | namelink); |
164 | 0 | } |
165 | | |
166 | | std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( |
167 | | cmMakefile* mf, std::vector<std::string> const& absFiles, |
168 | | cmInstallCommandArguments const& args, bool programs, |
169 | | std::string const& destination) |
170 | 0 | { |
171 | 0 | cmInstallGenerator::MessageLevel message = |
172 | 0 | cmInstallGenerator::SelectMessageLevel(mf); |
173 | 0 | return cm::make_unique<cmInstallFilesGenerator>( |
174 | 0 | absFiles, destination, programs, args.GetPermissions(), |
175 | 0 | args.GetConfigurations(), args.GetComponent(), message, |
176 | 0 | args.GetExcludeFromAll(), args.GetRename(), args.GetOptional(), |
177 | 0 | mf->GetBacktrace()); |
178 | 0 | } |
179 | | |
180 | | std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( |
181 | | cmMakefile* mf, std::vector<std::string> const& absFiles, |
182 | | cmInstallCommandArguments const& args, bool programs) |
183 | 0 | { |
184 | 0 | return CreateInstallFilesGenerator(mf, absFiles, args, programs, |
185 | 0 | args.GetDestination()); |
186 | 0 | } |
187 | | |
188 | | std::unique_ptr<cmInstallFileSetGenerator> CreateInstallFileSetGenerator( |
189 | | Helper& helper, cmTarget& target, |
190 | | cmInstallCommandFileSetArguments const& args) |
191 | 0 | { |
192 | 0 | cmInstallGenerator::MessageLevel message = |
193 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
194 | 0 | return cm::make_unique<cmInstallFileSetGenerator>( |
195 | 0 | target.GetName(), args.GetFileSet(), args.GetDestination(), |
196 | 0 | args.GetPermissions(), args.GetConfigurations(), args.GetComponent(), |
197 | 0 | message, args.GetExcludeFromAll(), args.GetOptional(), |
198 | 0 | helper.Makefile->GetBacktrace()); |
199 | 0 | } |
200 | | |
201 | | void AddInstallRuntimeDependenciesGenerator( |
202 | | Helper& helper, cmInstallRuntimeDependencySet* runtimeDependencySet, |
203 | | cmInstallCommandArguments const& runtimeArgs, |
204 | | cmInstallCommandArguments const& libraryArgs, |
205 | | cmInstallCommandArguments const& frameworkArgs, |
206 | | RuntimeDependenciesArgs runtimeDependenciesArgs, bool& installsRuntime, |
207 | | bool& installsLibrary, bool& installsFramework) |
208 | 0 | { |
209 | 0 | bool dllPlatform = |
210 | 0 | !helper.Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); |
211 | 0 | bool apple = |
212 | 0 | helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") == "Darwin"; |
213 | 0 | auto const& runtimeDependenciesArgsRef = |
214 | 0 | dllPlatform ? runtimeArgs : libraryArgs; |
215 | 0 | std::vector<std::string> configurations = |
216 | 0 | runtimeDependenciesArgsRef.GetConfigurations(); |
217 | 0 | if (apple) { |
218 | 0 | std::copy(frameworkArgs.GetConfigurations().begin(), |
219 | 0 | frameworkArgs.GetConfigurations().end(), |
220 | 0 | std::back_inserter(configurations)); |
221 | 0 | } |
222 | | |
223 | | // Create file(GET_RUNTIME_DEPENDENCIES) generator. |
224 | 0 | auto getRuntimeDependenciesGenerator = |
225 | 0 | cm::make_unique<cmInstallGetRuntimeDependenciesGenerator>( |
226 | 0 | runtimeDependencySet, std::move(runtimeDependenciesArgs.Directories), |
227 | 0 | std::move(runtimeDependenciesArgs.PreIncludeRegexes), |
228 | 0 | std::move(runtimeDependenciesArgs.PreExcludeRegexes), |
229 | 0 | std::move(runtimeDependenciesArgs.PostIncludeRegexes), |
230 | 0 | std::move(runtimeDependenciesArgs.PostExcludeRegexes), |
231 | 0 | std::move(runtimeDependenciesArgs.PostIncludeFiles), |
232 | 0 | std::move(runtimeDependenciesArgs.PostExcludeFiles), |
233 | 0 | runtimeDependenciesArgsRef.GetComponent(), |
234 | 0 | apple ? frameworkArgs.GetComponent() : "", true, "_CMAKE_DEPS", |
235 | 0 | "_CMAKE_RPATH", configurations, |
236 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
237 | 0 | runtimeDependenciesArgsRef.GetExcludeFromAll() && |
238 | 0 | (apple ? frameworkArgs.GetExcludeFromAll() : true), |
239 | 0 | helper.Makefile->GetBacktrace(), |
240 | 0 | helper.Makefile->GetPolicyStatus(cmPolicies::CMP0207)); |
241 | 0 | helper.Makefile->AddInstallGenerator( |
242 | 0 | std::move(getRuntimeDependenciesGenerator)); |
243 | | |
244 | | // Create the library dependencies generator. |
245 | 0 | auto libraryRuntimeDependenciesGenerator = |
246 | 0 | cm::make_unique<cmInstallRuntimeDependencySetGenerator>( |
247 | 0 | cmInstallRuntimeDependencySetGenerator::DependencyType::Library, |
248 | 0 | runtimeDependencySet, std::vector<std::string>{}, true, std::string{}, |
249 | 0 | true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP", |
250 | 0 | dllPlatform ? helper.GetRuntimeDestination(&runtimeArgs) |
251 | 0 | : helper.GetLibraryDestination(&libraryArgs), |
252 | 0 | runtimeDependenciesArgsRef.GetConfigurations(), |
253 | 0 | runtimeDependenciesArgsRef.GetComponent(), |
254 | 0 | runtimeDependenciesArgsRef.GetPermissions(), |
255 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
256 | 0 | runtimeDependenciesArgsRef.GetExcludeFromAll(), |
257 | 0 | helper.Makefile->GetBacktrace()); |
258 | 0 | helper.Makefile->AddInstallGenerator( |
259 | 0 | std::move(libraryRuntimeDependenciesGenerator)); |
260 | 0 | if (dllPlatform) { |
261 | 0 | installsRuntime = true; |
262 | 0 | } else { |
263 | 0 | installsLibrary = true; |
264 | 0 | } |
265 | |
|
266 | 0 | if (apple) { |
267 | | // Create the framework dependencies generator. |
268 | 0 | auto frameworkRuntimeDependenciesGenerator = |
269 | 0 | cm::make_unique<cmInstallRuntimeDependencySetGenerator>( |
270 | 0 | cmInstallRuntimeDependencySetGenerator::DependencyType::Framework, |
271 | 0 | runtimeDependencySet, std::vector<std::string>{}, true, std::string{}, |
272 | 0 | true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP", |
273 | 0 | frameworkArgs.GetDestination(), frameworkArgs.GetConfigurations(), |
274 | 0 | frameworkArgs.GetComponent(), frameworkArgs.GetPermissions(), |
275 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
276 | 0 | frameworkArgs.GetExcludeFromAll(), helper.Makefile->GetBacktrace()); |
277 | 0 | helper.Makefile->AddInstallGenerator( |
278 | 0 | std::move(frameworkRuntimeDependenciesGenerator)); |
279 | 0 | installsFramework = true; |
280 | 0 | } |
281 | 0 | } |
282 | | |
283 | | std::set<std::string> const allowedTypes{ |
284 | | "BIN", "SBIN", "LIB", "INCLUDE", "SYSCONF", |
285 | | "SHAREDSTATE", "LOCALSTATE", "RUNSTATE", "DATA", "INFO", |
286 | | "LOCALE", "MAN", "DOC", "LIBEXEC", |
287 | | }; |
288 | | |
289 | | template <typename T> |
290 | | bool AddBundleExecutable(Helper& helper, |
291 | | cmInstallRuntimeDependencySet* runtimeDependencySet, |
292 | | T&& bundleExecutable) |
293 | 0 | { |
294 | 0 | if (!runtimeDependencySet->AddBundleExecutable(bundleExecutable)) { |
295 | 0 | helper.SetError( |
296 | 0 | "A runtime dependency set may only have one bundle executable."); |
297 | 0 | return false; |
298 | 0 | } |
299 | 0 | return true; |
300 | 0 | } Unexecuted instantiation: cmInstallCommand.cxx:bool (anonymous namespace)::AddBundleExecutable<cmInstallTargetGenerator*>((anonymous namespace)::Helper&, cmInstallRuntimeDependencySet*, cmInstallTargetGenerator*&&) Unexecuted instantiation: cmInstallCommand.cxx:bool (anonymous namespace)::AddBundleExecutable<cmInstallImportedRuntimeArtifactsGenerator*>((anonymous namespace)::Helper&, cmInstallRuntimeDependencySet*, cmInstallImportedRuntimeArtifactsGenerator*&&) |
301 | | |
302 | | bool HandleScriptMode(std::vector<std::string> const& args, |
303 | | cmExecutionStatus& status) |
304 | 0 | { |
305 | 0 | Helper helper(status); |
306 | |
|
307 | 0 | std::string component = helper.DefaultComponentName; |
308 | 0 | int componentCount = 0; |
309 | 0 | bool doing_script = false; |
310 | 0 | bool doing_code = false; |
311 | 0 | bool exclude_from_all = false; |
312 | 0 | bool all_components = false; |
313 | | |
314 | | // Scan the args once for COMPONENT. Only allow one. |
315 | | // |
316 | 0 | for (size_t i = 0; i < args.size(); ++i) { |
317 | 0 | if (args[i] == "COMPONENT" && i + 1 < args.size()) { |
318 | 0 | ++componentCount; |
319 | 0 | ++i; |
320 | 0 | component = args[i]; |
321 | 0 | } |
322 | 0 | if (args[i] == "EXCLUDE_FROM_ALL") { |
323 | 0 | exclude_from_all = true; |
324 | 0 | } else if (args[i] == "ALL_COMPONENTS") { |
325 | 0 | all_components = true; |
326 | 0 | } |
327 | 0 | } |
328 | |
|
329 | 0 | if (componentCount > 1) { |
330 | 0 | status.SetError("given more than one COMPONENT for the SCRIPT or CODE " |
331 | 0 | "signature of the INSTALL command. " |
332 | 0 | "Use multiple INSTALL commands with one COMPONENT each."); |
333 | 0 | return false; |
334 | 0 | } |
335 | | |
336 | 0 | if (all_components && componentCount == 1) { |
337 | 0 | status.SetError("ALL_COMPONENTS and COMPONENT are mutually exclusive"); |
338 | 0 | return false; |
339 | 0 | } |
340 | | |
341 | | // Scan the args again, this time adding install generators each time we |
342 | | // encounter a SCRIPT or CODE arg: |
343 | | // |
344 | 0 | for (std::string const& arg : args) { |
345 | 0 | if (arg == "SCRIPT") { |
346 | 0 | doing_script = true; |
347 | 0 | doing_code = false; |
348 | 0 | } else if (arg == "CODE") { |
349 | 0 | doing_script = false; |
350 | 0 | doing_code = true; |
351 | 0 | } else if (arg == "COMPONENT") { |
352 | 0 | doing_script = false; |
353 | 0 | doing_code = false; |
354 | 0 | } else if (doing_script) { |
355 | 0 | doing_script = false; |
356 | 0 | std::string script = arg; |
357 | 0 | if (!cmHasLiteralPrefix(script, "$<INSTALL_PREFIX>")) { |
358 | 0 | if (!cmSystemTools::FileIsFullPath(script)) { |
359 | 0 | script = |
360 | 0 | cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg); |
361 | 0 | } |
362 | 0 | if (cmSystemTools::FileIsDirectory(script)) { |
363 | 0 | status.SetError("given a directory as value of SCRIPT argument."); |
364 | 0 | return false; |
365 | 0 | } |
366 | 0 | } |
367 | 0 | helper.Makefile->AddInstallGenerator( |
368 | 0 | cm::make_unique<cmInstallScriptGenerator>( |
369 | 0 | script, false, component, exclude_from_all, all_components, |
370 | 0 | helper.Makefile->GetBacktrace())); |
371 | 0 | } else if (doing_code) { |
372 | 0 | doing_code = false; |
373 | 0 | std::string const& code = arg; |
374 | 0 | helper.Makefile->AddInstallGenerator( |
375 | 0 | cm::make_unique<cmInstallScriptGenerator>( |
376 | 0 | code, true, component, exclude_from_all, all_components, |
377 | 0 | helper.Makefile->GetBacktrace())); |
378 | 0 | } |
379 | 0 | } |
380 | | |
381 | 0 | if (doing_script) { |
382 | 0 | status.SetError("given no value for SCRIPT argument."); |
383 | 0 | return false; |
384 | 0 | } |
385 | 0 | if (doing_code) { |
386 | 0 | status.SetError("given no value for CODE argument."); |
387 | 0 | return false; |
388 | 0 | } |
389 | | |
390 | | // Tell the global generator about any installation component names |
391 | | // specified. |
392 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component); |
393 | |
|
394 | 0 | return true; |
395 | 0 | } |
396 | | |
397 | | bool HandleTargetsMode(std::vector<std::string> const& args, |
398 | | cmExecutionStatus& status) |
399 | 0 | { |
400 | 0 | Helper helper(status); |
401 | | |
402 | | // This is the TARGETS mode. |
403 | 0 | std::vector<cmTarget*> targets; |
404 | |
|
405 | 0 | struct ArgVectors |
406 | 0 | { |
407 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Archive; |
408 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Library; |
409 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime; |
410 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Object; |
411 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework; |
412 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle; |
413 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Includes; |
414 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> PrivateHeader; |
415 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> PublicHeader; |
416 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Resource; |
417 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> CxxModulesBmi; |
418 | 0 | std::vector<std::vector<std::string>> FileSets; |
419 | 0 | }; |
420 | |
|
421 | 0 | static auto const argHelper = |
422 | 0 | cmArgumentParser<ArgVectors>{} |
423 | 0 | .Bind("ARCHIVE"_s, &ArgVectors::Archive) |
424 | 0 | .Bind("LIBRARY"_s, &ArgVectors::Library) |
425 | 0 | .Bind("RUNTIME"_s, &ArgVectors::Runtime) |
426 | 0 | .Bind("OBJECTS"_s, &ArgVectors::Object) |
427 | 0 | .Bind("FRAMEWORK"_s, &ArgVectors::Framework) |
428 | 0 | .Bind("BUNDLE"_s, &ArgVectors::Bundle) |
429 | 0 | .Bind("INCLUDES"_s, &ArgVectors::Includes) |
430 | 0 | .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader) |
431 | 0 | .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader) |
432 | 0 | .Bind("RESOURCE"_s, &ArgVectors::Resource) |
433 | 0 | .Bind("FILE_SET"_s, &ArgVectors::FileSets) |
434 | 0 | .Bind("CXX_MODULES_BMI"_s, &ArgVectors::CxxModulesBmi); |
435 | |
|
436 | 0 | std::vector<std::string> genericArgVector; |
437 | 0 | ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); |
438 | | |
439 | | // now parse the generic args (i.e. the ones not specialized on LIBRARY/ |
440 | | // ARCHIVE, RUNTIME etc. (see above) |
441 | | // These generic args also contain the targets and the export stuff |
442 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList; |
443 | 0 | std::string exports; |
444 | 0 | cm::optional<ArgumentParser::MaybeEmpty<std::vector<std::string>>> |
445 | 0 | runtimeDependenciesArgVector; |
446 | 0 | std::string runtimeDependencySetArg; |
447 | 0 | std::vector<std::string> unknownArgs; |
448 | 0 | cmInstallCommandArguments genericArgs(helper.DefaultComponentName, |
449 | 0 | *helper.Makefile); |
450 | 0 | genericArgs.Bind("TARGETS"_s, targetList); |
451 | 0 | genericArgs.Bind("EXPORT"_s, exports); |
452 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCIES"_s, runtimeDependenciesArgVector); |
453 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg); |
454 | 0 | genericArgs.Parse(genericArgVector, &unknownArgs); |
455 | 0 | bool success = genericArgs.Finalize(); |
456 | |
|
457 | 0 | RuntimeDependenciesArgs runtimeDependenciesArgs = |
458 | 0 | runtimeDependenciesArgVector |
459 | 0 | ? RuntimeDependenciesArgHelper.Parse(*runtimeDependenciesArgVector, |
460 | 0 | &unknownArgs) |
461 | 0 | : RuntimeDependenciesArgs(); |
462 | |
|
463 | 0 | cmInstallCommandArguments archiveArgs(helper.DefaultComponentName, |
464 | 0 | *helper.Makefile); |
465 | 0 | cmInstallCommandArguments libraryArgs(helper.DefaultComponentName, |
466 | 0 | *helper.Makefile); |
467 | 0 | cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName, |
468 | 0 | *helper.Makefile); |
469 | 0 | cmInstallCommandArguments objectArgs(helper.DefaultComponentName, |
470 | 0 | *helper.Makefile); |
471 | 0 | cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName, |
472 | 0 | *helper.Makefile); |
473 | 0 | cmInstallCommandArguments bundleArgs(helper.DefaultComponentName, |
474 | 0 | *helper.Makefile); |
475 | 0 | cmInstallCommandArguments privateHeaderArgs(helper.DefaultComponentName, |
476 | 0 | *helper.Makefile); |
477 | 0 | cmInstallCommandArguments publicHeaderArgs(helper.DefaultComponentName, |
478 | 0 | *helper.Makefile); |
479 | 0 | cmInstallCommandArguments resourceArgs(helper.DefaultComponentName, |
480 | 0 | *helper.Makefile); |
481 | 0 | cmInstallCommandIncludesArgument includesArgs; |
482 | 0 | std::vector<cmInstallCommandFileSetArguments> fileSetArgs( |
483 | 0 | argVectors.FileSets.size(), |
484 | 0 | { cmInstallCommandFileSetArguments(helper.DefaultComponentName, |
485 | 0 | *helper.Makefile) }); |
486 | 0 | cmInstallCommandArguments cxxModuleBmiArgs(helper.DefaultComponentName, |
487 | 0 | *helper.Makefile); |
488 | | |
489 | | // now parse the args for specific parts of the target (e.g. LIBRARY, |
490 | | // RUNTIME, ARCHIVE etc. |
491 | 0 | archiveArgs.Parse(argVectors.Archive, &unknownArgs); |
492 | 0 | libraryArgs.Parse(argVectors.Library, &unknownArgs); |
493 | 0 | runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); |
494 | 0 | objectArgs.Parse(argVectors.Object, &unknownArgs); |
495 | 0 | frameworkArgs.Parse(argVectors.Framework, &unknownArgs); |
496 | 0 | bundleArgs.Parse(argVectors.Bundle, &unknownArgs); |
497 | 0 | privateHeaderArgs.Parse(argVectors.PrivateHeader, &unknownArgs); |
498 | 0 | publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs); |
499 | 0 | resourceArgs.Parse(argVectors.Resource, &unknownArgs); |
500 | 0 | includesArgs.Parse(&argVectors.Includes, &unknownArgs); |
501 | 0 | cxxModuleBmiArgs.Parse(argVectors.CxxModulesBmi, &unknownArgs); |
502 | 0 | for (std::size_t i = 0; i < argVectors.FileSets.size(); i++) { |
503 | | // We have to create a separate object for the parsing because |
504 | | // cmArgumentParser<void>::Bind() binds to a specific address, but the |
505 | | // objects in the vector can move around. So we parse in an object with a |
506 | | // fixed address and then copy the data into the vector. |
507 | 0 | cmInstallCommandFileSetArguments fileSetArg(helper.DefaultComponentName, |
508 | 0 | *helper.Makefile); |
509 | 0 | fileSetArg.Parse(argVectors.FileSets[i], &unknownArgs); |
510 | 0 | fileSetArgs[i] = std::move(fileSetArg); |
511 | 0 | } |
512 | |
|
513 | 0 | if (!unknownArgs.empty()) { |
514 | | // Unknown argument. |
515 | 0 | status.SetError( |
516 | 0 | cmStrCat("TARGETS given unknown argument \"", unknownArgs[0], "\".")); |
517 | 0 | return false; |
518 | 0 | } |
519 | | |
520 | | // apply generic args |
521 | 0 | archiveArgs.SetGenericArguments(&genericArgs); |
522 | 0 | libraryArgs.SetGenericArguments(&genericArgs); |
523 | 0 | runtimeArgs.SetGenericArguments(&genericArgs); |
524 | 0 | objectArgs.SetGenericArguments(&genericArgs); |
525 | 0 | frameworkArgs.SetGenericArguments(&genericArgs); |
526 | 0 | bundleArgs.SetGenericArguments(&genericArgs); |
527 | 0 | privateHeaderArgs.SetGenericArguments(&genericArgs); |
528 | 0 | publicHeaderArgs.SetGenericArguments(&genericArgs); |
529 | 0 | resourceArgs.SetGenericArguments(&genericArgs); |
530 | 0 | for (auto& fileSetArg : fileSetArgs) { |
531 | 0 | fileSetArg.SetGenericArguments(&genericArgs); |
532 | 0 | } |
533 | 0 | cxxModuleBmiArgs.SetGenericArguments(&genericArgs); |
534 | |
|
535 | 0 | success = success && archiveArgs.Finalize(); |
536 | 0 | success = success && libraryArgs.Finalize(); |
537 | 0 | success = success && runtimeArgs.Finalize(); |
538 | 0 | success = success && objectArgs.Finalize(); |
539 | 0 | success = success && frameworkArgs.Finalize(); |
540 | 0 | success = success && bundleArgs.Finalize(); |
541 | 0 | success = success && privateHeaderArgs.Finalize(); |
542 | 0 | success = success && publicHeaderArgs.Finalize(); |
543 | 0 | success = success && resourceArgs.Finalize(); |
544 | 0 | success = success && cxxModuleBmiArgs.Finalize(); |
545 | 0 | for (auto& fileSetArg : fileSetArgs) { |
546 | 0 | success = success && fileSetArg.Finalize(); |
547 | 0 | } |
548 | |
|
549 | 0 | if (!success) { |
550 | 0 | return false; |
551 | 0 | } |
552 | | |
553 | | // Enforce argument rules too complex to specify for the |
554 | | // general-purpose parser. |
555 | 0 | if (runtimeArgs.GetNamelinkOnly() || objectArgs.GetNamelinkOnly() || |
556 | 0 | frameworkArgs.GetNamelinkOnly() || bundleArgs.GetNamelinkOnly() || |
557 | 0 | privateHeaderArgs.GetNamelinkOnly() || |
558 | 0 | publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly() || |
559 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
560 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
561 | 0 | -> bool { return fileSetArg.GetNamelinkOnly(); }) || |
562 | 0 | cxxModuleBmiArgs.GetNamelinkOnly()) { |
563 | 0 | status.SetError( |
564 | 0 | "TARGETS given NAMELINK_ONLY option not in LIBRARY or ARCHIVE group. " |
565 | 0 | "The NAMELINK_ONLY option may be specified only following LIBRARY or " |
566 | 0 | "ARCHIVE."); |
567 | 0 | return false; |
568 | 0 | } |
569 | 0 | if (runtimeArgs.GetNamelinkSkip() || objectArgs.GetNamelinkSkip() || |
570 | 0 | frameworkArgs.GetNamelinkSkip() || bundleArgs.GetNamelinkSkip() || |
571 | 0 | privateHeaderArgs.GetNamelinkSkip() || |
572 | 0 | publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip() || |
573 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
574 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
575 | 0 | -> bool { return fileSetArg.GetNamelinkSkip(); }) || |
576 | 0 | cxxModuleBmiArgs.GetNamelinkSkip()) { |
577 | 0 | status.SetError( |
578 | 0 | "TARGETS given NAMELINK_SKIP option not in LIBRARY or ARCHIVE group. " |
579 | 0 | "The NAMELINK_SKIP option may be specified only following LIBRARY or " |
580 | 0 | "ARCHIVE."); |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | if (runtimeArgs.HasNamelinkComponent() || |
584 | 0 | objectArgs.HasNamelinkComponent() || |
585 | 0 | frameworkArgs.HasNamelinkComponent() || |
586 | 0 | bundleArgs.HasNamelinkComponent() || |
587 | 0 | privateHeaderArgs.HasNamelinkComponent() || |
588 | 0 | publicHeaderArgs.HasNamelinkComponent() || |
589 | 0 | resourceArgs.HasNamelinkComponent() || |
590 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
591 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
592 | 0 | -> bool { return fileSetArg.HasNamelinkComponent(); }) || |
593 | 0 | cxxModuleBmiArgs.HasNamelinkComponent()) { |
594 | 0 | status.SetError( |
595 | 0 | "TARGETS given NAMELINK_COMPONENT option not in LIBRARY or ARCHIVE " |
596 | 0 | "group. The NAMELINK_COMPONENT option may be specified only following " |
597 | 0 | "LIBRARY or ARCHIVE."); |
598 | 0 | return false; |
599 | 0 | } |
600 | 0 | if (libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip()) { |
601 | 0 | status.SetError("TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. " |
602 | 0 | "At most one of these two options may be specified."); |
603 | 0 | return false; |
604 | 0 | } |
605 | 0 | if (!genericArgs.GetType().empty() || !archiveArgs.GetType().empty() || |
606 | 0 | !libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() || |
607 | 0 | !objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() || |
608 | 0 | !bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() || |
609 | 0 | !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty() || |
610 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
611 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
612 | 0 | -> bool { return !fileSetArg.GetType().empty(); }) || |
613 | 0 | !cxxModuleBmiArgs.GetType().empty()) { |
614 | 0 | status.SetError( |
615 | 0 | "TARGETS given TYPE option. The TYPE option may only be specified in " |
616 | 0 | " install(FILES) and install(DIRECTORIES)."); |
617 | 0 | return false; |
618 | 0 | } |
619 | 0 | if (std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
620 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
621 | 0 | -> bool { return fileSetArg.GetFileSet().empty(); })) { |
622 | 0 | status.SetError("TARGETS given FILE_SET option without file set name."); |
623 | 0 | return false; |
624 | 0 | } |
625 | | |
626 | 0 | cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr; |
627 | 0 | if (runtimeDependenciesArgVector) { |
628 | 0 | if (!runtimeDependencySetArg.empty()) { |
629 | 0 | status.SetError("TARGETS cannot have both RUNTIME_DEPENDENCIES and " |
630 | 0 | "RUNTIME_DEPENDENCY_SET."); |
631 | 0 | return false; |
632 | 0 | } |
633 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
634 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
635 | 0 | system)) { |
636 | 0 | status.SetError( |
637 | 0 | cmStrCat("TARGETS RUNTIME_DEPENDENCIES is not supported on system \"", |
638 | 0 | system, '"')); |
639 | 0 | return false; |
640 | 0 | } |
641 | 0 | if (helper.Makefile->IsOn("CMAKE_CROSSCOMPILING")) { |
642 | 0 | status.SetError("TARGETS RUNTIME_DEPENDENCIES is not supported " |
643 | 0 | "when cross-compiling."); |
644 | 0 | return false; |
645 | 0 | } |
646 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") == |
647 | 0 | "Darwin" && |
648 | 0 | frameworkArgs.GetDestination().empty()) { |
649 | 0 | status.SetError( |
650 | 0 | "TARGETS RUNTIME_DEPENDENCIES given no FRAMEWORK DESTINATION"); |
651 | 0 | return false; |
652 | 0 | } |
653 | 0 | runtimeDependencySet = helper.Makefile->GetGlobalGenerator() |
654 | 0 | ->CreateAnonymousRuntimeDependencySet(); |
655 | 0 | } else if (!runtimeDependencySetArg.empty()) { |
656 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
657 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
658 | 0 | system)) { |
659 | 0 | status.SetError(cmStrCat( |
660 | 0 | "TARGETS RUNTIME_DEPENDENCY_SET is not supported on system \"", system, |
661 | 0 | '"')); |
662 | 0 | return false; |
663 | 0 | } |
664 | 0 | runtimeDependencySet = |
665 | 0 | helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet( |
666 | 0 | runtimeDependencySetArg); |
667 | 0 | } |
668 | | |
669 | | // Select the mode for installing symlinks to versioned shared libraries. |
670 | 0 | cmInstallTargetGenerator::NamelinkModeType namelinkMode = |
671 | 0 | cmInstallTargetGenerator::NamelinkModeNone; |
672 | 0 | if (libraryArgs.GetNamelinkOnly()) { |
673 | 0 | namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly; |
674 | 0 | } else if (libraryArgs.GetNamelinkSkip()) { |
675 | 0 | namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip; |
676 | 0 | } |
677 | | // Select the mode for installing symlinks to versioned imported libraries. |
678 | 0 | cmInstallTargetGenerator::NamelinkModeType importlinkMode = |
679 | 0 | cmInstallTargetGenerator::NamelinkModeNone; |
680 | 0 | if (archiveArgs.GetNamelinkOnly()) { |
681 | 0 | importlinkMode = cmInstallTargetGenerator::NamelinkModeOnly; |
682 | 0 | } else if (archiveArgs.GetNamelinkSkip()) { |
683 | 0 | importlinkMode = cmInstallTargetGenerator::NamelinkModeSkip; |
684 | 0 | } |
685 | | |
686 | | // Check if there is something to do. |
687 | 0 | if (targetList.empty()) { |
688 | 0 | return true; |
689 | 0 | } |
690 | | |
691 | 0 | for (std::string const& tgt : targetList) { |
692 | |
|
693 | 0 | if (helper.Makefile->IsAlias(tgt)) { |
694 | 0 | status.SetError( |
695 | 0 | cmStrCat("TARGETS given target \"", tgt, "\" which is an alias.")); |
696 | 0 | return false; |
697 | 0 | } |
698 | | // Lookup this target in the current directory. |
699 | 0 | cmTarget* target = helper.Makefile->FindLocalNonAliasTarget(tgt); |
700 | 0 | if (!target) { |
701 | | // If no local target has been found, find it in the global scope. |
702 | 0 | cmTarget* const global_target = |
703 | 0 | helper.Makefile->GetGlobalGenerator()->FindTarget( |
704 | 0 | tgt, { cmStateEnums::TargetDomain::NATIVE }); |
705 | 0 | if (global_target && !global_target->IsImported()) { |
706 | 0 | target = global_target; |
707 | 0 | } |
708 | 0 | } |
709 | 0 | if (target) { |
710 | | // Found the target. Check its type. |
711 | 0 | if (target->GetType() != cmStateEnums::EXECUTABLE && |
712 | 0 | target->GetType() != cmStateEnums::STATIC_LIBRARY && |
713 | 0 | target->GetType() != cmStateEnums::SHARED_LIBRARY && |
714 | 0 | target->GetType() != cmStateEnums::MODULE_LIBRARY && |
715 | 0 | target->GetType() != cmStateEnums::OBJECT_LIBRARY && |
716 | 0 | target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { |
717 | 0 | status.SetError( |
718 | 0 | cmStrCat("TARGETS given target \"", tgt, |
719 | 0 | "\" which is not an executable, library, or module.")); |
720 | 0 | return false; |
721 | 0 | } |
722 | | // Store the target in the list to be installed. |
723 | 0 | targets.push_back(target); |
724 | 0 | } else { |
725 | | // Did not find the target. |
726 | 0 | status.SetError( |
727 | 0 | cmStrCat("TARGETS given target \"", tgt, "\" which does not exist.")); |
728 | 0 | return false; |
729 | 0 | } |
730 | 0 | } |
731 | | |
732 | | // Keep track of whether we will be performing an installation of |
733 | | // any files of the given type. |
734 | 0 | bool installsArchive = false; |
735 | 0 | bool installsLibrary = false; |
736 | 0 | bool installsNamelink = false; |
737 | 0 | bool installsImportlink = false; |
738 | 0 | bool installsRuntime = false; |
739 | 0 | bool installsObject = false; |
740 | 0 | bool installsFramework = false; |
741 | 0 | bool installsBundle = false; |
742 | 0 | bool installsPrivateHeader = false; |
743 | 0 | bool installsPublicHeader = false; |
744 | 0 | bool installsResource = false; |
745 | 0 | std::vector<bool> installsFileSet(fileSetArgs.size(), false); |
746 | 0 | bool installsCxxModuleBmi = false; |
747 | | |
748 | | // Generate install script code to install the given targets. |
749 | 0 | for (cmTarget* ti : targets) { |
750 | | // Handle each target type. |
751 | 0 | cmTarget& target = *ti; |
752 | 0 | std::unique_ptr<cmInstallTargetGenerator> archiveGenerator; |
753 | 0 | std::unique_ptr<cmInstallTargetGenerator> libraryGenerator; |
754 | 0 | std::unique_ptr<cmInstallTargetGenerator> namelinkGenerator; |
755 | 0 | std::unique_ptr<cmInstallTargetGenerator> importlinkGenerator; |
756 | 0 | std::unique_ptr<cmInstallTargetGenerator> runtimeGenerator; |
757 | 0 | std::unique_ptr<cmInstallTargetGenerator> objectGenerator; |
758 | 0 | std::unique_ptr<cmInstallTargetGenerator> frameworkGenerator; |
759 | 0 | std::unique_ptr<cmInstallTargetGenerator> bundleGenerator; |
760 | 0 | std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator; |
761 | 0 | std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator; |
762 | 0 | std::unique_ptr<cmInstallFilesGenerator> resourceGenerator; |
763 | 0 | std::vector<std::unique_ptr<cmInstallFileSetGenerator>> fileSetGenerators; |
764 | 0 | std::unique_ptr<cmInstallCxxModuleBmiGenerator> cxxModuleBmiGenerator; |
765 | | |
766 | | // Avoid selecting default destinations for PUBLIC_HEADER and |
767 | | // PRIVATE_HEADER if any artifacts are specified. |
768 | 0 | bool artifactsSpecified = false; |
769 | | |
770 | | // Track whether this is a namelink-only rule. |
771 | 0 | bool namelinkOnly = false; |
772 | |
|
773 | 0 | auto addTargetExport = [&]() -> bool { |
774 | | // Add this install rule to an export if one was specified. |
775 | 0 | if (!exports.empty()) { |
776 | 0 | auto interfaceFileSets = target.GetAllInterfaceFileSets(); |
777 | 0 | if (std::any_of( |
778 | 0 | interfaceFileSets.begin(), interfaceFileSets.end(), |
779 | 0 | [=](std::string const& name) -> bool { |
780 | 0 | return !std::any_of( |
781 | 0 | fileSetArgs.begin(), fileSetArgs.end(), |
782 | 0 | [=](cmInstallCommandFileSetArguments const& fileSetArg) |
783 | 0 | -> bool { return fileSetArg.GetFileSet() == name; }); |
784 | 0 | })) { |
785 | 0 | status.SetError(cmStrCat("TARGETS target ", target.GetName(), |
786 | 0 | " is exported but not all of its interface " |
787 | 0 | "file sets are installed")); |
788 | 0 | return false; |
789 | 0 | } |
790 | | |
791 | 0 | auto te = cm::make_unique<cmTargetExport>(); |
792 | 0 | te->TargetName = target.GetName(); |
793 | 0 | te->ArchiveGenerator = archiveGenerator.get(); |
794 | 0 | te->BundleGenerator = bundleGenerator.get(); |
795 | 0 | te->FrameworkGenerator = frameworkGenerator.get(); |
796 | 0 | te->HeaderGenerator = publicHeaderGenerator.get(); |
797 | 0 | te->LibraryGenerator = libraryGenerator.get(); |
798 | 0 | te->RuntimeGenerator = runtimeGenerator.get(); |
799 | 0 | te->ObjectsGenerator = objectGenerator.get(); |
800 | 0 | for (auto const& gen : fileSetGenerators) { |
801 | 0 | te->FileSetGenerators[gen->GetFileSetName()] = gen.get(); |
802 | 0 | } |
803 | 0 | te->CxxModuleBmiGenerator = cxxModuleBmiGenerator.get(); |
804 | 0 | target.AddInstallIncludeDirectories( |
805 | 0 | *te, cmMakeRange(includesArgs.GetIncludeDirs())); |
806 | 0 | te->NamelinkOnly = namelinkOnly; |
807 | 0 | helper.Makefile->GetGlobalGenerator() |
808 | 0 | ->GetExportSets()[exports] |
809 | 0 | .AddTargetExport(std::move(te)); |
810 | 0 | } |
811 | 0 | return true; |
812 | 0 | }; |
813 | |
|
814 | 0 | switch (target.GetType()) { |
815 | 0 | case cmStateEnums::SHARED_LIBRARY: { |
816 | | // Shared libraries are handled differently on DLL and non-DLL |
817 | | // platforms. All windows platforms are DLL platforms including |
818 | | // cygwin. Currently no other platform is a DLL platform. |
819 | 0 | if (target.IsDLLPlatform()) { |
820 | | // When in namelink only mode skip all libraries on Windows. |
821 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
822 | 0 | namelinkOnly = true; |
823 | 0 | if (!addTargetExport()) { |
824 | 0 | return false; |
825 | 0 | } |
826 | 0 | continue; |
827 | 0 | } |
828 | | |
829 | | // This is a DLL platform. |
830 | 0 | if (!archiveArgs.GetDestination().empty()) { |
831 | | // The import library uses the ARCHIVE properties. |
832 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
833 | 0 | target, archiveArgs, true, helper.Makefile->GetBacktrace()); |
834 | 0 | artifactsSpecified = true; |
835 | 0 | } |
836 | 0 | if (!runtimeArgs.GetDestination().empty()) { |
837 | | // The DLL uses the RUNTIME properties. |
838 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
839 | 0 | target, runtimeArgs, false, helper.Makefile->GetBacktrace()); |
840 | 0 | artifactsSpecified = true; |
841 | 0 | } |
842 | 0 | if (!archiveGenerator && !runtimeGenerator) { |
843 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
844 | 0 | target, archiveArgs, true, helper.Makefile->GetBacktrace(), |
845 | 0 | helper.GetArchiveDestination(nullptr)); |
846 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
847 | 0 | target, runtimeArgs, false, helper.Makefile->GetBacktrace(), |
848 | 0 | helper.GetRuntimeDestination(nullptr)); |
849 | 0 | } |
850 | 0 | if (runtimeDependencySet && runtimeGenerator) { |
851 | 0 | runtimeDependencySet->AddLibrary(runtimeGenerator.get()); |
852 | 0 | } |
853 | 0 | } else { |
854 | | // This is a non-DLL platform. |
855 | | // If it is marked with FRAMEWORK property use the FRAMEWORK set of |
856 | | // INSTALL properties. Otherwise, use the LIBRARY properties. |
857 | 0 | if (target.IsFrameworkOnApple()) { |
858 | | // When in namelink only mode skip frameworks. |
859 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
860 | 0 | namelinkOnly = true; |
861 | 0 | if (!addTargetExport()) { |
862 | 0 | return false; |
863 | 0 | } |
864 | 0 | continue; |
865 | 0 | } |
866 | | |
867 | | // Use the FRAMEWORK properties. |
868 | 0 | if (!frameworkArgs.GetDestination().empty()) { |
869 | 0 | frameworkGenerator = CreateInstallTargetGenerator( |
870 | 0 | target, frameworkArgs, false, helper.Makefile->GetBacktrace()); |
871 | 0 | } else { |
872 | 0 | status.SetError( |
873 | 0 | cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared " |
874 | 0 | "library FRAMEWORK target \"", |
875 | 0 | target.GetName(), "\".")); |
876 | 0 | return false; |
877 | 0 | } |
878 | 0 | } else { |
879 | | // The shared library uses the LIBRARY properties. |
880 | 0 | if (!libraryArgs.GetDestination().empty()) { |
881 | 0 | artifactsSpecified = true; |
882 | 0 | } |
883 | 0 | if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) { |
884 | 0 | libraryGenerator = CreateInstallTargetGenerator( |
885 | 0 | target, libraryArgs, false, helper.Makefile->GetBacktrace(), |
886 | 0 | helper.GetLibraryDestination(&libraryArgs)); |
887 | 0 | libraryGenerator->SetNamelinkMode( |
888 | 0 | cmInstallTargetGenerator::NamelinkModeSkip); |
889 | 0 | } |
890 | 0 | if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) { |
891 | 0 | namelinkGenerator = CreateInstallTargetGenerator( |
892 | 0 | target, libraryArgs, false, helper.Makefile->GetBacktrace(), |
893 | 0 | helper.GetLibraryDestination(&libraryArgs), false, true); |
894 | 0 | namelinkGenerator->SetNamelinkMode( |
895 | 0 | cmInstallTargetGenerator::NamelinkModeOnly); |
896 | 0 | } |
897 | 0 | namelinkOnly = |
898 | 0 | (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
899 | |
|
900 | 0 | if (target.GetMakefile()->PlatformSupportsAppleTextStubs() && |
901 | 0 | target.IsSharedLibraryWithExports()) { |
902 | | // Apple .tbd files use the ARCHIVE properties |
903 | 0 | if (!archiveArgs.GetDestination().empty()) { |
904 | 0 | artifactsSpecified = true; |
905 | 0 | } |
906 | 0 | if (importlinkMode != |
907 | 0 | cmInstallTargetGenerator::NamelinkModeOnly) { |
908 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
909 | 0 | target, archiveArgs, true, helper.Makefile->GetBacktrace(), |
910 | 0 | helper.GetLibraryDestination(&archiveArgs)); |
911 | 0 | archiveGenerator->SetImportlinkMode( |
912 | 0 | cmInstallTargetGenerator::NamelinkModeSkip); |
913 | 0 | } |
914 | 0 | if (importlinkMode != |
915 | 0 | cmInstallTargetGenerator::NamelinkModeSkip) { |
916 | 0 | importlinkGenerator = CreateInstallTargetGenerator( |
917 | 0 | target, archiveArgs, true, helper.Makefile->GetBacktrace(), |
918 | 0 | helper.GetLibraryDestination(&archiveArgs), false, true); |
919 | 0 | importlinkGenerator->SetImportlinkMode( |
920 | 0 | cmInstallTargetGenerator::NamelinkModeOnly); |
921 | 0 | } |
922 | 0 | namelinkOnly = |
923 | 0 | (importlinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
924 | 0 | } |
925 | 0 | } |
926 | 0 | if (runtimeDependencySet && libraryGenerator) { |
927 | 0 | runtimeDependencySet->AddLibrary(libraryGenerator.get()); |
928 | 0 | } |
929 | 0 | } |
930 | 0 | } break; |
931 | 0 | case cmStateEnums::STATIC_LIBRARY: { |
932 | | // If it is marked with FRAMEWORK property use the FRAMEWORK set of |
933 | | // INSTALL properties. Otherwise, use the LIBRARY properties. |
934 | 0 | if (target.IsFrameworkOnApple()) { |
935 | | // When in namelink only mode skip frameworks. |
936 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
937 | 0 | namelinkOnly = true; |
938 | 0 | if (!addTargetExport()) { |
939 | 0 | return false; |
940 | 0 | } |
941 | 0 | continue; |
942 | 0 | } |
943 | | |
944 | | // Use the FRAMEWORK properties. |
945 | 0 | if (!frameworkArgs.GetDestination().empty()) { |
946 | 0 | frameworkGenerator = CreateInstallTargetGenerator( |
947 | 0 | target, frameworkArgs, false, helper.Makefile->GetBacktrace()); |
948 | 0 | } else { |
949 | 0 | status.SetError( |
950 | 0 | cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static " |
951 | 0 | "library FRAMEWORK target \"", |
952 | 0 | target.GetName(), "\".")); |
953 | 0 | return false; |
954 | 0 | } |
955 | 0 | } else { |
956 | | // Static libraries use ARCHIVE properties. |
957 | 0 | if (!archiveArgs.GetDestination().empty()) { |
958 | 0 | artifactsSpecified = true; |
959 | 0 | } |
960 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
961 | 0 | target, archiveArgs, false, helper.Makefile->GetBacktrace(), |
962 | 0 | helper.GetArchiveDestination(&archiveArgs)); |
963 | 0 | } |
964 | 0 | } break; |
965 | 0 | case cmStateEnums::MODULE_LIBRARY: { |
966 | | // Modules use LIBRARY properties. |
967 | 0 | if (!libraryArgs.GetDestination().empty()) { |
968 | 0 | libraryGenerator = CreateInstallTargetGenerator( |
969 | 0 | target, libraryArgs, false, helper.Makefile->GetBacktrace()); |
970 | 0 | libraryGenerator->SetNamelinkMode(namelinkMode); |
971 | 0 | namelinkOnly = |
972 | 0 | (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
973 | 0 | if (runtimeDependencySet) { |
974 | 0 | runtimeDependencySet->AddModule(libraryGenerator.get()); |
975 | 0 | } |
976 | 0 | } else { |
977 | 0 | status.SetError( |
978 | 0 | cmStrCat("TARGETS given no LIBRARY DESTINATION for module " |
979 | 0 | "target \"", |
980 | 0 | target.GetName(), "\".")); |
981 | 0 | return false; |
982 | 0 | } |
983 | 0 | } break; |
984 | 0 | case cmStateEnums::OBJECT_LIBRARY: { |
985 | | // Objects use OBJECT properties. |
986 | 0 | if (!objectArgs.GetDestination().empty()) { |
987 | | // Verify that we know where the objects are to install them. |
988 | 0 | std::string reason; |
989 | 0 | if (!target.HasKnownObjectFileLocation(&reason)) { |
990 | 0 | status.SetError( |
991 | 0 | cmStrCat("TARGETS given OBJECT library \"", target.GetName(), |
992 | 0 | "\" whose objects may not be installed", reason, '.')); |
993 | 0 | return false; |
994 | 0 | } |
995 | | |
996 | 0 | objectGenerator = CreateInstallTargetGenerator( |
997 | 0 | target, objectArgs, false, helper.Makefile->GetBacktrace()); |
998 | 0 | } else { |
999 | | // Installing an OBJECT library without a destination transforms |
1000 | | // it to an INTERFACE library. It installs no files but can be |
1001 | | // exported. |
1002 | 0 | } |
1003 | 0 | } break; |
1004 | 0 | case cmStateEnums::EXECUTABLE: { |
1005 | 0 | if (target.IsAppBundleOnApple()) { |
1006 | | // Application bundles use the BUNDLE properties. |
1007 | 0 | if (!bundleArgs.GetDestination().empty()) { |
1008 | 0 | bundleGenerator = CreateInstallTargetGenerator( |
1009 | 0 | target, bundleArgs, false, helper.Makefile->GetBacktrace()); |
1010 | 0 | } |
1011 | 0 | if (!bundleGenerator) { |
1012 | 0 | status.SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for " |
1013 | 0 | "MACOSX_BUNDLE executable target \"", |
1014 | 0 | target.GetName(), "\".")); |
1015 | 0 | return false; |
1016 | 0 | } |
1017 | 0 | if (runtimeDependencySet) { |
1018 | 0 | if (!AddBundleExecutable(helper, runtimeDependencySet, |
1019 | 0 | bundleGenerator.get())) { |
1020 | 0 | return false; |
1021 | 0 | } |
1022 | 0 | } |
1023 | 0 | } else { |
1024 | | // Executables use the RUNTIME properties. |
1025 | 0 | if (!runtimeArgs.GetDestination().empty()) { |
1026 | 0 | artifactsSpecified = true; |
1027 | 0 | } |
1028 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
1029 | 0 | target, runtimeArgs, false, helper.Makefile->GetBacktrace(), |
1030 | 0 | helper.GetRuntimeDestination(&runtimeArgs)); |
1031 | 0 | if (runtimeDependencySet) { |
1032 | 0 | runtimeDependencySet->AddExecutable(runtimeGenerator.get()); |
1033 | 0 | } |
1034 | 0 | } |
1035 | | |
1036 | | // On DLL platforms an executable may also have an import |
1037 | | // library. Install it to the archive destination if it |
1038 | | // exists. |
1039 | 0 | if ((target.IsDLLPlatform() || target.IsAIX()) && |
1040 | 0 | !archiveArgs.GetDestination().empty() && |
1041 | 0 | target.IsExecutableWithExports()) { |
1042 | | // The import library uses the ARCHIVE properties. |
1043 | 0 | artifactsSpecified = true; |
1044 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
1045 | 0 | target, archiveArgs, true, helper.Makefile->GetBacktrace(), true); |
1046 | 0 | } |
1047 | 0 | } break; |
1048 | 0 | case cmStateEnums::INTERFACE_LIBRARY: |
1049 | | // Nothing to do. An INTERFACE_LIBRARY can be installed, but the |
1050 | | // only effect of that is to make it exportable. It installs no |
1051 | | // other files itself. |
1052 | 0 | default: |
1053 | | // This should never happen due to the above type check. |
1054 | | // Ignore the case. |
1055 | 0 | break; |
1056 | 0 | } |
1057 | | |
1058 | | // These well-known sets of files are installed *automatically* for |
1059 | | // FRAMEWORK SHARED library targets on the Mac as part of installing the |
1060 | | // FRAMEWORK. For other target types or on other platforms, they are not |
1061 | | // installed automatically and so we need to create install files |
1062 | | // generators for them. |
1063 | 0 | bool createInstallGeneratorsForTargetFileSets = true; |
1064 | |
|
1065 | 0 | if (target.IsFrameworkOnApple()) { |
1066 | 0 | createInstallGeneratorsForTargetFileSets = false; |
1067 | 0 | } |
1068 | |
|
1069 | 0 | if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) { |
1070 | 0 | cmValue files = target.GetProperty("PRIVATE_HEADER"); |
1071 | 0 | if (cmNonempty(files)) { |
1072 | 0 | cmList relFiles{ *files }; |
1073 | 0 | std::vector<std::string> absFiles; |
1074 | 0 | if (!helper.MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) { |
1075 | 0 | return false; |
1076 | 0 | } |
1077 | | |
1078 | | // Create the files install generator. |
1079 | 0 | if (!artifactsSpecified || |
1080 | 0 | !privateHeaderArgs.GetDestination().empty()) { |
1081 | 0 | privateHeaderGenerator = CreateInstallFilesGenerator( |
1082 | 0 | helper.Makefile, absFiles, privateHeaderArgs, false, |
1083 | 0 | helper.GetIncludeDestination(&privateHeaderArgs)); |
1084 | 0 | } else { |
1085 | 0 | helper.Makefile->IssueDiagnostic( |
1086 | 0 | cmDiagnostics::CMD_AUTHOR, |
1087 | 0 | cmStrCat("Target ", target.GetName(), |
1088 | 0 | " has PRIVATE_HEADER files" |
1089 | 0 | " but no PRIVATE_HEADER DESTINATION.")); |
1090 | 0 | } |
1091 | 0 | } |
1092 | | |
1093 | 0 | files = target.GetProperty("PUBLIC_HEADER"); |
1094 | 0 | if (cmNonempty(files)) { |
1095 | 0 | cmList relFiles{ *files }; |
1096 | 0 | std::vector<std::string> absFiles; |
1097 | 0 | if (!helper.MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) { |
1098 | 0 | return false; |
1099 | 0 | } |
1100 | | |
1101 | | // Create the files install generator. |
1102 | 0 | if (!artifactsSpecified || |
1103 | 0 | !publicHeaderArgs.GetDestination().empty()) { |
1104 | 0 | publicHeaderGenerator = CreateInstallFilesGenerator( |
1105 | 0 | helper.Makefile, absFiles, publicHeaderArgs, false, |
1106 | 0 | helper.GetIncludeDestination(&publicHeaderArgs)); |
1107 | 0 | } else { |
1108 | 0 | helper.Makefile->IssueDiagnostic( |
1109 | 0 | cmDiagnostics::CMD_AUTHOR, |
1110 | 0 | cmStrCat("Target ", target.GetName(), |
1111 | 0 | " has PUBLIC_HEADER files" |
1112 | 0 | " but no PUBLIC_HEADER DESTINATION.")); |
1113 | 0 | } |
1114 | 0 | } |
1115 | | |
1116 | 0 | files = target.GetProperty("RESOURCE"); |
1117 | 0 | if (cmNonempty(files)) { |
1118 | 0 | cmList relFiles{ *files }; |
1119 | 0 | std::vector<std::string> absFiles; |
1120 | 0 | if (!helper.MakeFilesFullPath("RESOURCE", relFiles, absFiles)) { |
1121 | 0 | return false; |
1122 | 0 | } |
1123 | | |
1124 | | // Create the files install generator. |
1125 | 0 | if (!resourceArgs.GetDestination().empty()) { |
1126 | 0 | resourceGenerator = CreateInstallFilesGenerator( |
1127 | 0 | helper.Makefile, absFiles, resourceArgs, false); |
1128 | 0 | } else if (!target.IsAppBundleOnApple()) { |
1129 | 0 | helper.Makefile->IssueDiagnostic( |
1130 | 0 | cmDiagnostics::CMD_AUTHOR, |
1131 | 0 | cmStrCat("Target ", target.GetName(), |
1132 | 0 | " has RESOURCE files but no RESOURCE DESTINATION.")); |
1133 | 0 | } |
1134 | 0 | } |
1135 | 0 | } |
1136 | | |
1137 | 0 | if (!namelinkOnly) { |
1138 | 0 | for (std::size_t i = 0; i < fileSetArgs.size(); i++) { |
1139 | 0 | fileSetGenerators.push_back( |
1140 | 0 | CreateInstallFileSetGenerator(helper, target, fileSetArgs[i])); |
1141 | 0 | installsFileSet[i] = true; |
1142 | 0 | } |
1143 | 0 | } |
1144 | |
|
1145 | 0 | if (!cxxModuleBmiArgs.GetDestination().empty()) { |
1146 | 0 | cxxModuleBmiGenerator = cm::make_unique<cmInstallCxxModuleBmiGenerator>( |
1147 | 0 | target.GetName(), |
1148 | 0 | helper.GetCxxModulesBmiDestination(&cxxModuleBmiArgs), |
1149 | 0 | cxxModuleBmiArgs.GetPermissions(), |
1150 | 0 | cxxModuleBmiArgs.GetConfigurations(), cxxModuleBmiArgs.GetComponent(), |
1151 | 0 | cmInstallGenerator::SelectMessageLevel(target.GetMakefile()), |
1152 | 0 | cxxModuleBmiArgs.GetExcludeFromAll(), cxxModuleBmiArgs.GetOptional(), |
1153 | 0 | helper.Makefile->GetBacktrace()); |
1154 | 0 | target.SetHaveInstallRule(true); |
1155 | 0 | } |
1156 | | |
1157 | | // Add this install rule to an export if one was specified. |
1158 | 0 | if (!addTargetExport()) { |
1159 | 0 | return false; |
1160 | 0 | } |
1161 | | |
1162 | | // Keep track of whether we're installing anything in each category |
1163 | 0 | installsArchive = installsArchive || archiveGenerator; |
1164 | 0 | installsLibrary = installsLibrary || libraryGenerator; |
1165 | 0 | installsNamelink = installsNamelink || namelinkGenerator; |
1166 | 0 | installsImportlink = installsImportlink || importlinkGenerator; |
1167 | 0 | installsRuntime = installsRuntime || runtimeGenerator; |
1168 | 0 | installsObject = installsObject || objectGenerator; |
1169 | 0 | installsFramework = installsFramework || frameworkGenerator; |
1170 | 0 | installsBundle = installsBundle || bundleGenerator; |
1171 | 0 | installsPrivateHeader = installsPrivateHeader || privateHeaderGenerator; |
1172 | 0 | installsPublicHeader = installsPublicHeader || publicHeaderGenerator; |
1173 | 0 | installsResource = installsResource || resourceGenerator; |
1174 | 0 | installsCxxModuleBmi = installsCxxModuleBmi || cxxModuleBmiGenerator; |
1175 | |
|
1176 | 0 | helper.Makefile->AddInstallGenerator(std::move(archiveGenerator)); |
1177 | 0 | helper.Makefile->AddInstallGenerator(std::move(libraryGenerator)); |
1178 | 0 | helper.Makefile->AddInstallGenerator(std::move(namelinkGenerator)); |
1179 | 0 | helper.Makefile->AddInstallGenerator(std::move(importlinkGenerator)); |
1180 | 0 | helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator)); |
1181 | 0 | helper.Makefile->AddInstallGenerator(std::move(objectGenerator)); |
1182 | 0 | helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator)); |
1183 | 0 | helper.Makefile->AddInstallGenerator(std::move(bundleGenerator)); |
1184 | 0 | helper.Makefile->AddInstallGenerator(std::move(privateHeaderGenerator)); |
1185 | 0 | helper.Makefile->AddInstallGenerator(std::move(publicHeaderGenerator)); |
1186 | 0 | helper.Makefile->AddInstallGenerator(std::move(resourceGenerator)); |
1187 | 0 | for (auto& gen : fileSetGenerators) { |
1188 | 0 | helper.Makefile->AddInstallGenerator(std::move(gen)); |
1189 | 0 | } |
1190 | 0 | helper.Makefile->AddInstallGenerator(std::move(cxxModuleBmiGenerator)); |
1191 | 0 | } |
1192 | | |
1193 | 0 | if (runtimeDependenciesArgVector && !runtimeDependencySet->Empty()) { |
1194 | 0 | AddInstallRuntimeDependenciesGenerator( |
1195 | 0 | helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs, |
1196 | 0 | std::move(runtimeDependenciesArgs), installsRuntime, installsLibrary, |
1197 | 0 | installsFramework); |
1198 | 0 | } |
1199 | | |
1200 | | // Tell the global generator about any installation component names |
1201 | | // specified |
1202 | 0 | if (installsArchive) { |
1203 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1204 | 0 | archiveArgs.GetComponent()); |
1205 | 0 | } |
1206 | 0 | if (installsLibrary) { |
1207 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1208 | 0 | libraryArgs.GetComponent()); |
1209 | 0 | } |
1210 | 0 | if (installsNamelink) { |
1211 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1212 | 0 | libraryArgs.GetNamelinkComponent()); |
1213 | 0 | } |
1214 | 0 | if (installsImportlink) { |
1215 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1216 | 0 | archiveArgs.GetNamelinkComponent()); |
1217 | 0 | } |
1218 | 0 | if (installsRuntime) { |
1219 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1220 | 0 | runtimeArgs.GetComponent()); |
1221 | 0 | } |
1222 | 0 | if (installsObject) { |
1223 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1224 | 0 | objectArgs.GetComponent()); |
1225 | 0 | } |
1226 | 0 | if (installsFramework) { |
1227 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1228 | 0 | frameworkArgs.GetComponent()); |
1229 | 0 | } |
1230 | 0 | if (installsBundle) { |
1231 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1232 | 0 | bundleArgs.GetComponent()); |
1233 | 0 | } |
1234 | 0 | if (installsPrivateHeader) { |
1235 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1236 | 0 | privateHeaderArgs.GetComponent()); |
1237 | 0 | } |
1238 | 0 | if (installsPublicHeader) { |
1239 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1240 | 0 | publicHeaderArgs.GetComponent()); |
1241 | 0 | } |
1242 | 0 | if (installsResource) { |
1243 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1244 | 0 | resourceArgs.GetComponent()); |
1245 | 0 | } |
1246 | 0 | for (std::size_t i = 0; i < fileSetArgs.size(); i++) { |
1247 | 0 | if (installsFileSet[i]) { |
1248 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1249 | 0 | fileSetArgs[i].GetComponent()); |
1250 | 0 | } |
1251 | 0 | } |
1252 | 0 | if (installsCxxModuleBmi) { |
1253 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1254 | 0 | cxxModuleBmiArgs.GetComponent()); |
1255 | 0 | } |
1256 | |
|
1257 | 0 | return true; |
1258 | 0 | } |
1259 | | |
1260 | | bool HandleImportedRuntimeArtifactsMode(std::vector<std::string> const& args, |
1261 | | cmExecutionStatus& status) |
1262 | 0 | { |
1263 | 0 | Helper helper(status); |
1264 | | |
1265 | | // This is the IMPORTED_RUNTIME_ARTIFACTS mode. |
1266 | 0 | std::vector<cmTarget*> targets; |
1267 | |
|
1268 | 0 | struct ArgVectors |
1269 | 0 | { |
1270 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Library; |
1271 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime; |
1272 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework; |
1273 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle; |
1274 | 0 | }; |
1275 | |
|
1276 | 0 | static auto const argHelper = cmArgumentParser<ArgVectors>{} |
1277 | 0 | .Bind("LIBRARY"_s, &ArgVectors::Library) |
1278 | 0 | .Bind("RUNTIME"_s, &ArgVectors::Runtime) |
1279 | 0 | .Bind("FRAMEWORK"_s, &ArgVectors::Framework) |
1280 | 0 | .Bind("BUNDLE"_s, &ArgVectors::Bundle); |
1281 | |
|
1282 | 0 | std::vector<std::string> genericArgVector; |
1283 | 0 | ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); |
1284 | | |
1285 | | // now parse the generic args (i.e. the ones not specialized on LIBRARY, |
1286 | | // RUNTIME etc. (see above) |
1287 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList; |
1288 | 0 | std::string runtimeDependencySetArg; |
1289 | 0 | std::vector<std::string> unknownArgs; |
1290 | 0 | cmInstallCommandArguments genericArgs(helper.DefaultComponentName, |
1291 | 0 | *helper.Makefile); |
1292 | 0 | genericArgs.Bind("IMPORTED_RUNTIME_ARTIFACTS"_s, targetList) |
1293 | 0 | .Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg); |
1294 | 0 | genericArgs.Parse(genericArgVector, &unknownArgs); |
1295 | 0 | bool success = genericArgs.Finalize(); |
1296 | |
|
1297 | 0 | cmInstallCommandArguments libraryArgs(helper.DefaultComponentName, |
1298 | 0 | *helper.Makefile); |
1299 | 0 | cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName, |
1300 | 0 | *helper.Makefile); |
1301 | 0 | cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName, |
1302 | 0 | *helper.Makefile); |
1303 | 0 | cmInstallCommandArguments bundleArgs(helper.DefaultComponentName, |
1304 | 0 | *helper.Makefile); |
1305 | | |
1306 | | // now parse the args for specific parts of the target (e.g. LIBRARY, |
1307 | | // RUNTIME etc. |
1308 | 0 | libraryArgs.Parse(argVectors.Library, &unknownArgs); |
1309 | 0 | runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); |
1310 | 0 | frameworkArgs.Parse(argVectors.Framework, &unknownArgs); |
1311 | 0 | bundleArgs.Parse(argVectors.Bundle, &unknownArgs); |
1312 | |
|
1313 | 0 | if (!unknownArgs.empty()) { |
1314 | | // Unknown argument. |
1315 | 0 | status.SetError( |
1316 | 0 | cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given unknown argument \"", |
1317 | 0 | unknownArgs[0], "\".")); |
1318 | 0 | return false; |
1319 | 0 | } |
1320 | | |
1321 | | // apply generic args |
1322 | 0 | libraryArgs.SetGenericArguments(&genericArgs); |
1323 | 0 | runtimeArgs.SetGenericArguments(&genericArgs); |
1324 | 0 | frameworkArgs.SetGenericArguments(&genericArgs); |
1325 | 0 | bundleArgs.SetGenericArguments(&genericArgs); |
1326 | |
|
1327 | 0 | success = success && libraryArgs.Finalize(); |
1328 | 0 | success = success && runtimeArgs.Finalize(); |
1329 | 0 | success = success && frameworkArgs.Finalize(); |
1330 | 0 | success = success && bundleArgs.Finalize(); |
1331 | |
|
1332 | 0 | if (!success) { |
1333 | 0 | return false; |
1334 | 0 | } |
1335 | | |
1336 | 0 | cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr; |
1337 | 0 | if (!runtimeDependencySetArg.empty()) { |
1338 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
1339 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
1340 | 0 | system)) { |
1341 | 0 | status.SetError( |
1342 | 0 | cmStrCat("IMPORTED_RUNTIME_ARTIFACTS RUNTIME_DEPENDENCY_SET is not " |
1343 | 0 | "supported on system \"", |
1344 | 0 | system, '"')); |
1345 | 0 | return false; |
1346 | 0 | } |
1347 | 0 | runtimeDependencySet = |
1348 | 0 | helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet( |
1349 | 0 | runtimeDependencySetArg); |
1350 | 0 | } |
1351 | | |
1352 | | // Check if there is something to do. |
1353 | 0 | if (targetList.empty()) { |
1354 | 0 | return true; |
1355 | 0 | } |
1356 | | |
1357 | 0 | for (std::string const& tgt : targetList) { |
1358 | 0 | if (helper.Makefile->IsAlias(tgt)) { |
1359 | 0 | status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"", |
1360 | 0 | tgt, "\" which is an alias.")); |
1361 | 0 | return false; |
1362 | 0 | } |
1363 | | // Lookup this target in the current directory. |
1364 | 0 | cmTarget* target = helper.Makefile->FindTargetToUse(tgt); |
1365 | 0 | if (!target || !target->IsImported()) { |
1366 | | // If no local target has been found, find it in the global scope. |
1367 | 0 | cmTarget* const global_target = |
1368 | 0 | helper.Makefile->GetGlobalGenerator()->FindTarget( |
1369 | 0 | tgt, { cmStateEnums::TargetDomain::NATIVE }); |
1370 | 0 | if (global_target && global_target->IsImported()) { |
1371 | 0 | target = global_target; |
1372 | 0 | } |
1373 | 0 | } |
1374 | 0 | if (target) { |
1375 | | // Found the target. Check its type. |
1376 | 0 | if (target->GetType() != cmStateEnums::EXECUTABLE && |
1377 | 0 | target->GetType() != cmStateEnums::SHARED_LIBRARY && |
1378 | 0 | target->GetType() != cmStateEnums::MODULE_LIBRARY) { |
1379 | 0 | status.SetError( |
1380 | 0 | cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"", tgt, |
1381 | 0 | "\" which is not an executable, library, or module.")); |
1382 | 0 | return false; |
1383 | 0 | } |
1384 | | // Store the target in the list to be installed. |
1385 | 0 | targets.push_back(target); |
1386 | 0 | } else { |
1387 | | // Did not find the target. |
1388 | 0 | status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given target \"", |
1389 | 0 | tgt, "\" which does not exist.")); |
1390 | 0 | return false; |
1391 | 0 | } |
1392 | 0 | } |
1393 | | |
1394 | | // Keep track of whether we will be performing an installation of |
1395 | | // any files of the given type. |
1396 | 0 | bool installsLibrary = false; |
1397 | 0 | bool installsRuntime = false; |
1398 | 0 | bool installsFramework = false; |
1399 | 0 | bool installsBundle = false; |
1400 | |
|
1401 | 0 | auto const createInstallGenerator = |
1402 | 0 | [helper](cmTarget& target, cmInstallCommandArguments const& typeArgs, |
1403 | 0 | std::string const& destination) |
1404 | 0 | -> std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> { |
1405 | 0 | return cm::make_unique<cmInstallImportedRuntimeArtifactsGenerator>( |
1406 | 0 | target.GetName(), destination, typeArgs.GetPermissions(), |
1407 | 0 | typeArgs.GetConfigurations(), typeArgs.GetComponent(), |
1408 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
1409 | 0 | typeArgs.GetExcludeFromAll(), typeArgs.GetOptional(), |
1410 | 0 | helper.Makefile->GetBacktrace()); |
1411 | 0 | }; |
1412 | | |
1413 | | // Generate install script code to install the given targets. |
1414 | 0 | for (cmTarget* ti : targets) { |
1415 | | // Handle each target type. |
1416 | 0 | cmTarget& target = *ti; |
1417 | 0 | std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> |
1418 | 0 | libraryGenerator; |
1419 | 0 | std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> |
1420 | 0 | runtimeGenerator; |
1421 | 0 | std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> |
1422 | 0 | frameworkGenerator; |
1423 | 0 | std::unique_ptr<cmInstallImportedRuntimeArtifactsGenerator> |
1424 | 0 | bundleGenerator; |
1425 | |
|
1426 | 0 | switch (target.GetType()) { |
1427 | 0 | case cmStateEnums::SHARED_LIBRARY: |
1428 | 0 | if (target.IsDLLPlatform()) { |
1429 | 0 | runtimeGenerator = createInstallGenerator( |
1430 | 0 | target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs)); |
1431 | 0 | if (runtimeDependencySet) { |
1432 | 0 | runtimeDependencySet->AddLibrary(runtimeGenerator.get()); |
1433 | 0 | } |
1434 | 0 | } else if (target.IsFrameworkOnApple()) { |
1435 | 0 | if (frameworkArgs.GetDestination().empty()) { |
1436 | 0 | status.SetError(cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no " |
1437 | 0 | "FRAMEWORK DESTINATION for shared " |
1438 | 0 | "library FRAMEWORK target \"", |
1439 | 0 | target.GetName(), "\".")); |
1440 | 0 | return false; |
1441 | 0 | } |
1442 | 0 | frameworkGenerator = createInstallGenerator( |
1443 | 0 | target, frameworkArgs, frameworkArgs.GetDestination()); |
1444 | 0 | if (runtimeDependencySet) { |
1445 | 0 | runtimeDependencySet->AddLibrary(frameworkGenerator.get()); |
1446 | 0 | } |
1447 | 0 | } else { |
1448 | 0 | libraryGenerator = createInstallGenerator( |
1449 | 0 | target, libraryArgs, helper.GetLibraryDestination(&libraryArgs)); |
1450 | 0 | if (runtimeDependencySet) { |
1451 | 0 | runtimeDependencySet->AddLibrary(libraryGenerator.get()); |
1452 | 0 | } |
1453 | 0 | } |
1454 | 0 | break; |
1455 | 0 | case cmStateEnums::MODULE_LIBRARY: |
1456 | 0 | libraryGenerator = createInstallGenerator( |
1457 | 0 | target, libraryArgs, helper.GetLibraryDestination(&libraryArgs)); |
1458 | 0 | if (runtimeDependencySet) { |
1459 | 0 | runtimeDependencySet->AddModule(libraryGenerator.get()); |
1460 | 0 | } |
1461 | 0 | break; |
1462 | 0 | case cmStateEnums::EXECUTABLE: |
1463 | 0 | if (target.IsAppBundleOnApple()) { |
1464 | 0 | if (bundleArgs.GetDestination().empty()) { |
1465 | 0 | status.SetError( |
1466 | 0 | cmStrCat("IMPORTED_RUNTIME_ARTIFACTS given no BUNDLE " |
1467 | 0 | "DESTINATION for MACOSX_BUNDLE executable target \"", |
1468 | 0 | target.GetName(), "\".")); |
1469 | 0 | return false; |
1470 | 0 | } |
1471 | 0 | bundleGenerator = createInstallGenerator( |
1472 | 0 | target, bundleArgs, bundleArgs.GetDestination()); |
1473 | 0 | if (runtimeDependencySet) { |
1474 | 0 | if (!AddBundleExecutable(helper, runtimeDependencySet, |
1475 | 0 | bundleGenerator.get())) { |
1476 | 0 | return false; |
1477 | 0 | } |
1478 | 0 | } |
1479 | 0 | } else { |
1480 | 0 | runtimeGenerator = createInstallGenerator( |
1481 | 0 | target, runtimeArgs, helper.GetRuntimeDestination(&runtimeArgs)); |
1482 | 0 | if (runtimeDependencySet) { |
1483 | 0 | runtimeDependencySet->AddExecutable(runtimeGenerator.get()); |
1484 | 0 | } |
1485 | 0 | } |
1486 | 0 | break; |
1487 | 0 | default: |
1488 | 0 | assert(false && "This should never happen"); |
1489 | 0 | break; |
1490 | 0 | } |
1491 | | |
1492 | | // Keep track of whether we're installing anything in each category |
1493 | 0 | installsLibrary = installsLibrary || libraryGenerator; |
1494 | 0 | installsRuntime = installsRuntime || runtimeGenerator; |
1495 | 0 | installsFramework = installsFramework || frameworkGenerator; |
1496 | 0 | installsBundle = installsBundle || bundleGenerator; |
1497 | |
|
1498 | 0 | helper.Makefile->AddInstallGenerator(std::move(libraryGenerator)); |
1499 | 0 | helper.Makefile->AddInstallGenerator(std::move(runtimeGenerator)); |
1500 | 0 | helper.Makefile->AddInstallGenerator(std::move(frameworkGenerator)); |
1501 | 0 | helper.Makefile->AddInstallGenerator(std::move(bundleGenerator)); |
1502 | 0 | } |
1503 | | |
1504 | | // Tell the global generator about any installation component names |
1505 | | // specified |
1506 | 0 | if (installsLibrary) { |
1507 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1508 | 0 | libraryArgs.GetComponent()); |
1509 | 0 | } |
1510 | 0 | if (installsRuntime) { |
1511 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1512 | 0 | runtimeArgs.GetComponent()); |
1513 | 0 | } |
1514 | 0 | if (installsFramework) { |
1515 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1516 | 0 | frameworkArgs.GetComponent()); |
1517 | 0 | } |
1518 | 0 | if (installsBundle) { |
1519 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1520 | 0 | bundleArgs.GetComponent()); |
1521 | 0 | } |
1522 | |
|
1523 | 0 | return true; |
1524 | 0 | } |
1525 | | |
1526 | | bool HandleFilesMode(std::vector<std::string> const& args, |
1527 | | cmExecutionStatus& status) |
1528 | 0 | { |
1529 | 0 | Helper helper(status); |
1530 | | |
1531 | | // This is the FILES mode. |
1532 | 0 | bool programs = (args[0] == "PROGRAMS"); |
1533 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
1534 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> files; |
1535 | 0 | ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files); |
1536 | 0 | std::vector<std::string> unknownArgs; |
1537 | 0 | ica.Parse(args, &unknownArgs); |
1538 | |
|
1539 | 0 | if (!unknownArgs.empty()) { |
1540 | | // Unknown argument. |
1541 | 0 | status.SetError( |
1542 | 0 | cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); |
1543 | 0 | return false; |
1544 | 0 | } |
1545 | | |
1546 | 0 | std::string type = ica.GetType(); |
1547 | 0 | if (!type.empty() && allowedTypes.count(type) == 0) { |
1548 | 0 | status.SetError( |
1549 | 0 | cmStrCat(args[0], " given non-type \"", type, "\" with TYPE argument.")); |
1550 | 0 | return false; |
1551 | 0 | } |
1552 | | |
1553 | 0 | std::vector<std::string> const& filesVector = files; |
1554 | | |
1555 | | // Check if there is something to do. |
1556 | 0 | if (filesVector.empty()) { |
1557 | 0 | return true; |
1558 | 0 | } |
1559 | | |
1560 | 0 | if (!ica.GetRename().empty() && filesVector.size() > 1) { |
1561 | | // The rename option works only with one file. |
1562 | 0 | status.SetError( |
1563 | 0 | cmStrCat(args[0], " given RENAME option with more than one file.")); |
1564 | 0 | return false; |
1565 | 0 | } |
1566 | | |
1567 | 0 | std::vector<std::string> absFiles; |
1568 | 0 | if (!helper.MakeFilesFullPath(args[0].c_str(), filesVector, absFiles)) { |
1569 | 0 | return false; |
1570 | 0 | } |
1571 | | |
1572 | 0 | cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator(); |
1573 | 0 | for (std::string const& file : filesVector) { |
1574 | 0 | if (gg->IsExportedTargetsFile(file)) { |
1575 | 0 | helper.Makefile->IssueMessage( |
1576 | 0 | MessageType::FATAL_ERROR, |
1577 | 0 | cmStrCat("The file\n ", file, |
1578 | 0 | "\n" |
1579 | 0 | "was generated by the export() command. " |
1580 | 0 | "It may not be installed with the install() command. " |
1581 | 0 | "Use the install(EXPORT) mechanism instead. " |
1582 | 0 | "See the cmake-packages(7) manual for more.")); |
1583 | 0 | return false; |
1584 | 0 | } |
1585 | 0 | } |
1586 | | |
1587 | 0 | if (!ica.Finalize()) { |
1588 | 0 | return false; |
1589 | 0 | } |
1590 | | |
1591 | 0 | if (!type.empty() && !ica.GetDestination().empty()) { |
1592 | 0 | status.SetError(cmStrCat(args[0], |
1593 | 0 | " given both TYPE and DESTINATION arguments. " |
1594 | 0 | "You may only specify one.")); |
1595 | 0 | return false; |
1596 | 0 | } |
1597 | | |
1598 | 0 | std::string destination = helper.GetDestinationForType(&ica, type); |
1599 | 0 | if (destination.empty()) { |
1600 | | // A destination is required. |
1601 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
1602 | 0 | return false; |
1603 | 0 | } |
1604 | | |
1605 | | // Create the files install generator. |
1606 | 0 | helper.Makefile->AddInstallGenerator(CreateInstallFilesGenerator( |
1607 | 0 | helper.Makefile, absFiles, ica, programs, destination)); |
1608 | | |
1609 | | // Tell the global generator about any installation component names |
1610 | | // specified. |
1611 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
1612 | 0 | ica.GetComponent()); |
1613 | |
|
1614 | 0 | return true; |
1615 | 0 | } |
1616 | | |
1617 | | bool HandleDirectoryMode(std::vector<std::string> const& args, |
1618 | | cmExecutionStatus& status) |
1619 | 0 | { |
1620 | 0 | Helper helper(status); |
1621 | |
|
1622 | 0 | enum Doing |
1623 | 0 | { |
1624 | 0 | DoingNone, |
1625 | 0 | DoingDirs, |
1626 | 0 | DoingDestination, |
1627 | 0 | DoingPattern, |
1628 | 0 | DoingRegex, |
1629 | 0 | DoingPermsFile, |
1630 | 0 | DoingPermsDir, |
1631 | 0 | DoingPermsMatch, |
1632 | 0 | DoingConfigurations, |
1633 | 0 | DoingComponent, |
1634 | 0 | DoingType |
1635 | 0 | }; |
1636 | 0 | Doing doing = DoingDirs; |
1637 | 0 | bool in_match_mode = false; |
1638 | 0 | bool optional = false; |
1639 | 0 | bool exclude_from_all = false; |
1640 | 0 | bool message_never = false; |
1641 | 0 | std::vector<std::string> dirs; |
1642 | 0 | cm::optional<std::string> destination; |
1643 | 0 | std::string permissions_file; |
1644 | 0 | std::string permissions_dir; |
1645 | 0 | std::vector<std::string> configurations; |
1646 | 0 | std::string component = helper.DefaultComponentName; |
1647 | 0 | std::string literal_args; |
1648 | 0 | std::string type; |
1649 | 0 | for (unsigned int i = 1; i < args.size(); ++i) { |
1650 | 0 | if (args[i] == "DESTINATION") { |
1651 | 0 | if (in_match_mode) { |
1652 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1653 | 0 | "\" after PATTERN or REGEX.")); |
1654 | 0 | return false; |
1655 | 0 | } |
1656 | | |
1657 | | // Switch to setting the destination property. |
1658 | 0 | doing = DoingDestination; |
1659 | 0 | } else if (args[i] == "TYPE") { |
1660 | 0 | if (in_match_mode) { |
1661 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1662 | 0 | "\" after PATTERN or REGEX.")); |
1663 | 0 | return false; |
1664 | 0 | } |
1665 | | |
1666 | | // Switch to setting the type. |
1667 | 0 | doing = DoingType; |
1668 | 0 | } else if (args[i] == "OPTIONAL") { |
1669 | 0 | if (in_match_mode) { |
1670 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1671 | 0 | "\" after PATTERN or REGEX.")); |
1672 | 0 | return false; |
1673 | 0 | } |
1674 | | |
1675 | | // Mark the rule as optional. |
1676 | 0 | optional = true; |
1677 | 0 | doing = DoingNone; |
1678 | 0 | } else if (args[i] == "MESSAGE_NEVER") { |
1679 | 0 | if (in_match_mode) { |
1680 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1681 | 0 | "\" after PATTERN or REGEX.")); |
1682 | 0 | return false; |
1683 | 0 | } |
1684 | | |
1685 | | // Mark the rule as quiet. |
1686 | 0 | message_never = true; |
1687 | 0 | doing = DoingNone; |
1688 | 0 | } else if (args[i] == "PATTERN") { |
1689 | | // Switch to a new pattern match rule. |
1690 | 0 | doing = DoingPattern; |
1691 | 0 | in_match_mode = true; |
1692 | 0 | } else if (args[i] == "REGEX") { |
1693 | | // Switch to a new regex match rule. |
1694 | 0 | doing = DoingRegex; |
1695 | 0 | in_match_mode = true; |
1696 | 0 | } else if (args[i] == "EXCLUDE") { |
1697 | | // Add this property to the current match rule. |
1698 | 0 | if (!in_match_mode || doing == DoingPattern || doing == DoingRegex) { |
1699 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1700 | 0 | "\" before a PATTERN or REGEX is given.")); |
1701 | 0 | return false; |
1702 | 0 | } |
1703 | 0 | literal_args += " EXCLUDE"; |
1704 | 0 | doing = DoingNone; |
1705 | 0 | } else if (args[i] == "PERMISSIONS") { |
1706 | 0 | if (!in_match_mode) { |
1707 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1708 | 0 | "\" before a PATTERN or REGEX is given.")); |
1709 | 0 | return false; |
1710 | 0 | } |
1711 | | |
1712 | | // Switch to setting the current match permissions property. |
1713 | 0 | literal_args += " PERMISSIONS"; |
1714 | 0 | doing = DoingPermsMatch; |
1715 | 0 | } else if (args[i] == "FILE_PERMISSIONS") { |
1716 | 0 | if (in_match_mode) { |
1717 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1718 | 0 | "\" after PATTERN or REGEX.")); |
1719 | 0 | return false; |
1720 | 0 | } |
1721 | | |
1722 | | // Switch to setting the file permissions property. |
1723 | 0 | doing = DoingPermsFile; |
1724 | 0 | } else if (args[i] == "DIRECTORY_PERMISSIONS") { |
1725 | 0 | if (in_match_mode) { |
1726 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1727 | 0 | "\" after PATTERN or REGEX.")); |
1728 | 0 | return false; |
1729 | 0 | } |
1730 | | |
1731 | | // Switch to setting the directory permissions property. |
1732 | 0 | doing = DoingPermsDir; |
1733 | 0 | } else if (args[i] == "USE_SOURCE_PERMISSIONS") { |
1734 | 0 | if (in_match_mode) { |
1735 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1736 | 0 | "\" after PATTERN or REGEX.")); |
1737 | 0 | return false; |
1738 | 0 | } |
1739 | | |
1740 | | // Add this option literally. |
1741 | 0 | literal_args += " USE_SOURCE_PERMISSIONS"; |
1742 | 0 | doing = DoingNone; |
1743 | 0 | } else if (args[i] == "FILES_MATCHING") { |
1744 | 0 | if (in_match_mode) { |
1745 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1746 | 0 | "\" after PATTERN or REGEX.")); |
1747 | 0 | return false; |
1748 | 0 | } |
1749 | | |
1750 | | // Add this option literally. |
1751 | 0 | literal_args += " FILES_MATCHING"; |
1752 | 0 | doing = DoingNone; |
1753 | 0 | } else if (args[i] == "CONFIGURATIONS") { |
1754 | 0 | if (in_match_mode) { |
1755 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1756 | 0 | "\" after PATTERN or REGEX.")); |
1757 | 0 | return false; |
1758 | 0 | } |
1759 | | |
1760 | | // Switch to setting the configurations property. |
1761 | 0 | doing = DoingConfigurations; |
1762 | 0 | } else if (args[i] == "COMPONENT") { |
1763 | 0 | if (in_match_mode) { |
1764 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1765 | 0 | "\" after PATTERN or REGEX.")); |
1766 | 0 | return false; |
1767 | 0 | } |
1768 | | |
1769 | | // Switch to setting the component property. |
1770 | 0 | doing = DoingComponent; |
1771 | 0 | } else if (args[i] == "EXCLUDE_FROM_ALL") { |
1772 | 0 | if (in_match_mode) { |
1773 | 0 | status.SetError(cmStrCat(args[0], " does not allow \"", args[i], |
1774 | 0 | "\" after PATTERN or REGEX.")); |
1775 | 0 | return false; |
1776 | 0 | } |
1777 | 0 | exclude_from_all = true; |
1778 | 0 | doing = DoingNone; |
1779 | 0 | } else if (doing == DoingDirs) { |
1780 | | // If the given directory is not a full path, convert it to one by |
1781 | | // assuming it's relative to the current source directory. |
1782 | 0 | std::string dir = args[i]; |
1783 | 0 | std::string::size_type gpos = cmGeneratorExpression::Find(dir); |
1784 | 0 | if (!dir.empty() && gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) { |
1785 | 0 | dir = |
1786 | 0 | cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', args[i]); |
1787 | 0 | } |
1788 | | |
1789 | | // Make sure the name is a directory. |
1790 | 0 | if (cmSystemTools::FileExists(dir, true)) { |
1791 | 0 | status.SetError(cmStrCat(args[0], " given non-directory \"", args[i], |
1792 | 0 | "\" to install.")); |
1793 | 0 | return false; |
1794 | 0 | } |
1795 | | |
1796 | | // Store the directory for installation. |
1797 | 0 | dirs.push_back(std::move(dir)); |
1798 | 0 | } else if (doing == DoingConfigurations) { |
1799 | 0 | configurations.push_back(args[i]); |
1800 | 0 | } else if (doing == DoingDestination) { |
1801 | | // A trailing slash is meaningful for this form, but normalization |
1802 | | // preserves it if present |
1803 | 0 | switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0177)) { |
1804 | 0 | case cmPolicies::NEW: |
1805 | 0 | destination = cmCMakePath(args[i]).Normal().String(); |
1806 | 0 | break; |
1807 | 0 | case cmPolicies::WARN: |
1808 | | // We can't be certain if a warning is appropriate if there are any |
1809 | | // generator expressions |
1810 | 0 | if (cmGeneratorExpression::Find(args[i]) == cm::string_view::npos && |
1811 | 0 | args[i] != cmCMakePath(args[i]).Normal().String()) { |
1812 | 0 | status.GetMakefile().IssueDiagnostic( |
1813 | 0 | cmDiagnostics::CMD_AUTHOR, |
1814 | 0 | cmPolicies::GetPolicyWarning(cmPolicies::CMP0177)); |
1815 | 0 | } |
1816 | 0 | CM_FALLTHROUGH; |
1817 | 0 | case cmPolicies::OLD: |
1818 | 0 | destination = args[i]; |
1819 | 0 | break; |
1820 | 0 | } |
1821 | 0 | doing = DoingNone; |
1822 | 0 | } else if (doing == DoingType) { |
1823 | 0 | if (allowedTypes.count(args[i]) == 0) { |
1824 | 0 | status.SetError(cmStrCat(args[0], " given non-type \"", args[i], |
1825 | 0 | "\" with TYPE argument.")); |
1826 | 0 | return false; |
1827 | 0 | } |
1828 | | |
1829 | 0 | type = args[i]; |
1830 | 0 | doing = DoingNone; |
1831 | 0 | } else if (doing == DoingPattern) { |
1832 | | // Convert the pattern to a regular expression. Require a |
1833 | | // leading slash and trailing end-of-string in the matched |
1834 | | // string to make sure the pattern matches only whole file |
1835 | | // names. |
1836 | 0 | literal_args += " REGEX \"/"; |
1837 | 0 | std::string regex = cmsys::Glob::PatternToRegex(args[i], false); |
1838 | 0 | cmSystemTools::ReplaceString(regex, "\\", "\\\\"); |
1839 | 0 | literal_args += regex; |
1840 | 0 | literal_args += "$\""; |
1841 | 0 | doing = DoingNone; |
1842 | 0 | } else if (doing == DoingRegex) { |
1843 | 0 | literal_args += " REGEX \""; |
1844 | | // Match rules are case-insensitive on some platforms. |
1845 | | #if defined(_WIN32) || defined(__APPLE__) |
1846 | | std::string regex = cmSystemTools::LowerCase(args[i]); |
1847 | | #else |
1848 | 0 | std::string regex = args[i]; |
1849 | 0 | #endif |
1850 | 0 | cmSystemTools::ReplaceString(regex, "\\", "\\\\"); |
1851 | 0 | literal_args += regex; |
1852 | 0 | literal_args += "\""; |
1853 | 0 | doing = DoingNone; |
1854 | 0 | } else if (doing == DoingComponent) { |
1855 | 0 | component = args[i]; |
1856 | 0 | doing = DoingNone; |
1857 | 0 | } else if (doing == DoingPermsFile) { |
1858 | | // Check the requested permission. |
1859 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], |
1860 | 0 | permissions_file)) { |
1861 | 0 | status.SetError(cmStrCat(args[0], " given invalid file permission \"", |
1862 | 0 | args[i], "\".")); |
1863 | 0 | return false; |
1864 | 0 | } |
1865 | 0 | } else if (doing == DoingPermsDir) { |
1866 | | // Check the requested permission. |
1867 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], |
1868 | 0 | permissions_dir)) { |
1869 | 0 | status.SetError(cmStrCat( |
1870 | 0 | args[0], " given invalid directory permission \"", args[i], "\".")); |
1871 | 0 | return false; |
1872 | 0 | } |
1873 | 0 | } else if (doing == DoingPermsMatch) { |
1874 | | // Check the requested permission. |
1875 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], |
1876 | 0 | literal_args)) { |
1877 | 0 | status.SetError( |
1878 | 0 | cmStrCat(args[0], " given invalid permission \"", args[i], "\".")); |
1879 | 0 | return false; |
1880 | 0 | } |
1881 | 0 | } else { |
1882 | | // Unknown argument. |
1883 | 0 | status.SetError( |
1884 | 0 | cmStrCat(args[0], " given unknown argument \"", args[i], "\".")); |
1885 | 0 | return false; |
1886 | 0 | } |
1887 | 0 | } |
1888 | | |
1889 | | // Support installing an empty directory. |
1890 | 0 | if (dirs.empty() && destination.has_value()) { |
1891 | 0 | dirs.emplace_back(); |
1892 | 0 | } |
1893 | | |
1894 | | // Check if there is something to do. |
1895 | 0 | if (dirs.empty()) { |
1896 | 0 | return true; |
1897 | 0 | } |
1898 | 0 | if (!destination.has_value()) { |
1899 | 0 | if (type.empty()) { |
1900 | | // A destination is required. |
1901 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
1902 | 0 | return false; |
1903 | 0 | } |
1904 | 0 | destination = helper.GetDestinationForType(nullptr, type); |
1905 | 0 | } else if (!type.empty()) { |
1906 | 0 | status.SetError(cmStrCat(args[0], |
1907 | 0 | " given both TYPE and DESTINATION " |
1908 | 0 | "arguments. You may only specify one.")); |
1909 | 0 | return false; |
1910 | 0 | } |
1911 | | |
1912 | 0 | cmInstallGenerator::MessageLevel message = |
1913 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile, message_never); |
1914 | | |
1915 | | // Create the directory install generator. |
1916 | 0 | helper.Makefile->AddInstallGenerator( |
1917 | 0 | cm::make_unique<cmInstallDirectoryGenerator>( |
1918 | 0 | dirs, *destination, permissions_file, permissions_dir, configurations, |
1919 | 0 | component, message, exclude_from_all, literal_args, optional, |
1920 | 0 | helper.Makefile->GetBacktrace())); |
1921 | | |
1922 | | // Tell the global generator about any installation component names |
1923 | | // specified. |
1924 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component); |
1925 | |
|
1926 | 0 | return true; |
1927 | 0 | } |
1928 | | |
1929 | | bool HandleExportAndroidMKMode(std::vector<std::string> const& args, |
1930 | | cmExecutionStatus& status) |
1931 | 0 | { |
1932 | 0 | #ifndef CMAKE_BOOTSTRAP |
1933 | 0 | Helper helper(status); |
1934 | | |
1935 | | // This is the EXPORT mode. |
1936 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
1937 | |
|
1938 | 0 | std::string exp; |
1939 | 0 | std::string name_space; |
1940 | 0 | bool exportOld = false; |
1941 | 0 | std::string filename; |
1942 | |
|
1943 | 0 | ica.Bind("EXPORT_ANDROID_MK"_s, exp); |
1944 | 0 | ica.Bind("NAMESPACE"_s, name_space); |
1945 | 0 | ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld); |
1946 | 0 | ica.Bind("FILE"_s, filename); |
1947 | |
|
1948 | 0 | std::vector<std::string> unknownArgs; |
1949 | 0 | ica.Parse(args, &unknownArgs); |
1950 | |
|
1951 | 0 | if (!unknownArgs.empty()) { |
1952 | | // Unknown argument. |
1953 | 0 | status.SetError( |
1954 | 0 | cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); |
1955 | 0 | return false; |
1956 | 0 | } |
1957 | | |
1958 | 0 | if (!ica.Finalize()) { |
1959 | 0 | return false; |
1960 | 0 | } |
1961 | | |
1962 | | // Make sure there is a destination. |
1963 | 0 | if (ica.GetDestination().empty()) { |
1964 | | // A destination is required. |
1965 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
1966 | 0 | return false; |
1967 | 0 | } |
1968 | | |
1969 | | // Check the file name. |
1970 | 0 | std::string fname = filename; |
1971 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
1972 | 0 | status.SetError(cmStrCat(args[0], " given invalid export file name \"", |
1973 | 0 | fname, |
1974 | 0 | "\". The FILE argument may not contain a path. " |
1975 | 0 | "Specify the path in the DESTINATION argument.")); |
1976 | 0 | return false; |
1977 | 0 | } |
1978 | | |
1979 | | // Check the file extension. |
1980 | 0 | if (!fname.empty() && !cmHasSuffix(fname, ".mk"_s)) { |
1981 | 0 | status.SetError(cmStrCat( |
1982 | 0 | args[0], " given invalid export file name \"", fname, |
1983 | 0 | R"(". The FILE argument must specify a name ending in ".mk".)")); |
1984 | 0 | return false; |
1985 | 0 | } |
1986 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
1987 | 0 | status.SetError( |
1988 | 0 | cmStrCat(args[0], " given export name \"", exp, |
1989 | 0 | "\". " |
1990 | 0 | "This name cannot be safely converted to a file name. " |
1991 | 0 | "Specify a different export name or use the FILE option to set " |
1992 | 0 | "a file name explicitly.")); |
1993 | 0 | return false; |
1994 | 0 | } |
1995 | | // Use the default name |
1996 | 0 | if (fname.empty()) { |
1997 | 0 | fname = "Android.mk"; |
1998 | 0 | } |
1999 | |
|
2000 | 0 | cmExportSet& exportSet = |
2001 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp]; |
2002 | |
|
2003 | 0 | cmInstallGenerator::MessageLevel message = |
2004 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2005 | | |
2006 | | // Tell the global generator about any installation component names |
2007 | | // specified |
2008 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2009 | 0 | ica.GetComponent()); |
2010 | | |
2011 | | // Create the export install generator. |
2012 | 0 | helper.Makefile->AddInstallGenerator( |
2013 | 0 | cm::make_unique<cmInstallAndroidMKExportGenerator>( |
2014 | 0 | &exportSet, ica.GetDestination(), ica.GetPermissions(), |
2015 | 0 | ica.GetConfigurations(), ica.GetComponent(), message, |
2016 | 0 | ica.GetExcludeFromAll(), std::move(fname), std::move(name_space), |
2017 | 0 | helper.Makefile->GetBacktrace())); |
2018 | |
|
2019 | 0 | return true; |
2020 | | #else |
2021 | | static_cast<void>(args); |
2022 | | status.SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake"); |
2023 | | return false; |
2024 | | #endif |
2025 | 0 | } |
2026 | | |
2027 | | #ifndef CMAKE_BOOTSTRAP |
2028 | | cm::optional<cm::string_view> MatchExport(cm::string_view directive, |
2029 | | std::string const& exportName) |
2030 | 0 | { |
2031 | 0 | std::string::size_type const l = exportName.size(); |
2032 | 0 | if (directive.substr(0, l) == exportName) { |
2033 | 0 | if (directive.size() > l && directive[l] == ':') { |
2034 | 0 | return directive.substr(l + 1); |
2035 | 0 | } |
2036 | 0 | } |
2037 | 0 | return cm::nullopt; |
2038 | 0 | } |
2039 | | |
2040 | | void AssignValue(std::string& dest, std::string const& value) |
2041 | 0 | { |
2042 | 0 | dest = value; |
2043 | 0 | } |
2044 | | |
2045 | | void AssignValue(std::vector<std::string>& dest, std::string const& value) |
2046 | 0 | { |
2047 | 0 | dest = cmList{ value }.data(); |
2048 | 0 | } |
2049 | | |
2050 | | template <typename T> |
2051 | | void GetExportArgumentFromVariable(cmMakefile const* makefile, |
2052 | | cmExportSet const& exportSet, |
2053 | | cm::string_view suffix, T& variable) |
2054 | 0 | { |
2055 | 0 | std::string const& name = |
2056 | 0 | cmStrCat(exportSet.GetName(), "_EXPORT_PACKAGE_INFO_"_s, suffix); |
2057 | 0 | if (cmValue const& value = makefile->GetDefinition(name)) { |
2058 | 0 | std::string realValue; |
2059 | 0 | makefile->ConfigureString(value, realValue, true, false); |
2060 | 0 | AssignValue(variable, realValue); |
2061 | 0 | } |
2062 | 0 | } Unexecuted instantiation: cmInstallCommand.cxx:void (anonymous namespace)::GetExportArgumentFromVariable<ArgumentParser::NonEmpty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(cmMakefile const*, cmExportSet const&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, ArgumentParser::NonEmpty<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >&) Unexecuted instantiation: cmInstallCommand.cxx:void (anonymous namespace)::GetExportArgumentFromVariable<ArgumentParser::NonEmpty<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> > > > > >(cmMakefile const*, cmExportSet const&, std::__1::basic_string_view<char, std::__1::char_traits<char> >, ArgumentParser::NonEmpty<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> > > > >&) |
2063 | | |
2064 | | bool HandleMappedPackageInfo( |
2065 | | cmExportSet& exportSet, cm::string_view directive, Helper& helper, |
2066 | | cmInstallCommandArguments const& installCommandArgs, |
2067 | | cmExecutionStatus& status, cmInstallGenerator::MessageLevel message, |
2068 | | std::string const& cxxModulesDirectory) |
2069 | 0 | { |
2070 | 0 | cmPackageInfoArguments arguments; |
2071 | | |
2072 | | // Extract information from the directive. |
2073 | 0 | std::string::size_type const n = directive.find('/'); |
2074 | 0 | if (n != std::string::npos) { |
2075 | 0 | arguments.PackageName = std::string{ directive.substr(0, n) }; |
2076 | 0 | directive = directive.substr(n + 1); |
2077 | |
|
2078 | 0 | if (!directive.empty() && directive[0] == 'l') { |
2079 | 0 | arguments.LowerCase = true; |
2080 | 0 | directive = directive.substr(1); |
2081 | 0 | } |
2082 | |
|
2083 | 0 | if (!directive.empty() && directive[0] == 'a') { |
2084 | 0 | std::string::size_type const d = directive.find('/'); |
2085 | 0 | if (d != std::string::npos) { |
2086 | 0 | arguments.Appendix = std::string{ directive.substr(1, d - 1) }; |
2087 | 0 | directive = directive.substr(d); |
2088 | 0 | } else { |
2089 | 0 | arguments.Appendix = std::string{ directive.substr(1) }; |
2090 | 0 | directive = {}; |
2091 | 0 | } |
2092 | |
|
2093 | 0 | if (arguments.Appendix.empty()) { |
2094 | 0 | status.SetError(cmStrCat( |
2095 | 0 | "CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO given APPENDIX " |
2096 | 0 | R"(directive for export ")"_s, |
2097 | 0 | exportSet.GetName(), R"(", but no appendix name was provided.)"_s)); |
2098 | 0 | return false; |
2099 | 0 | } |
2100 | 0 | } |
2101 | | |
2102 | 0 | if (!directive.empty()) { |
2103 | 0 | if (directive[0] != '/') { |
2104 | 0 | status.SetError( |
2105 | 0 | cmStrCat("CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO given unrecognized " |
2106 | 0 | R"(directive ")"_s, |
2107 | 0 | directive, R"(".)"_s)); |
2108 | 0 | return false; |
2109 | 0 | } |
2110 | | |
2111 | 0 | directive = directive.substr(1); |
2112 | 0 | } |
2113 | 0 | } else { |
2114 | 0 | arguments.PackageName = std::string{ directive }; |
2115 | 0 | directive = {}; |
2116 | 0 | } |
2117 | | |
2118 | 0 | if (arguments.PackageName.empty()) { |
2119 | 0 | status.SetError( |
2120 | 0 | cmStrCat("CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO missing package name " |
2121 | 0 | R"(for export ")"_s, |
2122 | 0 | exportSet.GetName(), R"(".)"_s)); |
2123 | 0 | return false; |
2124 | 0 | } |
2125 | | |
2126 | | // Build destination. |
2127 | 0 | std::string dest = std::string{ directive }; |
2128 | 0 | if (dest.empty()) { |
2129 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") { |
2130 | 0 | dest = std::string{ "cps"_s }; |
2131 | 0 | } else { |
2132 | 0 | dest = cmStrCat(helper.GetLibraryDestination(nullptr), "/cps/", |
2133 | 0 | arguments.GetPackageDirName()); |
2134 | 0 | } |
2135 | 0 | } |
2136 | |
|
2137 | 0 | if (arguments.Appendix.empty()) { |
2138 | | // Get additional export information from variables. |
2139 | 0 | GetExportArgumentFromVariable( // BR |
2140 | 0 | helper.Makefile, exportSet, "VERSION"_s, arguments.Version); |
2141 | 0 | GetExportArgumentFromVariable( // BR |
2142 | 0 | helper.Makefile, exportSet, "COMPAT_VERSION"_s, arguments.VersionCompat); |
2143 | 0 | GetExportArgumentFromVariable( // BR |
2144 | 0 | helper.Makefile, exportSet, "VERSION_SCHEMA"_s, arguments.VersionSchema); |
2145 | 0 | GetExportArgumentFromVariable( // BR |
2146 | 0 | helper.Makefile, exportSet, "LICENSE"_s, arguments.License); |
2147 | 0 | GetExportArgumentFromVariable( // BR |
2148 | 0 | helper.Makefile, exportSet, "DEFAULT_LICENSE"_s, |
2149 | 0 | arguments.DefaultLicense); |
2150 | 0 | GetExportArgumentFromVariable( // BR |
2151 | 0 | helper.Makefile, exportSet, "DEFAULT_CONFIGURATIONS"_s, |
2152 | 0 | arguments.DefaultConfigs); |
2153 | 0 | } |
2154 | | |
2155 | | // Sanity-check export information. |
2156 | 0 | if (!arguments.Check(status)) { |
2157 | 0 | return false; |
2158 | 0 | } |
2159 | | |
2160 | | // Create the package info generator. |
2161 | 0 | helper.Makefile->AddInstallGenerator( |
2162 | 0 | cm::make_unique<cmInstallPackageInfoExportGenerator>( |
2163 | 0 | &exportSet, dest, installCommandArgs.GetPermissions(), |
2164 | 0 | installCommandArgs.GetConfigurations(), |
2165 | 0 | installCommandArgs.GetComponent(), message, |
2166 | 0 | installCommandArgs.GetExcludeFromAll(), std::move(arguments), |
2167 | 0 | cxxModulesDirectory, helper.Makefile->GetBacktrace())); |
2168 | |
|
2169 | 0 | return true; |
2170 | 0 | } |
2171 | | #endif |
2172 | | |
2173 | | bool HandleExportMode(std::vector<std::string> const& args, |
2174 | | cmExecutionStatus& status) |
2175 | 0 | { |
2176 | 0 | Helper helper(status); |
2177 | | |
2178 | | // This is the EXPORT mode. |
2179 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
2180 | |
|
2181 | 0 | std::string exp; |
2182 | 0 | std::string name_space; |
2183 | 0 | bool exportOld = false; |
2184 | 0 | std::string filename; |
2185 | 0 | std::string cxx_modules_directory; |
2186 | 0 | bool exportPackageDependencies = false; |
2187 | |
|
2188 | 0 | ica.Bind("EXPORT"_s, exp); |
2189 | 0 | ica.Bind("NAMESPACE"_s, name_space); |
2190 | 0 | ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld); |
2191 | 0 | ica.Bind("FILE"_s, filename); |
2192 | 0 | ica.Bind("CXX_MODULES_DIRECTORY"_s, cxx_modules_directory); |
2193 | |
|
2194 | 0 | if (cmExperimental::HasSupportEnabled( |
2195 | 0 | status.GetMakefile(), |
2196 | 0 | cmExperimental::Feature::ExportPackageDependencies)) { |
2197 | 0 | ica.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s, exportPackageDependencies); |
2198 | 0 | } |
2199 | |
|
2200 | 0 | std::vector<std::string> unknownArgs; |
2201 | 0 | ica.Parse(args, &unknownArgs); |
2202 | |
|
2203 | 0 | if (!unknownArgs.empty()) { |
2204 | | // Unknown argument. |
2205 | 0 | status.SetError( |
2206 | 0 | cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); |
2207 | 0 | return false; |
2208 | 0 | } |
2209 | | |
2210 | 0 | if (!ica.Finalize()) { |
2211 | 0 | return false; |
2212 | 0 | } |
2213 | | |
2214 | 0 | if (exp.empty()) { |
2215 | 0 | status.SetError(cmStrCat(args[0], " missing EXPORT.")); |
2216 | 0 | return false; |
2217 | 0 | } |
2218 | | |
2219 | | // Make sure there is a destination. |
2220 | 0 | if (ica.GetDestination().empty()) { |
2221 | | // A destination is required. |
2222 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
2223 | 0 | return false; |
2224 | 0 | } |
2225 | | |
2226 | | // Check the file name. |
2227 | 0 | std::string fname = filename; |
2228 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
2229 | 0 | status.SetError(cmStrCat(args[0], " given invalid export file name \"", |
2230 | 0 | fname, |
2231 | 0 | "\". " |
2232 | 0 | "The FILE argument may not contain a path. " |
2233 | 0 | "Specify the path in the DESTINATION argument.")); |
2234 | 0 | return false; |
2235 | 0 | } |
2236 | | |
2237 | | // Check the file extension. |
2238 | 0 | if (!fname.empty() && !cmHasSuffix(fname, ".cmake"_s)) { |
2239 | 0 | status.SetError( |
2240 | 0 | cmStrCat(args[0], " given invalid export file name \"", fname, |
2241 | 0 | "\". " |
2242 | 0 | "The FILE argument must specify a name ending in \".cmake\".")); |
2243 | 0 | return false; |
2244 | 0 | } |
2245 | | |
2246 | | // Construct the file name. |
2247 | 0 | if (fname.empty()) { |
2248 | 0 | fname = cmStrCat(exp, ".cmake"); |
2249 | |
|
2250 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
2251 | 0 | status.SetError(cmStrCat( |
2252 | 0 | args[0], " given export name \"", exp, |
2253 | 0 | "\". " |
2254 | 0 | "This name cannot be safely converted to a file name. " |
2255 | 0 | "Specify a different export name or use the FILE option to set " |
2256 | 0 | "a file name explicitly.")); |
2257 | 0 | return false; |
2258 | 0 | } |
2259 | 0 | } |
2260 | | |
2261 | 0 | cmExportSet& exportSet = |
2262 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp]; |
2263 | |
|
2264 | 0 | cmInstallGenerator::MessageLevel message = |
2265 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2266 | | |
2267 | | // Tell the global generator about any installation component names |
2268 | | // specified |
2269 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2270 | 0 | ica.GetComponent()); |
2271 | |
|
2272 | 0 | #ifndef CMAKE_BOOTSTRAP |
2273 | | // Check if PACKAGE_INFO export has been requested for this export set. |
2274 | 0 | if (cmExperimental::HasSupportEnabled( |
2275 | 0 | status.GetMakefile(), cmExperimental::Feature::MappedPackageInfo)) { |
2276 | 0 | if (cmValue const& piExports = helper.Makefile->GetDefinition( |
2277 | 0 | "CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO")) { |
2278 | 0 | for (auto const& pie : cmList{ piExports }) { |
2279 | 0 | cm::optional<cm::string_view> const directive = MatchExport(pie, exp); |
2280 | 0 | if (directive) { |
2281 | 0 | if (!HandleMappedPackageInfo(exportSet, *directive, helper, ica, |
2282 | 0 | status, message, |
2283 | 0 | cxx_modules_directory)) { |
2284 | 0 | return false; |
2285 | 0 | } |
2286 | 0 | } |
2287 | 0 | } |
2288 | 0 | } |
2289 | 0 | } |
2290 | 0 | #endif |
2291 | | |
2292 | | // Create the export install generator. |
2293 | 0 | helper.Makefile->AddInstallGenerator( |
2294 | 0 | cm::make_unique<cmInstallCMakeConfigExportGenerator>( |
2295 | 0 | &exportSet, ica.GetDestination(), ica.GetPermissions(), |
2296 | 0 | ica.GetConfigurations(), ica.GetComponent(), message, |
2297 | 0 | ica.GetExcludeFromAll(), std::move(fname), std::move(name_space), |
2298 | 0 | std::move(cxx_modules_directory), exportOld, exportPackageDependencies, |
2299 | 0 | helper.Makefile->GetBacktrace())); |
2300 | |
|
2301 | 0 | return true; |
2302 | 0 | } |
2303 | | |
2304 | | bool HandlePackageInfoMode(std::vector<std::string> const& args, |
2305 | | cmExecutionStatus& status) |
2306 | 0 | { |
2307 | 0 | #ifndef CMAKE_BOOTSTRAP |
2308 | 0 | Helper helper(status); |
2309 | | |
2310 | | // This is the PACKAGE_INFO mode. |
2311 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
2312 | |
|
2313 | 0 | cmPackageInfoArguments arguments; |
2314 | 0 | ArgumentParser::NonEmpty<std::string> exportName; |
2315 | 0 | ArgumentParser::NonEmpty<std::string> cxxModulesDirectory; |
2316 | |
|
2317 | 0 | arguments.Bind(ica); |
2318 | 0 | ica.Bind("EXPORT"_s, exportName); |
2319 | 0 | ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); |
2320 | |
|
2321 | 0 | std::vector<std::string> unknownArgs; |
2322 | 0 | ArgumentParser::ParseResult result = ica.Parse(args, &unknownArgs); |
2323 | |
|
2324 | 0 | if (!result.Check(args[0], &unknownArgs, status)) { |
2325 | 0 | return false; |
2326 | 0 | } |
2327 | | |
2328 | 0 | if (!ica.Finalize()) { |
2329 | 0 | return false; |
2330 | 0 | } |
2331 | | |
2332 | 0 | if (exportName.empty()) { |
2333 | 0 | status.SetError(cmStrCat(args[0], " missing EXPORT.")); |
2334 | 0 | return false; |
2335 | 0 | } |
2336 | | |
2337 | 0 | if (!arguments.Check(status) || !arguments.SetMetadataFromProject(status)) { |
2338 | 0 | return false; |
2339 | 0 | } |
2340 | | |
2341 | | // Get or construct the destination path. |
2342 | 0 | std::string dest = ica.GetDestination(); |
2343 | 0 | if (dest.empty()) { |
2344 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") { |
2345 | 0 | dest = std::string{ "cps"_s }; |
2346 | 0 | } else { |
2347 | 0 | dest = cmStrCat(helper.GetLibraryDestination(nullptr), "/cps/", |
2348 | 0 | arguments.GetPackageDirName()); |
2349 | 0 | } |
2350 | 0 | } |
2351 | |
|
2352 | 0 | cmExportSet& exportSet = |
2353 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName]; |
2354 | |
|
2355 | 0 | cmInstallGenerator::MessageLevel message = |
2356 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2357 | | |
2358 | | // Tell the global generator about any installation component names |
2359 | | // specified |
2360 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2361 | 0 | ica.GetComponent()); |
2362 | | |
2363 | | // Create the export install generator. |
2364 | 0 | helper.Makefile->AddInstallGenerator( |
2365 | 0 | cm::make_unique<cmInstallPackageInfoExportGenerator>( |
2366 | 0 | &exportSet, dest, ica.GetPermissions(), ica.GetConfigurations(), |
2367 | 0 | ica.GetComponent(), message, ica.GetExcludeFromAll(), |
2368 | 0 | std::move(arguments), std::move(cxxModulesDirectory), |
2369 | 0 | helper.Makefile->GetBacktrace())); |
2370 | |
|
2371 | 0 | return true; |
2372 | | #else |
2373 | | static_cast<void>(args); |
2374 | | status.SetError("PACKAGE_INFO not supported in bootstrap cmake"); |
2375 | | return false; |
2376 | | #endif |
2377 | 0 | } |
2378 | | |
2379 | | bool HandleRuntimeDependencySetMode(std::vector<std::string> const& args, |
2380 | | cmExecutionStatus& status) |
2381 | 0 | { |
2382 | 0 | Helper helper(status); |
2383 | |
|
2384 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
2385 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
2386 | 0 | system)) { |
2387 | 0 | status.SetError(cmStrCat( |
2388 | 0 | "RUNTIME_DEPENDENCY_SET is not supported on system \"", system, '"')); |
2389 | 0 | return false; |
2390 | 0 | } |
2391 | | |
2392 | | // This is the RUNTIME_DEPENDENCY_SET mode. |
2393 | 0 | cmInstallRuntimeDependencySet* runtimeDependencySet; |
2394 | |
|
2395 | 0 | struct ArgVectors |
2396 | 0 | { |
2397 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Library; |
2398 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime; |
2399 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework; |
2400 | 0 | }; |
2401 | |
|
2402 | 0 | static auto const argHelper = cmArgumentParser<ArgVectors>{} |
2403 | 0 | .Bind("LIBRARY"_s, &ArgVectors::Library) |
2404 | 0 | .Bind("RUNTIME"_s, &ArgVectors::Runtime) |
2405 | 0 | .Bind("FRAMEWORK"_s, &ArgVectors::Framework); |
2406 | |
|
2407 | 0 | std::vector<std::string> genericArgVector; |
2408 | 0 | ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); |
2409 | | |
2410 | | // now parse the generic args (i.e. the ones not specialized on LIBRARY, |
2411 | | // RUNTIME, FRAMEWORK etc. (see above) |
2412 | | // These generic args also contain the runtime dependency set |
2413 | 0 | std::string runtimeDependencySetArg; |
2414 | 0 | std::vector<std::string> runtimeDependencyArgVector; |
2415 | 0 | cmInstallCommandArguments genericArgs(helper.DefaultComponentName, |
2416 | 0 | *helper.Makefile); |
2417 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg); |
2418 | 0 | genericArgs.Parse(genericArgVector, &runtimeDependencyArgVector); |
2419 | 0 | bool success = genericArgs.Finalize(); |
2420 | |
|
2421 | 0 | cmInstallCommandArguments libraryArgs(helper.DefaultComponentName, |
2422 | 0 | *helper.Makefile); |
2423 | 0 | cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName, |
2424 | 0 | *helper.Makefile); |
2425 | 0 | cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName, |
2426 | 0 | *helper.Makefile); |
2427 | | |
2428 | | // Now also parse the file(GET_RUNTIME_DEPENDENCY) args |
2429 | 0 | std::vector<std::string> unknownArgs; |
2430 | 0 | auto runtimeDependencyArgs = RuntimeDependenciesArgHelper.Parse( |
2431 | 0 | runtimeDependencyArgVector, &unknownArgs); |
2432 | | |
2433 | | // now parse the args for specific parts of the target (e.g. LIBRARY, |
2434 | | // RUNTIME, FRAMEWORK etc. |
2435 | 0 | libraryArgs.Parse(argVectors.Library, &unknownArgs); |
2436 | 0 | runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); |
2437 | 0 | frameworkArgs.Parse(argVectors.Framework, &unknownArgs); |
2438 | |
|
2439 | 0 | libraryArgs.SetGenericArguments(&genericArgs); |
2440 | 0 | runtimeArgs.SetGenericArguments(&genericArgs); |
2441 | 0 | frameworkArgs.SetGenericArguments(&genericArgs); |
2442 | |
|
2443 | 0 | success = success && libraryArgs.Finalize(); |
2444 | 0 | success = success && runtimeArgs.Finalize(); |
2445 | 0 | success = success && frameworkArgs.Finalize(); |
2446 | |
|
2447 | 0 | if (!success) { |
2448 | 0 | return false; |
2449 | 0 | } |
2450 | | |
2451 | 0 | if (!unknownArgs.empty()) { |
2452 | 0 | helper.SetError( |
2453 | 0 | cmStrCat("RUNTIME_DEPENDENCY_SET given unknown argument \"", |
2454 | 0 | unknownArgs.front(), "\".")); |
2455 | 0 | return false; |
2456 | 0 | } |
2457 | | |
2458 | 0 | if (runtimeDependencySetArg.empty()) { |
2459 | 0 | helper.SetError( |
2460 | 0 | "RUNTIME_DEPENDENCY_SET not given a runtime dependency set."); |
2461 | 0 | return false; |
2462 | 0 | } |
2463 | | |
2464 | 0 | runtimeDependencySet = |
2465 | 0 | helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet( |
2466 | 0 | runtimeDependencySetArg); |
2467 | |
|
2468 | 0 | bool installsRuntime = false; |
2469 | 0 | bool installsLibrary = false; |
2470 | 0 | bool installsFramework = false; |
2471 | |
|
2472 | 0 | AddInstallRuntimeDependenciesGenerator( |
2473 | 0 | helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs, |
2474 | 0 | std::move(runtimeDependencyArgs), installsRuntime, installsLibrary, |
2475 | 0 | installsFramework); |
2476 | | |
2477 | | // Tell the global generator about any installation component names |
2478 | | // specified |
2479 | 0 | if (installsLibrary) { |
2480 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2481 | 0 | libraryArgs.GetComponent()); |
2482 | 0 | } |
2483 | 0 | if (installsRuntime) { |
2484 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2485 | 0 | runtimeArgs.GetComponent()); |
2486 | 0 | } |
2487 | 0 | if (installsFramework) { |
2488 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2489 | 0 | frameworkArgs.GetComponent()); |
2490 | 0 | } |
2491 | |
|
2492 | 0 | return true; |
2493 | 0 | } |
2494 | | |
2495 | | bool HandleSbomMode(std::vector<std::string> const& args, |
2496 | | cmExecutionStatus& status) |
2497 | 0 | { |
2498 | 0 | #ifndef CMAKE_BOOTSTRAP |
2499 | 0 | if (!cmExperimental::HasSupportEnabled( |
2500 | 0 | status.GetMakefile(), cmExperimental::Feature::GenerateSbom)) { |
2501 | 0 | status.SetError("does not recognize sub-command SBOM"); |
2502 | 0 | return false; |
2503 | 0 | } |
2504 | | |
2505 | 0 | Helper helper(status); |
2506 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
2507 | |
|
2508 | 0 | cmSbomArguments arguments; |
2509 | 0 | ArgumentParser::NonEmpty<std::string> exportName; |
2510 | 0 | ArgumentParser::NonEmpty<std::string> cxxModulesDirectory; |
2511 | |
|
2512 | 0 | arguments.Bind(ica); |
2513 | 0 | ica.Bind("EXPORT"_s, exportName); |
2514 | | // ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); TODO? |
2515 | |
|
2516 | 0 | std::vector<std::string> unknownArgs; |
2517 | 0 | ica.Parse(args, &unknownArgs); |
2518 | |
|
2519 | 0 | ArgumentParser::ParseResult result = ica.Parse(args, &unknownArgs); |
2520 | 0 | if (!result.Check(args[0], &unknownArgs, status)) { |
2521 | 0 | return false; |
2522 | 0 | } |
2523 | | |
2524 | 0 | if (!ica.Finalize()) { |
2525 | 0 | return false; |
2526 | 0 | } |
2527 | | |
2528 | 0 | if (arguments.PackageName.empty()) { |
2529 | | // TODO: Fix our use of the parser to enforce this. |
2530 | 0 | status.SetError(cmStrCat(args[0], " missing SBOM name.")); |
2531 | 0 | return false; |
2532 | 0 | } |
2533 | | |
2534 | 0 | if (exportName.empty()) { |
2535 | 0 | status.SetError(cmStrCat(args[0], " missing EXPORT.")); |
2536 | 0 | return false; |
2537 | 0 | } |
2538 | | |
2539 | 0 | if (!arguments.Check(status) || !arguments.SetMetadataFromProject(status)) { |
2540 | 0 | return false; |
2541 | 0 | } |
2542 | | |
2543 | | // Get or construct the destination path. |
2544 | 0 | std::string dest = ica.GetDestination(); |
2545 | 0 | if (dest.empty()) { |
2546 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") { |
2547 | 0 | dest = std::string{ "/sbom/"_s }; |
2548 | 0 | } else { |
2549 | 0 | dest = cmStrCat(helper.GetLibraryDestination(nullptr), "/sbom/", |
2550 | 0 | arguments.GetPackageDirName()); |
2551 | 0 | } |
2552 | 0 | } |
2553 | |
|
2554 | 0 | cmExportSet& exportSet = |
2555 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName]; |
2556 | |
|
2557 | 0 | cmInstallGenerator::MessageLevel message = |
2558 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2559 | | |
2560 | | // Tell the global generator about any installation component names |
2561 | | // specified |
2562 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2563 | 0 | ica.GetComponent()); |
2564 | 0 | helper.Makefile->SetExplicitlyGeneratesSbom(true); |
2565 | | |
2566 | | // Create the export install generator. |
2567 | 0 | helper.Makefile->AddInstallGenerator( |
2568 | 0 | cm::make_unique<cmInstallSbomExportGenerator>( |
2569 | 0 | &exportSet, dest, ica.GetPermissions(), ica.GetConfigurations(), |
2570 | 0 | ica.GetComponent(), message, ica.GetExcludeFromAll(), |
2571 | 0 | std::move(arguments), std::move(cxxModulesDirectory), |
2572 | 0 | helper.Makefile->GetBacktrace())); |
2573 | |
|
2574 | 0 | return true; |
2575 | | #else |
2576 | | static_cast<void>(args); |
2577 | | status.SetError("SBOM not supported in bootstrap cmake"); |
2578 | | return false; |
2579 | | #endif |
2580 | 0 | } |
2581 | | |
2582 | | bool Helper::MakeFilesFullPath(char const* modeName, |
2583 | | std::vector<std::string> const& relFiles, |
2584 | | std::vector<std::string>& absFiles) |
2585 | 0 | { |
2586 | 0 | return this->MakeFilesFullPath( |
2587 | 0 | modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles); |
2588 | 0 | } |
2589 | | |
2590 | | bool Helper::MakeFilesFullPath(char const* modeName, |
2591 | | std::string const& basePath, |
2592 | | std::vector<std::string> const& relFiles, |
2593 | | std::vector<std::string>& absFiles) |
2594 | 0 | { |
2595 | 0 | for (std::string const& relFile : relFiles) { |
2596 | 0 | std::string file = relFile; |
2597 | 0 | std::string::size_type gpos = cmGeneratorExpression::Find(file); |
2598 | 0 | if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) { |
2599 | 0 | file = cmStrCat(basePath, '/', relFile); |
2600 | 0 | } |
2601 | | |
2602 | | // Make sure the file is not a directory. |
2603 | 0 | if (gpos == std::string::npos && !cmSystemTools::FileIsSymlink(file) && |
2604 | 0 | cmSystemTools::FileIsDirectory(file)) { |
2605 | 0 | this->SetError( |
2606 | 0 | cmStrCat(modeName, " given directory \"", relFile, "\" to install.")); |
2607 | 0 | return false; |
2608 | 0 | } |
2609 | | // Store the file for installation. |
2610 | 0 | absFiles.push_back(std::move(file)); |
2611 | 0 | } |
2612 | 0 | return true; |
2613 | 0 | } |
2614 | | |
2615 | | std::string Helper::GetRuntimeDestination( |
2616 | | cmInstallCommandArguments const* args) const |
2617 | 0 | { |
2618 | 0 | if (args && !args->GetDestination().empty()) { |
2619 | 0 | return args->GetDestination(); |
2620 | 0 | } |
2621 | 0 | return cm::InstallDirs::GetRuntimeDirectory(this->Makefile); |
2622 | 0 | } |
2623 | | |
2624 | | std::string Helper::GetArchiveDestination( |
2625 | | cmInstallCommandArguments const* args) const |
2626 | 0 | { |
2627 | 0 | if (args && !args->GetDestination().empty()) { |
2628 | 0 | return args->GetDestination(); |
2629 | 0 | } |
2630 | 0 | return cm::InstallDirs::GetArchiveDirectory(this->Makefile); |
2631 | 0 | } |
2632 | | |
2633 | | std::string Helper::GetLibraryDestination( |
2634 | | cmInstallCommandArguments const* args) const |
2635 | 0 | { |
2636 | 0 | if (args && !args->GetDestination().empty()) { |
2637 | 0 | return args->GetDestination(); |
2638 | 0 | } |
2639 | 0 | return cm::InstallDirs::GetLibraryDirectory(this->Makefile); |
2640 | 0 | } |
2641 | | |
2642 | | std::string Helper::GetCxxModulesBmiDestination( |
2643 | | cmInstallCommandArguments const* args) const |
2644 | 0 | { |
2645 | 0 | if (args) { |
2646 | 0 | return args->GetDestination(); |
2647 | 0 | } |
2648 | 0 | return {}; |
2649 | 0 | } |
2650 | | |
2651 | | std::string Helper::GetIncludeDestination( |
2652 | | cmInstallCommandArguments const* args) const |
2653 | 0 | { |
2654 | 0 | if (args && !args->GetDestination().empty()) { |
2655 | 0 | return args->GetDestination(); |
2656 | 0 | } |
2657 | 0 | return cm::InstallDirs::GetIncludeDirectory(this->Makefile); |
2658 | 0 | } |
2659 | | |
2660 | | std::string Helper::GetDestinationForType( |
2661 | | cmInstallCommandArguments const* args, std::string const& type) const |
2662 | 0 | { |
2663 | 0 | if (args && !args->GetDestination().empty()) { |
2664 | 0 | return args->GetDestination(); |
2665 | 0 | } |
2666 | 0 | return cm::InstallDirs::GetDirectoryForType(this->Makefile, type); |
2667 | 0 | } |
2668 | | |
2669 | | } // namespace |
2670 | | |
2671 | | bool cmInstallCommand(std::vector<std::string> const& args, |
2672 | | cmExecutionStatus& status) |
2673 | 0 | { |
2674 | | // Allow calling with no arguments so that arguments may be built up |
2675 | | // using a variable that may be left empty. |
2676 | 0 | if (args.empty()) { |
2677 | 0 | return true; |
2678 | 0 | } |
2679 | | |
2680 | | // Enable the install target. |
2681 | 0 | status.GetMakefile().GetGlobalGenerator()->EnableInstallTarget(); |
2682 | |
|
2683 | 0 | static cmSubcommandTable const subcommand{ |
2684 | 0 | { "SCRIPT"_s, HandleScriptMode }, |
2685 | 0 | { "CODE"_s, HandleScriptMode }, |
2686 | 0 | { "TARGETS"_s, HandleTargetsMode }, |
2687 | 0 | { "IMPORTED_RUNTIME_ARTIFACTS"_s, HandleImportedRuntimeArtifactsMode }, |
2688 | 0 | { "FILES"_s, HandleFilesMode }, |
2689 | 0 | { "PROGRAMS"_s, HandleFilesMode }, |
2690 | 0 | { "DIRECTORY"_s, HandleDirectoryMode }, |
2691 | 0 | { "EXPORT"_s, HandleExportMode }, |
2692 | 0 | { "EXPORT_ANDROID_MK"_s, HandleExportAndroidMKMode }, |
2693 | 0 | { "PACKAGE_INFO"_s, HandlePackageInfoMode }, |
2694 | 0 | { "RUNTIME_DEPENDENCY_SET"_s, HandleRuntimeDependencySetMode }, |
2695 | 0 | { "SBOM"_s, HandleSbomMode } |
2696 | 0 | }; |
2697 | |
|
2698 | 0 | return subcommand(args[0], args, status); |
2699 | 0 | } |