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