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