/src/CMake/Source/cmInstallCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmInstallCommand.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <cassert> |
7 | | #include <cstddef> |
8 | | #include <iterator> |
9 | | #include <map> |
10 | | #include <set> |
11 | | #include <utility> |
12 | | |
13 | | #include <cm/memory> |
14 | | #include <cm/optional> |
15 | | #include <cm/string_view> |
16 | | #include <cmext/string_view> |
17 | | |
18 | | #include "cmsys/Glob.hxx" |
19 | | |
20 | | #include "cmArgumentParser.h" |
21 | | #include "cmArgumentParserTypes.h" |
22 | | #include "cmCMakePath.h" |
23 | | #include "cmDiagnosticContext.h" |
24 | | #include "cmDiagnostics.h" |
25 | | #include "cmExecutionStatus.h" |
26 | | #include "cmExperimental.h" |
27 | | #include "cmExportSet.h" |
28 | | #include "cmGeneratorExpression.h" |
29 | | #include "cmGlobalGenerator.h" |
30 | | #include "cmInstallAndroidMKExportGenerator.h" |
31 | | #include "cmInstallCMakeConfigExportGenerator.h" |
32 | | #include "cmInstallCommandArguments.h" |
33 | | #include "cmInstallCxxModuleBmiGenerator.h" |
34 | | #include "cmInstallDirectoryGenerator.h" |
35 | | #include "cmInstallDirs.h" |
36 | | #include "cmInstallFileSetGenerator.h" |
37 | | #include "cmInstallFilesGenerator.h" |
38 | | #include "cmInstallGenerator.h" |
39 | | #include "cmInstallGetRuntimeDependenciesGenerator.h" |
40 | | #include "cmInstallImportedRuntimeArtifactsGenerator.h" |
41 | | #include "cmInstallPackageInfoExportGenerator.h" |
42 | | #include "cmInstallRuntimeDependencySet.h" |
43 | | #include "cmInstallRuntimeDependencySetGenerator.h" |
44 | | #include "cmInstallSbomGenerator.h" |
45 | | #include "cmInstallScriptGenerator.h" |
46 | | #include "cmInstallTargetGenerator.h" |
47 | | #include "cmList.h" |
48 | | #include "cmMakefile.h" |
49 | | #include "cmMessageType.h" |
50 | | #include "cmPackageInfoArguments.h" |
51 | | #include "cmPolicies.h" |
52 | | #include "cmRange.h" |
53 | | #include "cmRuntimeDependencyArchive.h" |
54 | | #include "cmSbomArguments.h" |
55 | | #include "cmStateTypes.h" |
56 | | #include "cmStringAlgorithms.h" |
57 | | #include "cmSubcommandTable.h" |
58 | | #include "cmSystemTools.h" |
59 | | #include "cmTarget.h" |
60 | | #include "cmTargetExport.h" |
61 | | #include "cmValue.h" |
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 == "<PROJECT_NAME>") { |
98 | 0 | cmValue projectName = this->Makefile->GetDefinition("PROJECT_NAME"); |
99 | 0 | if (!projectName->empty()) { |
100 | 0 | this->DefaultComponentName = projectName; |
101 | 0 | } else { |
102 | 0 | this->DefaultComponentName = "Unspecified"; |
103 | 0 | } |
104 | 0 | } |
105 | 0 | if (this->DefaultComponentName.empty()) { |
106 | 0 | this->DefaultComponentName = "Unspecified"; |
107 | 0 | } |
108 | 0 | } |
109 | | |
110 | | cmDiagnosticContext CaptureContext() const |
111 | 0 | { |
112 | 0 | return cmInstallGenerator::CaptureContext(this->Makefile); |
113 | 0 | } |
114 | | |
115 | 0 | void SetError(std::string const& err) { this->Status.SetError(err); } |
116 | | |
117 | | bool MakeFilesFullPath(char const* modeName, |
118 | | std::vector<std::string> const& relFiles, |
119 | | std::vector<std::string>& absFiles); |
120 | | bool MakeFilesFullPath(char const* modeName, std::string const& basePath, |
121 | | std::vector<std::string> const& relFiles, |
122 | | std::vector<std::string>& absFiles); |
123 | | |
124 | | std::string GetRuntimeDestination( |
125 | | cmInstallCommandArguments const* args) const; |
126 | | std::string GetArchiveDestination( |
127 | | cmInstallCommandArguments const* args) const; |
128 | | std::string GetLibraryDestination( |
129 | | cmInstallCommandArguments const* args) const; |
130 | | std::string GetCxxModulesBmiDestination( |
131 | | cmInstallCommandArguments const* args) const; |
132 | | std::string GetIncludeDestination( |
133 | | cmInstallCommandArguments const* args) const; |
134 | | std::string GetDestinationForType(cmInstallCommandArguments const* args, |
135 | | std::string const& type) const; |
136 | | |
137 | | cmExecutionStatus& Status; |
138 | | cmMakefile* Makefile; |
139 | | std::string DefaultComponentName; |
140 | | }; |
141 | | |
142 | | std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( |
143 | | cmTarget& target, cmInstallCommandArguments const& args, bool impLib, |
144 | | cmDiagnosticContext context, std::string const& destination, |
145 | | bool forceOpt = false, bool namelink = false) |
146 | 0 | { |
147 | 0 | cmInstallGenerator::MessageLevel message = |
148 | 0 | cmInstallGenerator::SelectMessageLevel(target.GetMakefile()); |
149 | 0 | target.SetHaveInstallRule(true); |
150 | 0 | std::string const& component = |
151 | 0 | namelink ? args.GetNamelinkComponent() : args.GetComponent(); |
152 | 0 | auto g = cm::make_unique<cmInstallTargetGenerator>( |
153 | 0 | target.GetName(), destination, impLib, args.GetPermissions(), |
154 | 0 | args.GetConfigurations(), component, message, args.GetExcludeFromAll(), |
155 | 0 | args.GetOptional() || forceOpt, std::move(context)); |
156 | 0 | target.AddInstallGenerator(g.get()); |
157 | 0 | return g; |
158 | 0 | } |
159 | | |
160 | | std::unique_ptr<cmInstallTargetGenerator> CreateInstallTargetGenerator( |
161 | | cmTarget& target, cmInstallCommandArguments const& args, bool impLib, |
162 | | cmDiagnosticContext context, bool forceOpt = false, bool namelink = false) |
163 | 0 | { |
164 | 0 | return CreateInstallTargetGenerator(target, args, impLib, std::move(context), |
165 | 0 | args.GetDestination(), forceOpt, |
166 | 0 | namelink); |
167 | 0 | } |
168 | | |
169 | | std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( |
170 | | cmMakefile* mf, std::vector<std::string> const& absFiles, |
171 | | cmInstallCommandArguments const& args, bool programs, |
172 | | std::string const& destination) |
173 | 0 | { |
174 | 0 | cmInstallGenerator::MessageLevel message = |
175 | 0 | cmInstallGenerator::SelectMessageLevel(mf); |
176 | 0 | return cm::make_unique<cmInstallFilesGenerator>( |
177 | 0 | absFiles, destination, programs, args.GetPermissions(), |
178 | 0 | args.GetConfigurations(), args.GetComponent(), message, |
179 | 0 | args.GetExcludeFromAll(), args.GetRename(), args.GetOptional(), |
180 | 0 | cmInstallGenerator::CaptureContext(mf)); |
181 | 0 | } |
182 | | |
183 | | std::unique_ptr<cmInstallFilesGenerator> CreateInstallFilesGenerator( |
184 | | cmMakefile* mf, std::vector<std::string> const& absFiles, |
185 | | cmInstallCommandArguments const& args, bool programs) |
186 | 0 | { |
187 | 0 | return CreateInstallFilesGenerator(mf, absFiles, args, programs, |
188 | 0 | args.GetDestination()); |
189 | 0 | } |
190 | | |
191 | | std::unique_ptr<cmInstallFileSetGenerator> CreateInstallFileSetGenerator( |
192 | | Helper& helper, cmTarget& target, |
193 | | cmInstallCommandFileSetArguments const& args) |
194 | 0 | { |
195 | 0 | cmInstallGenerator::MessageLevel message = |
196 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
197 | 0 | return cm::make_unique<cmInstallFileSetGenerator>( |
198 | 0 | target.GetName(), args.GetFileSet(), args.GetDestination(), |
199 | 0 | args.GetPermissions(), args.GetConfigurations(), args.GetComponent(), |
200 | 0 | message, args.GetExcludeFromAll(), args.GetOptional(), |
201 | 0 | helper.CaptureContext()); |
202 | 0 | } |
203 | | |
204 | | void AddInstallRuntimeDependenciesGenerator( |
205 | | Helper& helper, cmInstallRuntimeDependencySet* runtimeDependencySet, |
206 | | cmInstallCommandArguments const& runtimeArgs, |
207 | | cmInstallCommandArguments const& libraryArgs, |
208 | | cmInstallCommandArguments const& frameworkArgs, |
209 | | RuntimeDependenciesArgs runtimeDependenciesArgs, bool& installsRuntime, |
210 | | bool& installsLibrary, bool& installsFramework) |
211 | 0 | { |
212 | 0 | bool dllPlatform = |
213 | 0 | !helper.Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty(); |
214 | 0 | bool apple = |
215 | 0 | helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") == "Darwin"; |
216 | 0 | auto const& runtimeDependenciesArgsRef = |
217 | 0 | dllPlatform ? runtimeArgs : libraryArgs; |
218 | 0 | std::vector<std::string> configurations = |
219 | 0 | runtimeDependenciesArgsRef.GetConfigurations(); |
220 | 0 | if (apple) { |
221 | 0 | std::copy(frameworkArgs.GetConfigurations().begin(), |
222 | 0 | frameworkArgs.GetConfigurations().end(), |
223 | 0 | std::back_inserter(configurations)); |
224 | 0 | } |
225 | | |
226 | | // Create file(GET_RUNTIME_DEPENDENCIES) generator. |
227 | 0 | auto getRuntimeDependenciesGenerator = |
228 | 0 | cm::make_unique<cmInstallGetRuntimeDependenciesGenerator>( |
229 | 0 | runtimeDependencySet, std::move(runtimeDependenciesArgs.Directories), |
230 | 0 | std::move(runtimeDependenciesArgs.PreIncludeRegexes), |
231 | 0 | std::move(runtimeDependenciesArgs.PreExcludeRegexes), |
232 | 0 | std::move(runtimeDependenciesArgs.PostIncludeRegexes), |
233 | 0 | std::move(runtimeDependenciesArgs.PostExcludeRegexes), |
234 | 0 | std::move(runtimeDependenciesArgs.PostIncludeFiles), |
235 | 0 | std::move(runtimeDependenciesArgs.PostExcludeFiles), |
236 | 0 | runtimeDependenciesArgsRef.GetComponent(), |
237 | 0 | apple ? frameworkArgs.GetComponent() : "", true, "_CMAKE_DEPS", |
238 | 0 | "_CMAKE_RPATH", configurations, |
239 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
240 | 0 | runtimeDependenciesArgsRef.GetExcludeFromAll() && |
241 | 0 | (apple ? frameworkArgs.GetExcludeFromAll() : true), |
242 | 0 | helper.Makefile->GetBacktrace(), |
243 | 0 | helper.Makefile->GetPolicyStatus(cmPolicies::CMP0207)); |
244 | 0 | helper.Makefile->AddInstallGenerator( |
245 | 0 | std::move(getRuntimeDependenciesGenerator)); |
246 | | |
247 | | // Create the library dependencies generator. |
248 | 0 | auto libraryRuntimeDependenciesGenerator = |
249 | 0 | cm::make_unique<cmInstallRuntimeDependencySetGenerator>( |
250 | 0 | cmInstallRuntimeDependencySetGenerator::DependencyType::Library, |
251 | 0 | runtimeDependencySet, std::vector<std::string>{}, true, std::string{}, |
252 | 0 | true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP", |
253 | 0 | dllPlatform ? helper.GetRuntimeDestination(&runtimeArgs) |
254 | 0 | : helper.GetLibraryDestination(&libraryArgs), |
255 | 0 | runtimeDependenciesArgsRef.GetConfigurations(), |
256 | 0 | runtimeDependenciesArgsRef.GetComponent(), |
257 | 0 | runtimeDependenciesArgsRef.GetPermissions(), |
258 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
259 | 0 | runtimeDependenciesArgsRef.GetExcludeFromAll(), helper.CaptureContext()); |
260 | 0 | helper.Makefile->AddInstallGenerator( |
261 | 0 | std::move(libraryRuntimeDependenciesGenerator)); |
262 | 0 | if (dllPlatform) { |
263 | 0 | installsRuntime = true; |
264 | 0 | } else { |
265 | 0 | installsLibrary = true; |
266 | 0 | } |
267 | |
|
268 | 0 | if (apple) { |
269 | | // Create the framework dependencies generator. |
270 | 0 | auto frameworkRuntimeDependenciesGenerator = |
271 | 0 | cm::make_unique<cmInstallRuntimeDependencySetGenerator>( |
272 | 0 | cmInstallRuntimeDependencySetGenerator::DependencyType::Framework, |
273 | 0 | runtimeDependencySet, std::vector<std::string>{}, true, std::string{}, |
274 | 0 | true, "_CMAKE_DEPS", "_CMAKE_RPATH", "_CMAKE_TMP", |
275 | 0 | frameworkArgs.GetDestination(), frameworkArgs.GetConfigurations(), |
276 | 0 | frameworkArgs.GetComponent(), frameworkArgs.GetPermissions(), |
277 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile), |
278 | 0 | frameworkArgs.GetExcludeFromAll(), helper.CaptureContext()); |
279 | 0 | helper.Makefile->AddInstallGenerator( |
280 | 0 | std::move(frameworkRuntimeDependenciesGenerator)); |
281 | 0 | installsFramework = true; |
282 | 0 | } |
283 | 0 | } |
284 | | |
285 | | std::set<std::string> const allowedTypes{ |
286 | | "BIN", "SBIN", "LIB", "INCLUDE", "SYSCONF", |
287 | | "SHAREDSTATE", "LOCALSTATE", "RUNSTATE", "DATA", "INFO", |
288 | | "LOCALE", "MAN", "DOC", "LIBEXEC", |
289 | | }; |
290 | | |
291 | | template <typename T> |
292 | | bool AddBundleExecutable(Helper& helper, |
293 | | cmInstallRuntimeDependencySet* runtimeDependencySet, |
294 | | T&& bundleExecutable) |
295 | 0 | { |
296 | 0 | if (!runtimeDependencySet->AddBundleExecutable(bundleExecutable)) { |
297 | 0 | helper.SetError( |
298 | 0 | "A runtime dependency set may only have one bundle executable."); |
299 | 0 | return false; |
300 | 0 | } |
301 | 0 | return true; |
302 | 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*&&) |
303 | | |
304 | | void CheckAbsoluteDestination(Helper& helper, std::string const& destination) |
305 | 0 | { |
306 | | // Check for an absolute destination. |
307 | 0 | if (cmGeneratorExpression::Find(destination) == std::string::npos && |
308 | 0 | cmSystemTools::FileIsFullPath(destination)) { |
309 | 0 | helper.Makefile->IssueDiagnostic( |
310 | 0 | cmDiagnostics::CMD_INSTALL_ABSOLUTE_DESTINATION, |
311 | 0 | cmStrCat("INSTALL command given absolute DESTINATION path:\n ", |
312 | 0 | destination)); |
313 | 0 | } |
314 | 0 | } |
315 | | |
316 | | bool HandleScriptMode(std::vector<std::string> const& args, |
317 | | cmExecutionStatus& status) |
318 | 0 | { |
319 | 0 | Helper helper(status); |
320 | |
|
321 | 0 | std::string component = helper.DefaultComponentName; |
322 | 0 | int componentCount = 0; |
323 | 0 | bool doingScript = false; |
324 | 0 | bool doingCode = false; |
325 | 0 | bool excludeFromAll = false; |
326 | 0 | bool allComponents = false; |
327 | | |
328 | | // Scan the args once for COMPONENT. Only allow one. |
329 | | // |
330 | 0 | for (size_t i = 0; i < args.size(); ++i) { |
331 | 0 | if (args[i] == "COMPONENT" && i + 1 < args.size()) { |
332 | 0 | ++componentCount; |
333 | 0 | ++i; |
334 | 0 | component = args[i]; |
335 | 0 | } |
336 | 0 | if (args[i] == "EXCLUDE_FROM_ALL") { |
337 | 0 | excludeFromAll = true; |
338 | 0 | } else if (args[i] == "ALL_COMPONENTS") { |
339 | 0 | allComponents = true; |
340 | 0 | } |
341 | 0 | } |
342 | |
|
343 | 0 | if (componentCount > 1) { |
344 | 0 | status.SetError("given more than one COMPONENT for the SCRIPT or CODE " |
345 | 0 | "signature of the INSTALL command. " |
346 | 0 | "Use multiple INSTALL commands with one COMPONENT each."); |
347 | 0 | return false; |
348 | 0 | } |
349 | | |
350 | 0 | if (allComponents && componentCount == 1) { |
351 | 0 | status.SetError("ALL_COMPONENTS and COMPONENT are mutually exclusive"); |
352 | 0 | return false; |
353 | 0 | } |
354 | | |
355 | | // Scan the args again, this time adding install generators each time we |
356 | | // encounter a SCRIPT or CODE arg: |
357 | | // |
358 | 0 | for (std::string const& arg : args) { |
359 | 0 | if (arg == "SCRIPT") { |
360 | 0 | doingScript = true; |
361 | 0 | doingCode = false; |
362 | 0 | } else if (arg == "CODE") { |
363 | 0 | doingScript = false; |
364 | 0 | doingCode = true; |
365 | 0 | } else if (arg == "COMPONENT") { |
366 | 0 | doingScript = false; |
367 | 0 | doingCode = false; |
368 | 0 | } else if (doingScript) { |
369 | 0 | doingScript = false; |
370 | 0 | std::string script = arg; |
371 | 0 | if (!cmHasLiteralPrefix(script, "$<INSTALL_PREFIX>")) { |
372 | 0 | if (!cmSystemTools::FileIsFullPath(script)) { |
373 | 0 | script = |
374 | 0 | cmStrCat(helper.Makefile->GetCurrentSourceDirectory(), '/', arg); |
375 | 0 | } |
376 | 0 | if (cmSystemTools::FileIsDirectory(script)) { |
377 | 0 | status.SetError("given a directory as value of SCRIPT argument."); |
378 | 0 | return false; |
379 | 0 | } |
380 | 0 | } |
381 | 0 | helper.Makefile->AddInstallGenerator( |
382 | 0 | cm::make_unique<cmInstallScriptGenerator>( |
383 | 0 | script, false, component, excludeFromAll, allComponents, |
384 | 0 | helper.Makefile->GetBacktrace())); |
385 | 0 | } else if (doingCode) { |
386 | 0 | doingCode = false; |
387 | 0 | std::string const& code = arg; |
388 | 0 | helper.Makefile->AddInstallGenerator( |
389 | 0 | cm::make_unique<cmInstallScriptGenerator>( |
390 | 0 | code, true, component, excludeFromAll, allComponents, |
391 | 0 | helper.Makefile->GetBacktrace())); |
392 | 0 | } |
393 | 0 | } |
394 | | |
395 | 0 | if (doingScript) { |
396 | 0 | status.SetError("given no value for SCRIPT argument."); |
397 | 0 | return false; |
398 | 0 | } |
399 | 0 | if (doingCode) { |
400 | 0 | status.SetError("given no value for CODE argument."); |
401 | 0 | return false; |
402 | 0 | } |
403 | | |
404 | | // Tell the global generator about any installation component names |
405 | | // specified. |
406 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent(component); |
407 | |
|
408 | 0 | return true; |
409 | 0 | } |
410 | | |
411 | | bool HandleTargetsMode(std::vector<std::string> const& args, |
412 | | cmExecutionStatus& status) |
413 | 0 | { |
414 | 0 | Helper helper(status); |
415 | | |
416 | | // This is the TARGETS mode. |
417 | 0 | std::vector<cmTarget*> targets; |
418 | |
|
419 | 0 | struct ArgVectors |
420 | 0 | { |
421 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Archive; |
422 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Library; |
423 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime; |
424 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Object; |
425 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework; |
426 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Bundle; |
427 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Includes; |
428 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> PrivateHeader; |
429 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> PublicHeader; |
430 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Resource; |
431 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> CxxModulesBmi; |
432 | 0 | std::vector<std::vector<std::string>> FileSets; |
433 | 0 | }; |
434 | |
|
435 | 0 | static auto const argHelper = |
436 | 0 | cmArgumentParser<ArgVectors>{} |
437 | 0 | .Bind("ARCHIVE"_s, &ArgVectors::Archive) |
438 | 0 | .Bind("LIBRARY"_s, &ArgVectors::Library) |
439 | 0 | .Bind("RUNTIME"_s, &ArgVectors::Runtime) |
440 | 0 | .Bind("OBJECTS"_s, &ArgVectors::Object) |
441 | 0 | .Bind("FRAMEWORK"_s, &ArgVectors::Framework) |
442 | 0 | .Bind("BUNDLE"_s, &ArgVectors::Bundle) |
443 | 0 | .Bind("INCLUDES"_s, &ArgVectors::Includes) |
444 | 0 | .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader) |
445 | 0 | .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader) |
446 | 0 | .Bind("RESOURCE"_s, &ArgVectors::Resource) |
447 | 0 | .Bind("FILE_SET"_s, &ArgVectors::FileSets) |
448 | 0 | .Bind("CXX_MODULES_BMI"_s, &ArgVectors::CxxModulesBmi); |
449 | |
|
450 | 0 | std::vector<std::string> genericArgVector; |
451 | 0 | ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); |
452 | | |
453 | | // now parse the generic args (i.e. the ones not specialized on LIBRARY/ |
454 | | // ARCHIVE, RUNTIME etc. (see above) |
455 | | // These generic args also contain the targets and the export stuff |
456 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> targetList; |
457 | 0 | std::string exports; |
458 | 0 | cm::optional<ArgumentParser::MaybeEmpty<std::vector<std::string>>> |
459 | 0 | runtimeDependenciesArgVector; |
460 | 0 | std::string runtimeDependencySetArg; |
461 | 0 | std::vector<std::string> unknownArgs; |
462 | 0 | cmInstallCommandArguments genericArgs(helper.DefaultComponentName, |
463 | 0 | *helper.Makefile); |
464 | 0 | genericArgs.Bind("TARGETS"_s, targetList); |
465 | 0 | genericArgs.Bind("EXPORT"_s, exports); |
466 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCIES"_s, runtimeDependenciesArgVector); |
467 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg); |
468 | 0 | genericArgs.Parse(genericArgVector, &unknownArgs); |
469 | 0 | bool success = genericArgs.Finalize(); |
470 | |
|
471 | 0 | RuntimeDependenciesArgs runtimeDependenciesArgs = |
472 | 0 | runtimeDependenciesArgVector |
473 | 0 | ? RuntimeDependenciesArgHelper.Parse(*runtimeDependenciesArgVector, |
474 | 0 | &unknownArgs) |
475 | 0 | : RuntimeDependenciesArgs(); |
476 | |
|
477 | 0 | cmInstallCommandArguments archiveArgs(helper.DefaultComponentName, |
478 | 0 | *helper.Makefile); |
479 | 0 | cmInstallCommandArguments libraryArgs(helper.DefaultComponentName, |
480 | 0 | *helper.Makefile); |
481 | 0 | cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName, |
482 | 0 | *helper.Makefile); |
483 | 0 | cmInstallCommandArguments objectArgs(helper.DefaultComponentName, |
484 | 0 | *helper.Makefile); |
485 | 0 | cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName, |
486 | 0 | *helper.Makefile); |
487 | 0 | cmInstallCommandArguments bundleArgs(helper.DefaultComponentName, |
488 | 0 | *helper.Makefile); |
489 | 0 | cmInstallCommandArguments privateHeaderArgs(helper.DefaultComponentName, |
490 | 0 | *helper.Makefile); |
491 | 0 | cmInstallCommandArguments publicHeaderArgs(helper.DefaultComponentName, |
492 | 0 | *helper.Makefile); |
493 | 0 | cmInstallCommandArguments resourceArgs(helper.DefaultComponentName, |
494 | 0 | *helper.Makefile); |
495 | 0 | cmInstallCommandIncludesArgument includesArgs; |
496 | 0 | std::vector<cmInstallCommandFileSetArguments> fileSetArgs( |
497 | 0 | argVectors.FileSets.size(), |
498 | 0 | { cmInstallCommandFileSetArguments(helper.DefaultComponentName, |
499 | 0 | *helper.Makefile) }); |
500 | 0 | cmInstallCommandArguments cxxModuleBmiArgs(helper.DefaultComponentName, |
501 | 0 | *helper.Makefile); |
502 | | |
503 | | // now parse the args for specific parts of the target (e.g. LIBRARY, |
504 | | // RUNTIME, ARCHIVE etc. |
505 | 0 | archiveArgs.Parse(argVectors.Archive, &unknownArgs); |
506 | 0 | libraryArgs.Parse(argVectors.Library, &unknownArgs); |
507 | 0 | runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); |
508 | 0 | objectArgs.Parse(argVectors.Object, &unknownArgs); |
509 | 0 | frameworkArgs.Parse(argVectors.Framework, &unknownArgs); |
510 | 0 | bundleArgs.Parse(argVectors.Bundle, &unknownArgs); |
511 | 0 | privateHeaderArgs.Parse(argVectors.PrivateHeader, &unknownArgs); |
512 | 0 | publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs); |
513 | 0 | resourceArgs.Parse(argVectors.Resource, &unknownArgs); |
514 | 0 | includesArgs.Parse(&argVectors.Includes, &unknownArgs); |
515 | 0 | cxxModuleBmiArgs.Parse(argVectors.CxxModulesBmi, &unknownArgs); |
516 | 0 | for (std::size_t i = 0; i < argVectors.FileSets.size(); i++) { |
517 | | // We have to create a separate object for the parsing because |
518 | | // cmArgumentParser<void>::Bind() binds to a specific address, but the |
519 | | // objects in the vector can move around. So we parse in an object with a |
520 | | // fixed address and then copy the data into the vector. |
521 | 0 | cmInstallCommandFileSetArguments fileSetArg(helper.DefaultComponentName, |
522 | 0 | *helper.Makefile); |
523 | 0 | fileSetArg.Parse(argVectors.FileSets[i], &unknownArgs); |
524 | 0 | fileSetArgs[i] = std::move(fileSetArg); |
525 | 0 | } |
526 | |
|
527 | 0 | if (!unknownArgs.empty()) { |
528 | | // Unknown argument. |
529 | 0 | status.SetError( |
530 | 0 | cmStrCat("TARGETS given unknown argument \"", unknownArgs[0], "\".")); |
531 | 0 | return false; |
532 | 0 | } |
533 | | |
534 | | // apply generic args |
535 | 0 | archiveArgs.SetGenericArguments(&genericArgs); |
536 | 0 | libraryArgs.SetGenericArguments(&genericArgs); |
537 | 0 | runtimeArgs.SetGenericArguments(&genericArgs); |
538 | 0 | objectArgs.SetGenericArguments(&genericArgs); |
539 | 0 | frameworkArgs.SetGenericArguments(&genericArgs); |
540 | 0 | bundleArgs.SetGenericArguments(&genericArgs); |
541 | 0 | privateHeaderArgs.SetGenericArguments(&genericArgs); |
542 | 0 | publicHeaderArgs.SetGenericArguments(&genericArgs); |
543 | 0 | resourceArgs.SetGenericArguments(&genericArgs); |
544 | 0 | for (auto& fileSetArg : fileSetArgs) { |
545 | 0 | fileSetArg.SetGenericArguments(&genericArgs); |
546 | 0 | } |
547 | 0 | cxxModuleBmiArgs.SetGenericArguments(&genericArgs); |
548 | |
|
549 | 0 | success = success && archiveArgs.Finalize(); |
550 | 0 | success = success && libraryArgs.Finalize(); |
551 | 0 | success = success && runtimeArgs.Finalize(); |
552 | 0 | success = success && objectArgs.Finalize(); |
553 | 0 | success = success && frameworkArgs.Finalize(); |
554 | 0 | success = success && bundleArgs.Finalize(); |
555 | 0 | success = success && privateHeaderArgs.Finalize(); |
556 | 0 | success = success && publicHeaderArgs.Finalize(); |
557 | 0 | success = success && resourceArgs.Finalize(); |
558 | 0 | success = success && cxxModuleBmiArgs.Finalize(); |
559 | 0 | for (auto& fileSetArg : fileSetArgs) { |
560 | 0 | success = success && fileSetArg.Finalize(); |
561 | 0 | } |
562 | |
|
563 | 0 | if (!success) { |
564 | 0 | return false; |
565 | 0 | } |
566 | | |
567 | | // Enforce argument rules too complex to specify for the |
568 | | // general-purpose parser. |
569 | 0 | if (runtimeArgs.GetNamelinkOnly() || objectArgs.GetNamelinkOnly() || |
570 | 0 | frameworkArgs.GetNamelinkOnly() || bundleArgs.GetNamelinkOnly() || |
571 | 0 | privateHeaderArgs.GetNamelinkOnly() || |
572 | 0 | publicHeaderArgs.GetNamelinkOnly() || resourceArgs.GetNamelinkOnly() || |
573 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
574 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
575 | 0 | -> bool { return fileSetArg.GetNamelinkOnly(); }) || |
576 | 0 | cxxModuleBmiArgs.GetNamelinkOnly()) { |
577 | 0 | status.SetError( |
578 | 0 | "TARGETS given NAMELINK_ONLY option not in LIBRARY or ARCHIVE group. " |
579 | 0 | "The NAMELINK_ONLY option may be specified only following LIBRARY or " |
580 | 0 | "ARCHIVE."); |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | if (runtimeArgs.GetNamelinkSkip() || objectArgs.GetNamelinkSkip() || |
584 | 0 | frameworkArgs.GetNamelinkSkip() || bundleArgs.GetNamelinkSkip() || |
585 | 0 | privateHeaderArgs.GetNamelinkSkip() || |
586 | 0 | publicHeaderArgs.GetNamelinkSkip() || resourceArgs.GetNamelinkSkip() || |
587 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
588 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
589 | 0 | -> bool { return fileSetArg.GetNamelinkSkip(); }) || |
590 | 0 | cxxModuleBmiArgs.GetNamelinkSkip()) { |
591 | 0 | status.SetError( |
592 | 0 | "TARGETS given NAMELINK_SKIP option not in LIBRARY or ARCHIVE group. " |
593 | 0 | "The NAMELINK_SKIP option may be specified only following LIBRARY or " |
594 | 0 | "ARCHIVE."); |
595 | 0 | return false; |
596 | 0 | } |
597 | 0 | if (runtimeArgs.HasNamelinkComponent() || |
598 | 0 | objectArgs.HasNamelinkComponent() || |
599 | 0 | frameworkArgs.HasNamelinkComponent() || |
600 | 0 | bundleArgs.HasNamelinkComponent() || |
601 | 0 | privateHeaderArgs.HasNamelinkComponent() || |
602 | 0 | publicHeaderArgs.HasNamelinkComponent() || |
603 | 0 | resourceArgs.HasNamelinkComponent() || |
604 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
605 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
606 | 0 | -> bool { return fileSetArg.HasNamelinkComponent(); }) || |
607 | 0 | cxxModuleBmiArgs.HasNamelinkComponent()) { |
608 | 0 | status.SetError( |
609 | 0 | "TARGETS given NAMELINK_COMPONENT option not in LIBRARY or ARCHIVE " |
610 | 0 | "group. The NAMELINK_COMPONENT option may be specified only following " |
611 | 0 | "LIBRARY or ARCHIVE."); |
612 | 0 | return false; |
613 | 0 | } |
614 | 0 | if (libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip()) { |
615 | 0 | status.SetError("TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. " |
616 | 0 | "At most one of these two options may be specified."); |
617 | 0 | return false; |
618 | 0 | } |
619 | 0 | if (!genericArgs.GetType().empty() || !archiveArgs.GetType().empty() || |
620 | 0 | !libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() || |
621 | 0 | !objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() || |
622 | 0 | !bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() || |
623 | 0 | !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty() || |
624 | 0 | std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
625 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
626 | 0 | -> bool { return !fileSetArg.GetType().empty(); }) || |
627 | 0 | !cxxModuleBmiArgs.GetType().empty()) { |
628 | 0 | status.SetError( |
629 | 0 | "TARGETS given TYPE option. The TYPE option may only be specified in " |
630 | 0 | " install(FILES) and install(DIRECTORIES)."); |
631 | 0 | return false; |
632 | 0 | } |
633 | 0 | if (std::any_of(fileSetArgs.begin(), fileSetArgs.end(), |
634 | 0 | [](cmInstallCommandFileSetArguments const& fileSetArg) |
635 | 0 | -> bool { return fileSetArg.GetFileSet().empty(); })) { |
636 | 0 | status.SetError("TARGETS given FILE_SET option without file set name."); |
637 | 0 | return false; |
638 | 0 | } |
639 | | |
640 | 0 | cmInstallRuntimeDependencySet* runtimeDependencySet = nullptr; |
641 | 0 | if (runtimeDependenciesArgVector) { |
642 | 0 | if (!runtimeDependencySetArg.empty()) { |
643 | 0 | status.SetError("TARGETS cannot have both RUNTIME_DEPENDENCIES and " |
644 | 0 | "RUNTIME_DEPENDENCY_SET."); |
645 | 0 | return false; |
646 | 0 | } |
647 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
648 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
649 | 0 | system)) { |
650 | 0 | status.SetError( |
651 | 0 | cmStrCat("TARGETS RUNTIME_DEPENDENCIES is not supported on system \"", |
652 | 0 | system, '"')); |
653 | 0 | return false; |
654 | 0 | } |
655 | 0 | if (helper.Makefile->IsOn("CMAKE_CROSSCOMPILING")) { |
656 | 0 | status.SetError("TARGETS RUNTIME_DEPENDENCIES is not supported " |
657 | 0 | "when cross-compiling."); |
658 | 0 | return false; |
659 | 0 | } |
660 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME") == |
661 | 0 | "Darwin" && |
662 | 0 | frameworkArgs.GetDestination().empty()) { |
663 | 0 | status.SetError( |
664 | 0 | "TARGETS RUNTIME_DEPENDENCIES given no FRAMEWORK DESTINATION"); |
665 | 0 | return false; |
666 | 0 | } |
667 | 0 | runtimeDependencySet = helper.Makefile->GetGlobalGenerator() |
668 | 0 | ->CreateAnonymousRuntimeDependencySet(); |
669 | 0 | } else if (!runtimeDependencySetArg.empty()) { |
670 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
671 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
672 | 0 | system)) { |
673 | 0 | status.SetError(cmStrCat( |
674 | 0 | "TARGETS RUNTIME_DEPENDENCY_SET is not supported on system \"", system, |
675 | 0 | '"')); |
676 | 0 | return false; |
677 | 0 | } |
678 | 0 | runtimeDependencySet = |
679 | 0 | helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet( |
680 | 0 | runtimeDependencySetArg); |
681 | 0 | } |
682 | | |
683 | | // Select the mode for installing symlinks to versioned shared libraries. |
684 | 0 | cmInstallTargetGenerator::NamelinkModeType namelinkMode = |
685 | 0 | cmInstallTargetGenerator::NamelinkModeNone; |
686 | 0 | if (libraryArgs.GetNamelinkOnly()) { |
687 | 0 | namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly; |
688 | 0 | } else if (libraryArgs.GetNamelinkSkip()) { |
689 | 0 | namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip; |
690 | 0 | } |
691 | | // Select the mode for installing symlinks to versioned imported libraries. |
692 | 0 | cmInstallTargetGenerator::NamelinkModeType importlinkMode = |
693 | 0 | cmInstallTargetGenerator::NamelinkModeNone; |
694 | 0 | if (archiveArgs.GetNamelinkOnly()) { |
695 | 0 | importlinkMode = cmInstallTargetGenerator::NamelinkModeOnly; |
696 | 0 | } else if (archiveArgs.GetNamelinkSkip()) { |
697 | 0 | importlinkMode = cmInstallTargetGenerator::NamelinkModeSkip; |
698 | 0 | } |
699 | | |
700 | | // Check if there is something to do. |
701 | 0 | if (targetList.empty()) { |
702 | 0 | return true; |
703 | 0 | } |
704 | | |
705 | 0 | for (std::string const& tgt : targetList) { |
706 | |
|
707 | 0 | if (helper.Makefile->IsAlias(tgt)) { |
708 | 0 | status.SetError( |
709 | 0 | cmStrCat("TARGETS given target \"", tgt, "\" which is an alias.")); |
710 | 0 | return false; |
711 | 0 | } |
712 | | // Lookup this target in the current directory. |
713 | 0 | cmTarget* target = helper.Makefile->FindLocalNonAliasTarget(tgt); |
714 | 0 | if (!target) { |
715 | | // If no local target has been found, find it in the global scope. |
716 | 0 | cmTarget* const globalTarget = |
717 | 0 | helper.Makefile->GetGlobalGenerator()->FindTarget( |
718 | 0 | tgt, { cmStateEnums::TargetDomain::NATIVE }); |
719 | 0 | if (globalTarget && !globalTarget->IsImported()) { |
720 | 0 | target = globalTarget; |
721 | 0 | } |
722 | 0 | } |
723 | 0 | if (target) { |
724 | | // Found the target. Check its type. |
725 | 0 | if (target->GetType() != cmStateEnums::EXECUTABLE && |
726 | 0 | target->GetType() != cmStateEnums::STATIC_LIBRARY && |
727 | 0 | target->GetType() != cmStateEnums::SHARED_LIBRARY && |
728 | 0 | target->GetType() != cmStateEnums::MODULE_LIBRARY && |
729 | 0 | target->GetType() != cmStateEnums::OBJECT_LIBRARY && |
730 | 0 | target->GetType() != cmStateEnums::INTERFACE_LIBRARY) { |
731 | 0 | status.SetError( |
732 | 0 | cmStrCat("TARGETS given target \"", tgt, |
733 | 0 | "\" which is not an executable, library, or module.")); |
734 | 0 | return false; |
735 | 0 | } |
736 | | // Store the target in the list to be installed. |
737 | 0 | targets.push_back(target); |
738 | 0 | } else { |
739 | | // Did not find the target. |
740 | 0 | status.SetError( |
741 | 0 | cmStrCat("TARGETS given target \"", tgt, "\" which does not exist.")); |
742 | 0 | return false; |
743 | 0 | } |
744 | 0 | } |
745 | | |
746 | | // Keep track of whether we will be performing an installation of |
747 | | // any files of the given type. |
748 | 0 | bool installsArchive = false; |
749 | 0 | bool installsLibrary = false; |
750 | 0 | bool installsNamelink = false; |
751 | 0 | bool installsImportlink = false; |
752 | 0 | bool installsRuntime = false; |
753 | 0 | bool installsObject = false; |
754 | 0 | bool installsFramework = false; |
755 | 0 | bool installsBundle = false; |
756 | 0 | bool installsPrivateHeader = false; |
757 | 0 | bool installsPublicHeader = false; |
758 | 0 | bool installsResource = false; |
759 | 0 | std::vector<bool> installsFileSet(fileSetArgs.size(), false); |
760 | 0 | bool installsCxxModuleBmi = false; |
761 | | |
762 | | // Generate install script code to install the given targets. |
763 | 0 | for (cmTarget* ti : targets) { |
764 | | // Handle each target type. |
765 | 0 | cmTarget& target = *ti; |
766 | 0 | std::unique_ptr<cmInstallTargetGenerator> archiveGenerator; |
767 | 0 | std::unique_ptr<cmInstallTargetGenerator> libraryGenerator; |
768 | 0 | std::unique_ptr<cmInstallTargetGenerator> namelinkGenerator; |
769 | 0 | std::unique_ptr<cmInstallTargetGenerator> importlinkGenerator; |
770 | 0 | std::unique_ptr<cmInstallTargetGenerator> runtimeGenerator; |
771 | 0 | std::unique_ptr<cmInstallTargetGenerator> objectGenerator; |
772 | 0 | std::unique_ptr<cmInstallTargetGenerator> frameworkGenerator; |
773 | 0 | std::unique_ptr<cmInstallTargetGenerator> bundleGenerator; |
774 | 0 | std::unique_ptr<cmInstallFilesGenerator> privateHeaderGenerator; |
775 | 0 | std::unique_ptr<cmInstallFilesGenerator> publicHeaderGenerator; |
776 | 0 | std::unique_ptr<cmInstallFilesGenerator> resourceGenerator; |
777 | 0 | std::vector<std::unique_ptr<cmInstallFileSetGenerator>> fileSetGenerators; |
778 | 0 | std::unique_ptr<cmInstallCxxModuleBmiGenerator> cxxModuleBmiGenerator; |
779 | | |
780 | | // Avoid selecting default destinations for PUBLIC_HEADER and |
781 | | // PRIVATE_HEADER if any artifacts are specified. |
782 | 0 | bool artifactsSpecified = false; |
783 | | |
784 | | // Track whether this is a namelink-only rule. |
785 | 0 | bool namelinkOnly = false; |
786 | |
|
787 | 0 | auto addTargetExport = [&]() -> bool { |
788 | | // Add this install rule to an export if one was specified. |
789 | 0 | if (!exports.empty()) { |
790 | 0 | auto interfaceFileSets = target.GetAllInterfaceFileSets(); |
791 | 0 | if (std::any_of( |
792 | 0 | interfaceFileSets.begin(), interfaceFileSets.end(), |
793 | 0 | [=](std::string const& name) -> bool { |
794 | 0 | return !std::any_of( |
795 | 0 | fileSetArgs.begin(), fileSetArgs.end(), |
796 | 0 | [=](cmInstallCommandFileSetArguments const& fileSetArg) |
797 | 0 | -> bool { return fileSetArg.GetFileSet() == name; }); |
798 | 0 | })) { |
799 | 0 | status.SetError(cmStrCat("TARGETS target ", target.GetName(), |
800 | 0 | " is exported but not all of its interface " |
801 | 0 | "file sets are installed")); |
802 | 0 | return false; |
803 | 0 | } |
804 | | |
805 | 0 | auto te = cm::make_unique<cmTargetExport>(); |
806 | 0 | te->TargetName = target.GetName(); |
807 | 0 | te->ArchiveGenerator = archiveGenerator.get(); |
808 | 0 | te->BundleGenerator = bundleGenerator.get(); |
809 | 0 | te->FrameworkGenerator = frameworkGenerator.get(); |
810 | 0 | te->HeaderGenerator = publicHeaderGenerator.get(); |
811 | 0 | te->LibraryGenerator = libraryGenerator.get(); |
812 | 0 | te->RuntimeGenerator = runtimeGenerator.get(); |
813 | 0 | te->ObjectsGenerator = objectGenerator.get(); |
814 | 0 | for (auto const& gen : fileSetGenerators) { |
815 | 0 | te->FileSetGenerators[gen->GetFileSetName()] = gen.get(); |
816 | 0 | } |
817 | 0 | te->CxxModuleBmiGenerator = cxxModuleBmiGenerator.get(); |
818 | 0 | target.AddInstallIncludeDirectories( |
819 | 0 | *te, cmMakeRange(includesArgs.GetIncludeDirs())); |
820 | 0 | te->NamelinkOnly = namelinkOnly; |
821 | 0 | helper.Makefile->GetGlobalGenerator() |
822 | 0 | ->GetExportSets()[exports] |
823 | 0 | .AddTargetExport(std::move(te)); |
824 | 0 | } |
825 | 0 | return true; |
826 | 0 | }; |
827 | |
|
828 | 0 | switch (target.GetType()) { |
829 | 0 | case cmStateEnums::SHARED_LIBRARY: { |
830 | | // Shared libraries are handled differently on DLL and non-DLL |
831 | | // platforms. All windows platforms are DLL platforms including |
832 | | // cygwin. Currently no other platform is a DLL platform. |
833 | 0 | if (target.IsDLLPlatform()) { |
834 | | // When in namelink only mode skip all libraries on Windows. |
835 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
836 | 0 | namelinkOnly = true; |
837 | 0 | if (!addTargetExport()) { |
838 | 0 | return false; |
839 | 0 | } |
840 | 0 | continue; |
841 | 0 | } |
842 | | |
843 | | // This is a DLL platform. |
844 | 0 | if (!archiveArgs.GetDestination().empty()) { |
845 | | // The import library uses the ARCHIVE properties. |
846 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
847 | 0 | target, archiveArgs, true, helper.CaptureContext()); |
848 | 0 | artifactsSpecified = true; |
849 | 0 | } |
850 | 0 | if (!runtimeArgs.GetDestination().empty()) { |
851 | | // The DLL uses the RUNTIME properties. |
852 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
853 | 0 | target, runtimeArgs, false, helper.CaptureContext()); |
854 | 0 | artifactsSpecified = true; |
855 | 0 | } |
856 | 0 | if (!archiveGenerator && !runtimeGenerator) { |
857 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
858 | 0 | target, archiveArgs, true, helper.CaptureContext(), |
859 | 0 | helper.GetArchiveDestination(nullptr)); |
860 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
861 | 0 | target, runtimeArgs, false, helper.CaptureContext(), |
862 | 0 | helper.GetRuntimeDestination(nullptr)); |
863 | 0 | } |
864 | 0 | if (runtimeDependencySet && runtimeGenerator) { |
865 | 0 | runtimeDependencySet->AddLibrary(runtimeGenerator.get()); |
866 | 0 | } |
867 | 0 | } else { |
868 | | // This is a non-DLL platform. |
869 | | // If it is marked with FRAMEWORK property use the FRAMEWORK set of |
870 | | // INSTALL properties. Otherwise, use the LIBRARY properties. |
871 | 0 | if (target.IsFrameworkOnApple()) { |
872 | | // When in namelink only mode skip frameworks. |
873 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
874 | 0 | namelinkOnly = true; |
875 | 0 | if (!addTargetExport()) { |
876 | 0 | return false; |
877 | 0 | } |
878 | 0 | continue; |
879 | 0 | } |
880 | | |
881 | | // Use the FRAMEWORK properties. |
882 | 0 | if (!frameworkArgs.GetDestination().empty()) { |
883 | 0 | frameworkGenerator = CreateInstallTargetGenerator( |
884 | 0 | target, frameworkArgs, false, helper.CaptureContext()); |
885 | 0 | } else { |
886 | 0 | status.SetError( |
887 | 0 | cmStrCat("TARGETS given no FRAMEWORK DESTINATION for shared " |
888 | 0 | "library FRAMEWORK target \"", |
889 | 0 | target.GetName(), "\".")); |
890 | 0 | return false; |
891 | 0 | } |
892 | 0 | } else { |
893 | | // The shared library uses the LIBRARY properties. |
894 | 0 | if (!libraryArgs.GetDestination().empty()) { |
895 | 0 | artifactsSpecified = true; |
896 | 0 | } |
897 | 0 | if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) { |
898 | 0 | libraryGenerator = CreateInstallTargetGenerator( |
899 | 0 | target, libraryArgs, false, helper.CaptureContext(), |
900 | 0 | helper.GetLibraryDestination(&libraryArgs)); |
901 | 0 | libraryGenerator->SetNamelinkMode( |
902 | 0 | cmInstallTargetGenerator::NamelinkModeSkip); |
903 | 0 | } |
904 | 0 | if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) { |
905 | 0 | namelinkGenerator = CreateInstallTargetGenerator( |
906 | 0 | target, libraryArgs, false, helper.CaptureContext(), |
907 | 0 | helper.GetLibraryDestination(&libraryArgs), false, true); |
908 | 0 | namelinkGenerator->SetNamelinkMode( |
909 | 0 | cmInstallTargetGenerator::NamelinkModeOnly); |
910 | 0 | } |
911 | 0 | namelinkOnly = |
912 | 0 | (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
913 | |
|
914 | 0 | if (target.GetMakefile()->PlatformSupportsAppleTextStubs() && |
915 | 0 | target.IsSharedLibraryWithExports()) { |
916 | | // Apple .tbd files use the ARCHIVE properties |
917 | 0 | if (!archiveArgs.GetDestination().empty()) { |
918 | 0 | artifactsSpecified = true; |
919 | 0 | } |
920 | 0 | if (importlinkMode != |
921 | 0 | cmInstallTargetGenerator::NamelinkModeOnly) { |
922 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
923 | 0 | target, archiveArgs, true, helper.CaptureContext(), |
924 | 0 | helper.GetLibraryDestination(&archiveArgs)); |
925 | 0 | archiveGenerator->SetImportlinkMode( |
926 | 0 | cmInstallTargetGenerator::NamelinkModeSkip); |
927 | 0 | } |
928 | 0 | if (importlinkMode != |
929 | 0 | cmInstallTargetGenerator::NamelinkModeSkip) { |
930 | 0 | importlinkGenerator = CreateInstallTargetGenerator( |
931 | 0 | target, archiveArgs, true, helper.CaptureContext(), |
932 | 0 | helper.GetLibraryDestination(&archiveArgs), false, true); |
933 | 0 | importlinkGenerator->SetImportlinkMode( |
934 | 0 | cmInstallTargetGenerator::NamelinkModeOnly); |
935 | 0 | } |
936 | 0 | namelinkOnly = |
937 | 0 | (importlinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
938 | 0 | } |
939 | 0 | } |
940 | 0 | if (runtimeDependencySet && libraryGenerator) { |
941 | 0 | runtimeDependencySet->AddLibrary(libraryGenerator.get()); |
942 | 0 | } |
943 | 0 | } |
944 | 0 | } break; |
945 | 0 | case cmStateEnums::STATIC_LIBRARY: { |
946 | | // If it is marked with FRAMEWORK property use the FRAMEWORK set of |
947 | | // INSTALL properties. Otherwise, use the LIBRARY properties. |
948 | 0 | if (target.IsFrameworkOnApple()) { |
949 | | // When in namelink only mode skip frameworks. |
950 | 0 | if (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly) { |
951 | 0 | namelinkOnly = true; |
952 | 0 | if (!addTargetExport()) { |
953 | 0 | return false; |
954 | 0 | } |
955 | 0 | continue; |
956 | 0 | } |
957 | | |
958 | | // Use the FRAMEWORK properties. |
959 | 0 | if (!frameworkArgs.GetDestination().empty()) { |
960 | 0 | frameworkGenerator = CreateInstallTargetGenerator( |
961 | 0 | target, frameworkArgs, false, helper.CaptureContext()); |
962 | 0 | } else { |
963 | 0 | status.SetError( |
964 | 0 | cmStrCat("TARGETS given no FRAMEWORK DESTINATION for static " |
965 | 0 | "library FRAMEWORK target \"", |
966 | 0 | target.GetName(), "\".")); |
967 | 0 | return false; |
968 | 0 | } |
969 | 0 | } else { |
970 | | // Static libraries use ARCHIVE properties. |
971 | 0 | if (!archiveArgs.GetDestination().empty()) { |
972 | 0 | artifactsSpecified = true; |
973 | 0 | } |
974 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
975 | 0 | target, archiveArgs, false, helper.CaptureContext(), |
976 | 0 | helper.GetArchiveDestination(&archiveArgs)); |
977 | 0 | } |
978 | 0 | } break; |
979 | 0 | case cmStateEnums::MODULE_LIBRARY: { |
980 | | // Modules use LIBRARY properties. |
981 | 0 | if (!libraryArgs.GetDestination().empty()) { |
982 | 0 | libraryGenerator = CreateInstallTargetGenerator( |
983 | 0 | target, libraryArgs, false, helper.CaptureContext()); |
984 | 0 | libraryGenerator->SetNamelinkMode(namelinkMode); |
985 | 0 | namelinkOnly = |
986 | 0 | (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly); |
987 | 0 | if (runtimeDependencySet) { |
988 | 0 | runtimeDependencySet->AddModule(libraryGenerator.get()); |
989 | 0 | } |
990 | 0 | } else { |
991 | 0 | status.SetError( |
992 | 0 | cmStrCat("TARGETS given no LIBRARY DESTINATION for module " |
993 | 0 | "target \"", |
994 | 0 | target.GetName(), "\".")); |
995 | 0 | return false; |
996 | 0 | } |
997 | 0 | } break; |
998 | 0 | case cmStateEnums::OBJECT_LIBRARY: { |
999 | | // Objects use OBJECT properties. |
1000 | 0 | if (!objectArgs.GetDestination().empty()) { |
1001 | | // Verify that we know where the objects are to install them. |
1002 | 0 | std::string reason; |
1003 | 0 | if (!target.HasKnownObjectFileLocation(&reason)) { |
1004 | 0 | status.SetError( |
1005 | 0 | cmStrCat("TARGETS given OBJECT library \"", target.GetName(), |
1006 | 0 | "\" whose objects may not be installed", reason, '.')); |
1007 | 0 | return false; |
1008 | 0 | } |
1009 | | |
1010 | 0 | objectGenerator = CreateInstallTargetGenerator( |
1011 | 0 | target, objectArgs, false, helper.CaptureContext()); |
1012 | 0 | } else { |
1013 | | // Installing an OBJECT library without a destination transforms |
1014 | | // it to an INTERFACE library. It installs no files but can be |
1015 | | // exported. |
1016 | 0 | } |
1017 | 0 | } break; |
1018 | 0 | case cmStateEnums::EXECUTABLE: { |
1019 | 0 | if (target.IsAppBundleOnApple()) { |
1020 | | // Application bundles use the BUNDLE properties. |
1021 | 0 | if (!bundleArgs.GetDestination().empty()) { |
1022 | 0 | bundleGenerator = CreateInstallTargetGenerator( |
1023 | 0 | target, bundleArgs, false, helper.CaptureContext()); |
1024 | 0 | } |
1025 | 0 | if (!bundleGenerator) { |
1026 | 0 | status.SetError(cmStrCat("TARGETS given no BUNDLE DESTINATION for " |
1027 | 0 | "MACOSX_BUNDLE executable target \"", |
1028 | 0 | target.GetName(), "\".")); |
1029 | 0 | return false; |
1030 | 0 | } |
1031 | 0 | if (runtimeDependencySet) { |
1032 | 0 | if (!AddBundleExecutable(helper, runtimeDependencySet, |
1033 | 0 | bundleGenerator.get())) { |
1034 | 0 | return false; |
1035 | 0 | } |
1036 | 0 | } |
1037 | 0 | } else { |
1038 | | // Executables use the RUNTIME properties. |
1039 | 0 | if (!runtimeArgs.GetDestination().empty()) { |
1040 | 0 | artifactsSpecified = true; |
1041 | 0 | } |
1042 | 0 | runtimeGenerator = CreateInstallTargetGenerator( |
1043 | 0 | target, runtimeArgs, false, helper.CaptureContext(), |
1044 | 0 | helper.GetRuntimeDestination(&runtimeArgs)); |
1045 | 0 | if (runtimeDependencySet) { |
1046 | 0 | runtimeDependencySet->AddExecutable(runtimeGenerator.get()); |
1047 | 0 | } |
1048 | 0 | } |
1049 | | |
1050 | | // On DLL platforms an executable may also have an import |
1051 | | // library. Install it to the archive destination if it |
1052 | | // exists. |
1053 | 0 | if ((target.IsDLLPlatform() || target.IsAIX()) && |
1054 | 0 | !archiveArgs.GetDestination().empty() && |
1055 | 0 | target.IsExecutableWithExports()) { |
1056 | | // The import library uses the ARCHIVE properties. |
1057 | 0 | artifactsSpecified = true; |
1058 | 0 | archiveGenerator = CreateInstallTargetGenerator( |
1059 | 0 | target, archiveArgs, true, helper.CaptureContext(), true); |
1060 | 0 | } |
1061 | 0 | } break; |
1062 | 0 | case cmStateEnums::INTERFACE_LIBRARY: |
1063 | | // Nothing to do. An INTERFACE_LIBRARY can be installed, but the |
1064 | | // only effect of that is to make it exportable. It installs no |
1065 | | // other files itself. |
1066 | 0 | default: |
1067 | | // This should never happen due to the above type check. |
1068 | | // Ignore the case. |
1069 | 0 | break; |
1070 | 0 | } |
1071 | | |
1072 | | // These well-known sets of files are installed *automatically* for |
1073 | | // FRAMEWORK SHARED library targets on the Mac as part of installing the |
1074 | | // FRAMEWORK. For other target types or on other platforms, they are not |
1075 | | // installed automatically and so we need to create install files |
1076 | | // generators for them. |
1077 | 0 | bool createInstallGeneratorsForTargetFileSets = true; |
1078 | |
|
1079 | 0 | if (target.IsFrameworkOnApple()) { |
1080 | 0 | createInstallGeneratorsForTargetFileSets = false; |
1081 | 0 | } |
1082 | |
|
1083 | 0 | if (createInstallGeneratorsForTargetFileSets && !namelinkOnly) { |
1084 | 0 | cmValue files = target.GetProperty("PRIVATE_HEADER"); |
1085 | 0 | if (cmNonempty(files)) { |
1086 | 0 | cmList relFiles{ *files }; |
1087 | 0 | std::vector<std::string> absFiles; |
1088 | 0 | if (!helper.MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) { |
1089 | 0 | return false; |
1090 | 0 | } |
1091 | | |
1092 | | // Create the files install generator. |
1093 | 0 | if (!artifactsSpecified || |
1094 | 0 | !privateHeaderArgs.GetDestination().empty()) { |
1095 | 0 | privateHeaderGenerator = CreateInstallFilesGenerator( |
1096 | 0 | helper.Makefile, absFiles, privateHeaderArgs, false, |
1097 | 0 | helper.GetIncludeDestination(&privateHeaderArgs)); |
1098 | 0 | } else { |
1099 | 0 | helper.Makefile->IssueDiagnostic( |
1100 | 0 | cmDiagnostics::CMD_AUTHOR, |
1101 | 0 | cmStrCat("Target ", target.GetName(), |
1102 | 0 | " has PRIVATE_HEADER files" |
1103 | 0 | " but no PRIVATE_HEADER DESTINATION.")); |
1104 | 0 | } |
1105 | 0 | } |
1106 | | |
1107 | 0 | files = target.GetProperty("PUBLIC_HEADER"); |
1108 | 0 | if (cmNonempty(files)) { |
1109 | 0 | cmList relFiles{ *files }; |
1110 | 0 | std::vector<std::string> absFiles; |
1111 | 0 | if (!helper.MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) { |
1112 | 0 | return false; |
1113 | 0 | } |
1114 | | |
1115 | | // Create the files install generator. |
1116 | 0 | if (!artifactsSpecified || |
1117 | 0 | !publicHeaderArgs.GetDestination().empty()) { |
1118 | 0 | publicHeaderGenerator = CreateInstallFilesGenerator( |
1119 | 0 | helper.Makefile, absFiles, publicHeaderArgs, false, |
1120 | 0 | helper.GetIncludeDestination(&publicHeaderArgs)); |
1121 | 0 | } else { |
1122 | 0 | helper.Makefile->IssueDiagnostic( |
1123 | 0 | cmDiagnostics::CMD_AUTHOR, |
1124 | 0 | cmStrCat("Target ", target.GetName(), |
1125 | 0 | " has PUBLIC_HEADER files" |
1126 | 0 | " but no PUBLIC_HEADER DESTINATION.")); |
1127 | 0 | } |
1128 | 0 | } |
1129 | | |
1130 | 0 | files = target.GetProperty("RESOURCE"); |
1131 | 0 | if (cmNonempty(files)) { |
1132 | 0 | cmList relFiles{ *files }; |
1133 | 0 | std::vector<std::string> absFiles; |
1134 | 0 | if (!helper.MakeFilesFullPath("RESOURCE", relFiles, absFiles)) { |
1135 | 0 | return false; |
1136 | 0 | } |
1137 | | |
1138 | | // Create the files install generator. |
1139 | 0 | if (!resourceArgs.GetDestination().empty()) { |
1140 | 0 | resourceGenerator = CreateInstallFilesGenerator( |
1141 | 0 | helper.Makefile, absFiles, resourceArgs, false); |
1142 | 0 | } else if (!target.IsAppBundleOnApple()) { |
1143 | 0 | helper.Makefile->IssueDiagnostic( |
1144 | 0 | cmDiagnostics::CMD_AUTHOR, |
1145 | 0 | cmStrCat("Target ", target.GetName(), |
1146 | 0 | " has RESOURCE files but no RESOURCE DESTINATION.")); |
1147 | 0 | } |
1148 | 0 | } |
1149 | 0 | } |
1150 | | |
1151 | 0 | if (!namelinkOnly) { |
1152 | 0 | for (std::size_t i = 0; i < fileSetArgs.size(); i++) { |
1153 | 0 | fileSetGenerators.push_back( |
1154 | 0 | CreateInstallFileSetGenerator(helper, target, 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.CaptureContext()); |
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 globalTarget = |
1382 | 0 | helper.Makefile->GetGlobalGenerator()->FindTarget( |
1383 | 0 | tgt, { cmStateEnums::TargetDomain::NATIVE }); |
1384 | 0 | if (globalTarget && globalTarget->IsImported()) { |
1385 | 0 | target = globalTarget; |
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.CaptureContext()); |
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 inMatchMode = false; |
1652 | 0 | bool optional = false; |
1653 | 0 | bool excludeFromAll = false; |
1654 | 0 | bool messageNever = false; |
1655 | 0 | std::vector<std::string> dirs; |
1656 | 0 | cm::optional<std::string> destination; |
1657 | 0 | std::string permissionsFile; |
1658 | 0 | std::string permissionsDir; |
1659 | 0 | std::vector<std::string> configurations; |
1660 | 0 | std::string component = helper.DefaultComponentName; |
1661 | 0 | std::string literalArgs; |
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 (inMatchMode) { |
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 (inMatchMode) { |
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 (inMatchMode) { |
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 (inMatchMode) { |
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 | messageNever = 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 | inMatchMode = true; |
1706 | 0 | } else if (args[i] == "REGEX") { |
1707 | | // Switch to a new regex match rule. |
1708 | 0 | doing = DoingRegex; |
1709 | 0 | inMatchMode = true; |
1710 | 0 | } else if (args[i] == "EXCLUDE") { |
1711 | | // Add this property to the current match rule. |
1712 | 0 | if (!inMatchMode || 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 | literalArgs += " EXCLUDE"; |
1718 | 0 | doing = DoingNone; |
1719 | 0 | } else if (args[i] == "PERMISSIONS") { |
1720 | 0 | if (!inMatchMode) { |
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 | literalArgs += " PERMISSIONS"; |
1728 | 0 | doing = DoingPermsMatch; |
1729 | 0 | } else if (args[i] == "FILE_PERMISSIONS") { |
1730 | 0 | if (inMatchMode) { |
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 (inMatchMode) { |
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 (inMatchMode) { |
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 | literalArgs += " USE_SOURCE_PERMISSIONS"; |
1756 | 0 | doing = DoingNone; |
1757 | 0 | } else if (args[i] == "FILES_MATCHING") { |
1758 | 0 | if (inMatchMode) { |
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 | literalArgs += " FILES_MATCHING"; |
1766 | 0 | doing = DoingNone; |
1767 | 0 | } else if (args[i] == "CONFIGURATIONS") { |
1768 | 0 | if (inMatchMode) { |
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 (inMatchMode) { |
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 (inMatchMode) { |
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 | excludeFromAll = 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().IssuePolicyWarning(cmPolicies::CMP0177); |
1827 | 0 | } |
1828 | 0 | CM_FALLTHROUGH; |
1829 | 0 | case cmPolicies::OLD: |
1830 | 0 | destination = args[i]; |
1831 | 0 | break; |
1832 | 0 | } |
1833 | 0 | doing = DoingNone; |
1834 | 0 | } else if (doing == DoingType) { |
1835 | 0 | if (allowedTypes.count(args[i]) == 0) { |
1836 | 0 | status.SetError(cmStrCat(args[0], " given non-type \"", args[i], |
1837 | 0 | "\" with TYPE argument.")); |
1838 | 0 | return false; |
1839 | 0 | } |
1840 | | |
1841 | 0 | type = args[i]; |
1842 | 0 | doing = DoingNone; |
1843 | 0 | } else if (doing == DoingPattern) { |
1844 | | // Convert the pattern to a regular expression. Require a |
1845 | | // leading slash and trailing end-of-string in the matched |
1846 | | // string to make sure the pattern matches only whole file |
1847 | | // names. |
1848 | 0 | literalArgs += " REGEX \"/"; |
1849 | 0 | std::string regex = cmsys::Glob::PatternToRegex(args[i], false); |
1850 | 0 | cmSystemTools::ReplaceString(regex, "\\", "\\\\"); |
1851 | 0 | literalArgs += regex; |
1852 | 0 | literalArgs += "$\""; |
1853 | 0 | doing = DoingNone; |
1854 | 0 | } else if (doing == DoingRegex) { |
1855 | 0 | literalArgs += " REGEX \""; |
1856 | | // Match rules are case-insensitive on some platforms. |
1857 | | #if defined(_WIN32) || defined(__APPLE__) |
1858 | | std::string regex = cmSystemTools::LowerCase(args[i]); |
1859 | | #else |
1860 | 0 | std::string regex = args[i]; |
1861 | 0 | #endif |
1862 | 0 | cmSystemTools::ReplaceString(regex, "\\", "\\\\"); |
1863 | 0 | literalArgs += regex; |
1864 | 0 | literalArgs += "\""; |
1865 | 0 | doing = DoingNone; |
1866 | 0 | } else if (doing == DoingComponent) { |
1867 | 0 | component = args[i]; |
1868 | 0 | doing = DoingNone; |
1869 | 0 | } else if (doing == DoingPermsFile) { |
1870 | | // Check the requested permission. |
1871 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], |
1872 | 0 | permissionsFile)) { |
1873 | 0 | status.SetError(cmStrCat(args[0], " given invalid file permission \"", |
1874 | 0 | args[i], "\".")); |
1875 | 0 | return false; |
1876 | 0 | } |
1877 | 0 | } else if (doing == DoingPermsDir) { |
1878 | | // Check the requested permission. |
1879 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], |
1880 | 0 | permissionsDir)) { |
1881 | 0 | status.SetError(cmStrCat( |
1882 | 0 | args[0], " given invalid directory permission \"", args[i], "\".")); |
1883 | 0 | return false; |
1884 | 0 | } |
1885 | 0 | } else if (doing == DoingPermsMatch) { |
1886 | | // Check the requested permission. |
1887 | 0 | if (!cmInstallCommandArguments::CheckPermissions(args[i], literalArgs)) { |
1888 | 0 | status.SetError( |
1889 | 0 | cmStrCat(args[0], " given invalid permission \"", args[i], "\".")); |
1890 | 0 | return false; |
1891 | 0 | } |
1892 | 0 | } else { |
1893 | | // Unknown argument. |
1894 | 0 | status.SetError( |
1895 | 0 | cmStrCat(args[0], " given unknown argument \"", args[i], "\".")); |
1896 | 0 | return false; |
1897 | 0 | } |
1898 | 0 | } |
1899 | | |
1900 | | // Support installing an empty directory. |
1901 | 0 | if (dirs.empty() && destination.has_value()) { |
1902 | 0 | dirs.emplace_back(); |
1903 | 0 | } |
1904 | | |
1905 | | // Check if there is something to do. |
1906 | 0 | if (dirs.empty()) { |
1907 | 0 | return true; |
1908 | 0 | } |
1909 | 0 | if (!destination.has_value()) { |
1910 | 0 | if (type.empty()) { |
1911 | | // A destination is required. |
1912 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
1913 | 0 | return false; |
1914 | 0 | } |
1915 | 0 | destination = helper.GetDestinationForType(nullptr, type); |
1916 | 0 | } else if (!type.empty()) { |
1917 | 0 | status.SetError(cmStrCat(args[0], |
1918 | 0 | " given both TYPE and DESTINATION " |
1919 | 0 | "arguments. You may only specify one.")); |
1920 | 0 | return false; |
1921 | 0 | } |
1922 | | |
1923 | 0 | cmInstallGenerator::MessageLevel message = |
1924 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile, messageNever); |
1925 | | |
1926 | | // Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
1927 | 0 | CheckAbsoluteDestination(helper, *destination); |
1928 | | |
1929 | | // Create the directory install generator. |
1930 | 0 | helper.Makefile->AddInstallGenerator( |
1931 | 0 | cm::make_unique<cmInstallDirectoryGenerator>( |
1932 | 0 | dirs, *destination, permissionsFile, permissionsDir, configurations, |
1933 | 0 | component, message, excludeFromAll, literalArgs, optional, |
1934 | 0 | helper.CaptureContext())); |
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 exportNamespace; |
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, exportNamespace); |
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 for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
1984 | 0 | CheckAbsoluteDestination(helper, ica.GetDestination()); |
1985 | | |
1986 | | // Check the file name. |
1987 | 0 | std::string fname = filename; |
1988 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
1989 | 0 | status.SetError(cmStrCat(args[0], " given invalid export file name \"", |
1990 | 0 | fname, |
1991 | 0 | "\". The FILE argument may not contain a path. " |
1992 | 0 | "Specify the path in the DESTINATION argument.")); |
1993 | 0 | return false; |
1994 | 0 | } |
1995 | | |
1996 | | // Check the file extension. |
1997 | 0 | if (!fname.empty() && !cmHasSuffix(fname, ".mk"_s)) { |
1998 | 0 | status.SetError(cmStrCat( |
1999 | 0 | args[0], " given invalid export file name \"", fname, |
2000 | 0 | R"(". The FILE argument must specify a name ending in ".mk".)")); |
2001 | 0 | return false; |
2002 | 0 | } |
2003 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
2004 | 0 | status.SetError( |
2005 | 0 | cmStrCat(args[0], " given export name \"", exp, |
2006 | 0 | "\". " |
2007 | 0 | "This name cannot be safely converted to a file name. " |
2008 | 0 | "Specify a different export name or use the FILE option to set " |
2009 | 0 | "a file name explicitly.")); |
2010 | 0 | return false; |
2011 | 0 | } |
2012 | | // Use the default name |
2013 | 0 | if (fname.empty()) { |
2014 | 0 | fname = "Android.mk"; |
2015 | 0 | } |
2016 | |
|
2017 | 0 | cmExportSet& exportSet = |
2018 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp]; |
2019 | |
|
2020 | 0 | cmInstallGenerator::MessageLevel message = |
2021 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2022 | | |
2023 | | // Tell the global generator about any installation component names |
2024 | | // specified |
2025 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2026 | 0 | ica.GetComponent()); |
2027 | | |
2028 | | // Create the export install generator. |
2029 | 0 | helper.Makefile->AddInstallGenerator( |
2030 | 0 | cm::make_unique<cmInstallAndroidMKExportGenerator>( |
2031 | 0 | &exportSet, ica.GetDestination(), ica.GetPermissions(), |
2032 | 0 | ica.GetConfigurations(), ica.GetComponent(), message, |
2033 | 0 | ica.GetExcludeFromAll(), std::move(fname), std::move(exportNamespace), |
2034 | 0 | helper.CaptureContext())); |
2035 | |
|
2036 | 0 | return true; |
2037 | | #else |
2038 | | static_cast<void>(args); |
2039 | | status.SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake"); |
2040 | | return false; |
2041 | | #endif |
2042 | 0 | } |
2043 | | |
2044 | | #ifndef CMAKE_BOOTSTRAP |
2045 | | cm::optional<cm::string_view> MatchExport(cm::string_view directive, |
2046 | | std::string const& exportName) |
2047 | 0 | { |
2048 | 0 | std::string::size_type const l = exportName.size(); |
2049 | 0 | if (directive.substr(0, l) == exportName) { |
2050 | 0 | if (directive.size() > l && directive[l] == ':') { |
2051 | 0 | return directive.substr(l + 1); |
2052 | 0 | } |
2053 | 0 | } |
2054 | 0 | return cm::nullopt; |
2055 | 0 | } |
2056 | | |
2057 | | void AssignValue(std::string& dest, std::string const& value) |
2058 | 0 | { |
2059 | 0 | dest = value; |
2060 | 0 | } |
2061 | | |
2062 | | void AssignValue(std::vector<std::string>& dest, std::string const& value) |
2063 | 0 | { |
2064 | 0 | dest = cmList{ value }.data(); |
2065 | 0 | } |
2066 | | |
2067 | | template <typename T> |
2068 | | void GetExportArgumentFromVariable(cmMakefile const* makefile, |
2069 | | cmExportSet const& exportSet, |
2070 | | cm::string_view suffix, T& variable) |
2071 | 0 | { |
2072 | 0 | std::string const& name = |
2073 | 0 | cmStrCat(exportSet.GetName(), "_EXPORT_PACKAGE_INFO_"_s, suffix); |
2074 | 0 | if (cmValue const& value = makefile->GetDefinition(name)) { |
2075 | 0 | std::string realValue; |
2076 | 0 | makefile->ConfigureString(value, realValue, true, false); |
2077 | 0 | AssignValue(variable, realValue); |
2078 | 0 | } |
2079 | 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> > > > >&) |
2080 | | |
2081 | | bool HandleMappedPackageInfo( |
2082 | | cmExportSet& exportSet, cm::string_view directive, Helper& helper, |
2083 | | cmInstallCommandArguments const& installCommandArgs, |
2084 | | cmExecutionStatus& status, cmInstallGenerator::MessageLevel message, |
2085 | | std::string const& cxxModulesDirectory) |
2086 | 0 | { |
2087 | 0 | cmPackageInfoArguments arguments; |
2088 | | |
2089 | | // Extract information from the directive. |
2090 | 0 | std::string::size_type const n = directive.find('/'); |
2091 | 0 | if (n != std::string::npos) { |
2092 | 0 | arguments.PackageName = std::string{ directive.substr(0, n) }; |
2093 | 0 | directive = directive.substr(n + 1); |
2094 | |
|
2095 | 0 | if (!directive.empty() && directive[0] == 'l') { |
2096 | 0 | arguments.LowerCase = true; |
2097 | 0 | directive = directive.substr(1); |
2098 | 0 | } |
2099 | |
|
2100 | 0 | if (!directive.empty() && directive[0] == 'a') { |
2101 | 0 | std::string::size_type const d = directive.find('/'); |
2102 | 0 | if (d != std::string::npos) { |
2103 | 0 | arguments.Appendix = std::string{ directive.substr(1, d - 1) }; |
2104 | 0 | directive = directive.substr(d); |
2105 | 0 | } else { |
2106 | 0 | arguments.Appendix = std::string{ directive.substr(1) }; |
2107 | 0 | directive = {}; |
2108 | 0 | } |
2109 | |
|
2110 | 0 | if (arguments.Appendix.empty()) { |
2111 | 0 | status.SetError(cmStrCat( |
2112 | 0 | "CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO given APPENDIX " |
2113 | 0 | R"(directive for export ")"_s, |
2114 | 0 | exportSet.GetName(), R"(", but no appendix name was provided.)"_s)); |
2115 | 0 | return false; |
2116 | 0 | } |
2117 | 0 | } |
2118 | | |
2119 | 0 | if (!directive.empty()) { |
2120 | 0 | if (directive[0] != '/') { |
2121 | 0 | status.SetError( |
2122 | 0 | cmStrCat("CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO given unrecognized " |
2123 | 0 | R"(directive ")"_s, |
2124 | 0 | directive, R"(".)"_s)); |
2125 | 0 | return false; |
2126 | 0 | } |
2127 | | |
2128 | 0 | directive = directive.substr(1); |
2129 | 0 | } |
2130 | 0 | } else { |
2131 | 0 | arguments.PackageName = std::string{ directive }; |
2132 | 0 | directive = {}; |
2133 | 0 | } |
2134 | | |
2135 | 0 | if (arguments.PackageName.empty()) { |
2136 | 0 | status.SetError( |
2137 | 0 | cmStrCat("CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO missing package name " |
2138 | 0 | R"(for export ")"_s, |
2139 | 0 | exportSet.GetName(), R"(".)"_s)); |
2140 | 0 | return false; |
2141 | 0 | } |
2142 | | |
2143 | | // Build destination. |
2144 | 0 | std::string dest = std::string{ directive }; |
2145 | 0 | if (dest.empty()) { |
2146 | 0 | if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") { |
2147 | 0 | dest = arguments.GetDefaultDestination(); |
2148 | 0 | } else { |
2149 | 0 | dest = |
2150 | 0 | arguments.GetDefaultDestination(helper.GetLibraryDestination(nullptr)); |
2151 | 0 | } |
2152 | 0 | } |
2153 | | |
2154 | | // Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
2155 | 0 | CheckAbsoluteDestination(helper, dest); |
2156 | |
|
2157 | 0 | if (arguments.Appendix.empty()) { |
2158 | | // Get additional export information from variables. |
2159 | 0 | GetExportArgumentFromVariable( // BR |
2160 | 0 | helper.Makefile, exportSet, "VERSION"_s, arguments.Version); |
2161 | 0 | GetExportArgumentFromVariable( // BR |
2162 | 0 | helper.Makefile, exportSet, "COMPAT_VERSION"_s, arguments.VersionCompat); |
2163 | 0 | GetExportArgumentFromVariable( // BR |
2164 | 0 | helper.Makefile, exportSet, "VERSION_SCHEMA"_s, arguments.VersionSchema); |
2165 | 0 | GetExportArgumentFromVariable( // BR |
2166 | 0 | helper.Makefile, exportSet, "LICENSE"_s, arguments.License); |
2167 | 0 | GetExportArgumentFromVariable( // BR |
2168 | 0 | helper.Makefile, exportSet, "DEFAULT_LICENSE"_s, |
2169 | 0 | arguments.DefaultLicense); |
2170 | 0 | GetExportArgumentFromVariable( // BR |
2171 | 0 | helper.Makefile, exportSet, "DEFAULT_CONFIGURATIONS"_s, |
2172 | 0 | arguments.DefaultConfigs); |
2173 | 0 | } |
2174 | | |
2175 | | // Sanity-check export information. |
2176 | 0 | if (!arguments.Check(status)) { |
2177 | 0 | return false; |
2178 | 0 | } |
2179 | | |
2180 | | // Create the package info generator. |
2181 | 0 | helper.Makefile->AddInstallGenerator( |
2182 | 0 | cm::make_unique<cmInstallPackageInfoExportGenerator>( |
2183 | 0 | &exportSet, dest, installCommandArgs.GetPermissions(), |
2184 | 0 | installCommandArgs.GetConfigurations(), |
2185 | 0 | installCommandArgs.GetComponent(), message, |
2186 | 0 | installCommandArgs.GetExcludeFromAll(), std::move(arguments), |
2187 | 0 | cxxModulesDirectory, helper.CaptureContext())); |
2188 | |
|
2189 | 0 | return true; |
2190 | 0 | } |
2191 | | #endif |
2192 | | |
2193 | | bool HandleExportMode(std::vector<std::string> const& args, |
2194 | | cmExecutionStatus& status) |
2195 | 0 | { |
2196 | 0 | Helper helper(status); |
2197 | | |
2198 | | // This is the EXPORT mode. |
2199 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
2200 | |
|
2201 | 0 | std::string exp; |
2202 | 0 | std::string exportNamespace; |
2203 | 0 | bool exportOld = false; |
2204 | 0 | std::string filename; |
2205 | 0 | std::string cxxModulesDirectory; |
2206 | 0 | bool exportPackageDependencies = false; |
2207 | |
|
2208 | 0 | ica.Bind("EXPORT"_s, exp); |
2209 | 0 | ica.Bind("NAMESPACE"_s, exportNamespace); |
2210 | 0 | ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld); |
2211 | 0 | ica.Bind("FILE"_s, filename); |
2212 | 0 | ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); |
2213 | |
|
2214 | 0 | if (cmExperimental::HasSupportEnabled( |
2215 | 0 | status.GetMakefile(), |
2216 | 0 | cmExperimental::Feature::ExportPackageDependencies)) { |
2217 | 0 | ica.Bind("EXPORT_PACKAGE_DEPENDENCIES"_s, exportPackageDependencies); |
2218 | 0 | } |
2219 | |
|
2220 | 0 | std::vector<std::string> unknownArgs; |
2221 | 0 | ica.Parse(args, &unknownArgs); |
2222 | |
|
2223 | 0 | if (!unknownArgs.empty()) { |
2224 | | // Unknown argument. |
2225 | 0 | status.SetError( |
2226 | 0 | cmStrCat(args[0], " given unknown argument \"", unknownArgs[0], "\".")); |
2227 | 0 | return false; |
2228 | 0 | } |
2229 | | |
2230 | 0 | if (!ica.Finalize()) { |
2231 | 0 | return false; |
2232 | 0 | } |
2233 | | |
2234 | 0 | if (exp.empty()) { |
2235 | 0 | status.SetError(cmStrCat(args[0], " missing EXPORT.")); |
2236 | 0 | return false; |
2237 | 0 | } |
2238 | | |
2239 | | // Make sure there is a destination. |
2240 | 0 | if (ica.GetDestination().empty()) { |
2241 | | // A destination is required. |
2242 | 0 | status.SetError(cmStrCat(args[0], " given no DESTINATION!")); |
2243 | 0 | return false; |
2244 | 0 | } |
2245 | | |
2246 | | // Check the file name. |
2247 | 0 | std::string fname = filename; |
2248 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
2249 | 0 | status.SetError(cmStrCat(args[0], " given invalid export file name \"", |
2250 | 0 | fname, |
2251 | 0 | "\". " |
2252 | 0 | "The FILE argument may not contain a path. " |
2253 | 0 | "Specify the path in the DESTINATION argument.")); |
2254 | 0 | return false; |
2255 | 0 | } |
2256 | | |
2257 | | // Check the file extension. |
2258 | 0 | if (!fname.empty() && !cmHasSuffix(fname, ".cmake"_s)) { |
2259 | 0 | status.SetError( |
2260 | 0 | cmStrCat(args[0], " given invalid export file name \"", fname, |
2261 | 0 | "\". " |
2262 | 0 | "The FILE argument must specify a name ending in \".cmake\".")); |
2263 | 0 | return false; |
2264 | 0 | } |
2265 | | |
2266 | | // Construct the file name. |
2267 | 0 | if (fname.empty()) { |
2268 | 0 | fname = cmStrCat(exp, ".cmake"); |
2269 | |
|
2270 | 0 | if (fname.find_first_of(":/\\") != std::string::npos) { |
2271 | 0 | status.SetError(cmStrCat( |
2272 | 0 | args[0], " given export name \"", exp, |
2273 | 0 | "\". " |
2274 | 0 | "This name cannot be safely converted to a file name. " |
2275 | 0 | "Specify a different export name or use the FILE option to set " |
2276 | 0 | "a file name explicitly.")); |
2277 | 0 | return false; |
2278 | 0 | } |
2279 | 0 | } |
2280 | | |
2281 | 0 | cmExportSet& exportSet = |
2282 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exp]; |
2283 | |
|
2284 | 0 | cmInstallGenerator::MessageLevel message = |
2285 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2286 | | |
2287 | | // Tell the global generator about any installation component names |
2288 | | // specified |
2289 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2290 | 0 | ica.GetComponent()); |
2291 | |
|
2292 | 0 | #ifndef CMAKE_BOOTSTRAP |
2293 | | // Check if PACKAGE_INFO export has been requested for this export set. |
2294 | 0 | if (cmExperimental::HasSupportEnabled( |
2295 | 0 | status.GetMakefile(), cmExperimental::Feature::MappedPackageInfo)) { |
2296 | 0 | if (cmValue const& piExports = helper.Makefile->GetDefinition( |
2297 | 0 | "CMAKE_INSTALL_EXPORTS_AS_PACKAGE_INFO")) { |
2298 | 0 | for (auto const& pie : cmList{ piExports }) { |
2299 | 0 | cm::optional<cm::string_view> const directive = MatchExport(pie, exp); |
2300 | 0 | if (directive) { |
2301 | 0 | if (!HandleMappedPackageInfo(exportSet, *directive, helper, ica, |
2302 | 0 | status, message, cxxModulesDirectory)) { |
2303 | 0 | return false; |
2304 | 0 | } |
2305 | 0 | } |
2306 | 0 | } |
2307 | 0 | } |
2308 | 0 | } |
2309 | 0 | #endif |
2310 | | |
2311 | | // Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
2312 | 0 | CheckAbsoluteDestination(helper, ica.GetDestination()); |
2313 | | |
2314 | | // Create the export install generator. |
2315 | 0 | helper.Makefile->AddInstallGenerator( |
2316 | 0 | cm::make_unique<cmInstallCMakeConfigExportGenerator>( |
2317 | 0 | &exportSet, ica.GetDestination(), ica.GetPermissions(), |
2318 | 0 | ica.GetConfigurations(), ica.GetComponent(), message, |
2319 | 0 | ica.GetExcludeFromAll(), std::move(fname), std::move(exportNamespace), |
2320 | 0 | std::move(cxxModulesDirectory), exportOld, exportPackageDependencies, |
2321 | 0 | helper.CaptureContext())); |
2322 | |
|
2323 | 0 | return true; |
2324 | 0 | } |
2325 | | |
2326 | | bool HandlePackageInfoMode(std::vector<std::string> const& args, |
2327 | | cmExecutionStatus& status) |
2328 | 0 | { |
2329 | 0 | #ifndef CMAKE_BOOTSTRAP |
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 = arguments.GetDefaultDestination(); |
2368 | 0 | } else { |
2369 | 0 | dest = |
2370 | 0 | arguments.GetDefaultDestination(helper.GetLibraryDestination(nullptr)); |
2371 | 0 | } |
2372 | 0 | } |
2373 | | |
2374 | | // Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
2375 | 0 | CheckAbsoluteDestination(helper, dest); |
2376 | |
|
2377 | 0 | cmExportSet& exportSet = |
2378 | 0 | helper.Makefile->GetGlobalGenerator()->GetExportSets()[exportName]; |
2379 | |
|
2380 | 0 | cmInstallGenerator::MessageLevel message = |
2381 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2382 | | |
2383 | | // Tell the global generator about any installation component names |
2384 | | // specified |
2385 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2386 | 0 | ica.GetComponent()); |
2387 | | |
2388 | | // Create the export install generator. |
2389 | 0 | helper.Makefile->AddInstallGenerator( |
2390 | 0 | cm::make_unique<cmInstallPackageInfoExportGenerator>( |
2391 | 0 | &exportSet, dest, ica.GetPermissions(), ica.GetConfigurations(), |
2392 | 0 | ica.GetComponent(), message, ica.GetExcludeFromAll(), |
2393 | 0 | std::move(arguments), std::move(cxxModulesDirectory), |
2394 | 0 | helper.CaptureContext())); |
2395 | |
|
2396 | 0 | return true; |
2397 | | #else |
2398 | | static_cast<void>(args); |
2399 | | status.SetError("PACKAGE_INFO not supported in bootstrap cmake"); |
2400 | | return false; |
2401 | | #endif |
2402 | 0 | } |
2403 | | |
2404 | | bool HandleRuntimeDependencySetMode(std::vector<std::string> const& args, |
2405 | | cmExecutionStatus& status) |
2406 | 0 | { |
2407 | 0 | Helper helper(status); |
2408 | |
|
2409 | 0 | auto system = helper.Makefile->GetSafeDefinition("CMAKE_HOST_SYSTEM_NAME"); |
2410 | 0 | if (!cmRuntimeDependencyArchive::PlatformSupportsRuntimeDependencies( |
2411 | 0 | system)) { |
2412 | 0 | status.SetError(cmStrCat( |
2413 | 0 | "RUNTIME_DEPENDENCY_SET is not supported on system \"", system, '"')); |
2414 | 0 | return false; |
2415 | 0 | } |
2416 | | |
2417 | | // This is the RUNTIME_DEPENDENCY_SET mode. |
2418 | 0 | cmInstallRuntimeDependencySet* runtimeDependencySet; |
2419 | |
|
2420 | 0 | struct ArgVectors |
2421 | 0 | { |
2422 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Library; |
2423 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Runtime; |
2424 | 0 | ArgumentParser::MaybeEmpty<std::vector<std::string>> Framework; |
2425 | 0 | }; |
2426 | |
|
2427 | 0 | static auto const argHelper = cmArgumentParser<ArgVectors>{} |
2428 | 0 | .Bind("LIBRARY"_s, &ArgVectors::Library) |
2429 | 0 | .Bind("RUNTIME"_s, &ArgVectors::Runtime) |
2430 | 0 | .Bind("FRAMEWORK"_s, &ArgVectors::Framework); |
2431 | |
|
2432 | 0 | std::vector<std::string> genericArgVector; |
2433 | 0 | ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector); |
2434 | | |
2435 | | // now parse the generic args (i.e. the ones not specialized on LIBRARY, |
2436 | | // RUNTIME, FRAMEWORK etc. (see above) |
2437 | | // These generic args also contain the runtime dependency set |
2438 | 0 | std::string runtimeDependencySetArg; |
2439 | 0 | std::vector<std::string> runtimeDependencyArgVector; |
2440 | 0 | cmInstallCommandArguments genericArgs(helper.DefaultComponentName, |
2441 | 0 | *helper.Makefile); |
2442 | 0 | genericArgs.Bind("RUNTIME_DEPENDENCY_SET"_s, runtimeDependencySetArg); |
2443 | 0 | genericArgs.Parse(genericArgVector, &runtimeDependencyArgVector); |
2444 | 0 | bool success = genericArgs.Finalize(); |
2445 | |
|
2446 | 0 | cmInstallCommandArguments libraryArgs(helper.DefaultComponentName, |
2447 | 0 | *helper.Makefile); |
2448 | 0 | cmInstallCommandArguments runtimeArgs(helper.DefaultComponentName, |
2449 | 0 | *helper.Makefile); |
2450 | 0 | cmInstallCommandArguments frameworkArgs(helper.DefaultComponentName, |
2451 | 0 | *helper.Makefile); |
2452 | | |
2453 | | // Now also parse the file(GET_RUNTIME_DEPENDENCY) args |
2454 | 0 | std::vector<std::string> unknownArgs; |
2455 | 0 | auto runtimeDependencyArgs = RuntimeDependenciesArgHelper.Parse( |
2456 | 0 | runtimeDependencyArgVector, &unknownArgs); |
2457 | | |
2458 | | // now parse the args for specific parts of the target (e.g. LIBRARY, |
2459 | | // RUNTIME, FRAMEWORK etc. |
2460 | 0 | libraryArgs.Parse(argVectors.Library, &unknownArgs); |
2461 | 0 | runtimeArgs.Parse(argVectors.Runtime, &unknownArgs); |
2462 | 0 | frameworkArgs.Parse(argVectors.Framework, &unknownArgs); |
2463 | |
|
2464 | 0 | libraryArgs.SetGenericArguments(&genericArgs); |
2465 | 0 | runtimeArgs.SetGenericArguments(&genericArgs); |
2466 | 0 | frameworkArgs.SetGenericArguments(&genericArgs); |
2467 | |
|
2468 | 0 | success = success && libraryArgs.Finalize(); |
2469 | 0 | success = success && runtimeArgs.Finalize(); |
2470 | 0 | success = success && frameworkArgs.Finalize(); |
2471 | |
|
2472 | 0 | if (!success) { |
2473 | 0 | return false; |
2474 | 0 | } |
2475 | | |
2476 | 0 | if (!unknownArgs.empty()) { |
2477 | 0 | helper.SetError( |
2478 | 0 | cmStrCat("RUNTIME_DEPENDENCY_SET given unknown argument \"", |
2479 | 0 | unknownArgs.front(), "\".")); |
2480 | 0 | return false; |
2481 | 0 | } |
2482 | | |
2483 | 0 | if (runtimeDependencySetArg.empty()) { |
2484 | 0 | helper.SetError( |
2485 | 0 | "RUNTIME_DEPENDENCY_SET not given a runtime dependency set."); |
2486 | 0 | return false; |
2487 | 0 | } |
2488 | | |
2489 | 0 | runtimeDependencySet = |
2490 | 0 | helper.Makefile->GetGlobalGenerator()->GetNamedRuntimeDependencySet( |
2491 | 0 | runtimeDependencySetArg); |
2492 | |
|
2493 | 0 | bool installsRuntime = false; |
2494 | 0 | bool installsLibrary = false; |
2495 | 0 | bool installsFramework = false; |
2496 | |
|
2497 | 0 | AddInstallRuntimeDependenciesGenerator( |
2498 | 0 | helper, runtimeDependencySet, runtimeArgs, libraryArgs, frameworkArgs, |
2499 | 0 | std::move(runtimeDependencyArgs), installsRuntime, installsLibrary, |
2500 | 0 | installsFramework); |
2501 | | |
2502 | | // Tell the global generator about any installation component names |
2503 | | // specified |
2504 | 0 | if (installsLibrary) { |
2505 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2506 | 0 | libraryArgs.GetComponent()); |
2507 | 0 | } |
2508 | 0 | if (installsRuntime) { |
2509 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2510 | 0 | runtimeArgs.GetComponent()); |
2511 | 0 | } |
2512 | 0 | if (installsFramework) { |
2513 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2514 | 0 | frameworkArgs.GetComponent()); |
2515 | 0 | } |
2516 | |
|
2517 | 0 | return true; |
2518 | 0 | } |
2519 | | |
2520 | | bool HandleSbomMode(std::vector<std::string> const& args, |
2521 | | cmExecutionStatus& status) |
2522 | 0 | { |
2523 | 0 | #ifndef CMAKE_BOOTSTRAP |
2524 | 0 | if (!cmExperimental::HasSupportEnabled( |
2525 | 0 | status.GetMakefile(), cmExperimental::Feature::GenerateSbom)) { |
2526 | 0 | status.SetError("does not recognize sub-command SBOM"); |
2527 | 0 | return false; |
2528 | 0 | } |
2529 | | |
2530 | 0 | Helper helper(status); |
2531 | 0 | cmInstallCommandArguments ica(helper.DefaultComponentName, *helper.Makefile); |
2532 | |
|
2533 | 0 | cmSbomArguments arguments; |
2534 | 0 | ArgumentParser::NonEmpty<std::vector<std::string>> exportNames; |
2535 | |
|
2536 | 0 | arguments.Bind(ica); |
2537 | 0 | ica.Bind("EXPORTS"_s, exportNames); |
2538 | | // ica.Bind("CXX_MODULES_DIRECTORY"_s, cxxModulesDirectory); TODO? |
2539 | |
|
2540 | 0 | std::vector<std::string> unknownArgs; |
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 (exportNames.empty()) { |
2557 | 0 | status.SetError(cmStrCat(args[0], " missing EXPORTS.")); |
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 | dest = |
2569 | 0 | arguments.GetDefaultDestination(helper.GetLibraryDestination(nullptr)); |
2570 | 0 | } |
2571 | | |
2572 | | // Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics. |
2573 | 0 | CheckAbsoluteDestination(helper, dest); |
2574 | |
|
2575 | 0 | cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator(); |
2576 | |
|
2577 | 0 | std::string const fpath = cmStrCat(dest, '/', arguments.GetPackageName()); |
2578 | 0 | if (gg->IsInstallSbomFile(fpath)) { |
2579 | 0 | status.SetError(cmStrCat("SBOM command already specified for the file "_s, |
2580 | 0 | cmSystemTools::GetFilenameNameView(fpath), '.')); |
2581 | 0 | return false; |
2582 | 0 | } |
2583 | | |
2584 | 0 | cmExportSetMap& allExportSets = gg->GetExportSets(); |
2585 | 0 | std::vector<cmExportSet*> sets; |
2586 | 0 | sets.reserve(exportNames.size()); |
2587 | 0 | for (std::string const& name : exportNames) { |
2588 | 0 | sets.push_back(&allExportSets[name]); |
2589 | 0 | } |
2590 | |
|
2591 | 0 | cmInstallGenerator::MessageLevel message = |
2592 | 0 | cmInstallGenerator::SelectMessageLevel(helper.Makefile); |
2593 | | |
2594 | | // Tell the global generator about any installation component names |
2595 | | // specified. |
2596 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallComponent( |
2597 | 0 | ica.GetComponent()); |
2598 | | |
2599 | | // Create the SBOM install generator. |
2600 | 0 | auto sbomGen = cm::make_unique<cmInstallSbomGenerator>( |
2601 | 0 | std::move(sets), dest, ica.GetPermissions(), ica.GetConfigurations(), |
2602 | 0 | ica.GetComponent(), message, ica.GetExcludeFromAll(), std::move(arguments), |
2603 | 0 | helper.CaptureContext()); |
2604 | 0 | cmInstallSbomGenerator const* rawPtr = sbomGen.get(); |
2605 | 0 | helper.Makefile->AddInstallGenerator(std::move(sbomGen)); |
2606 | 0 | helper.Makefile->GetGlobalGenerator()->AddInstallSbomGenerator(rawPtr); |
2607 | |
|
2608 | 0 | return true; |
2609 | | #else |
2610 | | static_cast<void>(args); |
2611 | | status.SetError("SBOM not supported in bootstrap cmake"); |
2612 | | return false; |
2613 | | #endif |
2614 | 0 | } |
2615 | | |
2616 | | bool Helper::MakeFilesFullPath(char const* modeName, |
2617 | | std::vector<std::string> const& relFiles, |
2618 | | std::vector<std::string>& absFiles) |
2619 | 0 | { |
2620 | 0 | return this->MakeFilesFullPath( |
2621 | 0 | modeName, this->Makefile->GetCurrentSourceDirectory(), relFiles, absFiles); |
2622 | 0 | } |
2623 | | |
2624 | | bool Helper::MakeFilesFullPath(char const* modeName, |
2625 | | std::string const& basePath, |
2626 | | std::vector<std::string> const& relFiles, |
2627 | | std::vector<std::string>& absFiles) |
2628 | 0 | { |
2629 | 0 | for (std::string const& relFile : relFiles) { |
2630 | 0 | std::string file = relFile; |
2631 | 0 | std::string::size_type gpos = cmGeneratorExpression::Find(file); |
2632 | 0 | if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) { |
2633 | 0 | file = cmStrCat(basePath, '/', relFile); |
2634 | 0 | } |
2635 | | |
2636 | | // Make sure the file is not a directory. |
2637 | 0 | if (gpos == std::string::npos && !cmSystemTools::FileIsSymlink(file) && |
2638 | 0 | cmSystemTools::FileIsDirectory(file)) { |
2639 | 0 | this->SetError( |
2640 | 0 | cmStrCat(modeName, " given directory \"", relFile, "\" to install.")); |
2641 | 0 | return false; |
2642 | 0 | } |
2643 | | // Store the file for installation. |
2644 | 0 | absFiles.push_back(std::move(file)); |
2645 | 0 | } |
2646 | 0 | return true; |
2647 | 0 | } |
2648 | | |
2649 | | std::string Helper::GetRuntimeDestination( |
2650 | | cmInstallCommandArguments const* args) const |
2651 | 0 | { |
2652 | 0 | if (args && !args->GetDestination().empty()) { |
2653 | 0 | return args->GetDestination(); |
2654 | 0 | } |
2655 | 0 | return cm::InstallDirs::GetRuntimeDirectory(this->Makefile); |
2656 | 0 | } |
2657 | | |
2658 | | std::string Helper::GetArchiveDestination( |
2659 | | cmInstallCommandArguments const* args) const |
2660 | 0 | { |
2661 | 0 | if (args && !args->GetDestination().empty()) { |
2662 | 0 | return args->GetDestination(); |
2663 | 0 | } |
2664 | 0 | return cm::InstallDirs::GetArchiveDirectory(this->Makefile); |
2665 | 0 | } |
2666 | | |
2667 | | std::string Helper::GetLibraryDestination( |
2668 | | cmInstallCommandArguments const* args) const |
2669 | 0 | { |
2670 | 0 | if (args && !args->GetDestination().empty()) { |
2671 | 0 | return args->GetDestination(); |
2672 | 0 | } |
2673 | 0 | return cm::InstallDirs::GetLibraryDirectory(this->Makefile); |
2674 | 0 | } |
2675 | | |
2676 | | std::string Helper::GetCxxModulesBmiDestination( |
2677 | | cmInstallCommandArguments const* args) const |
2678 | 0 | { |
2679 | 0 | if (args) { |
2680 | 0 | return args->GetDestination(); |
2681 | 0 | } |
2682 | 0 | return {}; |
2683 | 0 | } |
2684 | | |
2685 | | std::string Helper::GetIncludeDestination( |
2686 | | cmInstallCommandArguments const* args) const |
2687 | 0 | { |
2688 | 0 | if (args && !args->GetDestination().empty()) { |
2689 | 0 | return args->GetDestination(); |
2690 | 0 | } |
2691 | 0 | return cm::InstallDirs::GetIncludeDirectory(this->Makefile); |
2692 | 0 | } |
2693 | | |
2694 | | std::string Helper::GetDestinationForType( |
2695 | | cmInstallCommandArguments const* args, std::string const& type) const |
2696 | 0 | { |
2697 | 0 | if (args && !args->GetDestination().empty()) { |
2698 | 0 | return args->GetDestination(); |
2699 | 0 | } |
2700 | 0 | return cm::InstallDirs::GetDirectoryForType(this->Makefile, type); |
2701 | 0 | } |
2702 | | |
2703 | | } // namespace |
2704 | | |
2705 | | bool cmInstallCommand(std::vector<std::string> const& args, |
2706 | | cmExecutionStatus& status) |
2707 | 0 | { |
2708 | | // Allow calling with no arguments so that arguments may be built up |
2709 | | // using a variable that may be left empty. |
2710 | 0 | if (args.empty()) { |
2711 | 0 | return true; |
2712 | 0 | } |
2713 | | |
2714 | | // Enable the install target. |
2715 | 0 | status.GetMakefile().GetGlobalGenerator()->EnableInstallTarget(); |
2716 | |
|
2717 | 0 | static cmSubcommandTable const subcommand{ |
2718 | 0 | { "SCRIPT"_s, HandleScriptMode }, |
2719 | 0 | { "CODE"_s, HandleScriptMode }, |
2720 | 0 | { "TARGETS"_s, HandleTargetsMode }, |
2721 | 0 | { "IMPORTED_RUNTIME_ARTIFACTS"_s, HandleImportedRuntimeArtifactsMode }, |
2722 | 0 | { "FILES"_s, HandleFilesMode }, |
2723 | 0 | { "PROGRAMS"_s, HandleFilesMode }, |
2724 | 0 | { "DIRECTORY"_s, HandleDirectoryMode }, |
2725 | 0 | { "EXPORT"_s, HandleExportMode }, |
2726 | 0 | { "EXPORT_ANDROID_MK"_s, HandleExportAndroidMKMode }, |
2727 | 0 | { "PACKAGE_INFO"_s, HandlePackageInfoMode }, |
2728 | 0 | { "RUNTIME_DEPENDENCY_SET"_s, HandleRuntimeDependencySetMode }, |
2729 | 0 | { "SBOM"_s, HandleSbomMode } |
2730 | 0 | }; |
2731 | |
|
2732 | 0 | return subcommand(args[0], args, status); |
2733 | 0 | } |