Coverage Report

Created: 2026-10-28 06:38

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