Coverage Report

Created: 2026-10-28 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstallFilesGenerator.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 "cmInstallFilesGenerator.h"
4
5
#include <utility>
6
7
#include "cmDiagnosticContext.h"
8
#include "cmGeneratorExpression.h"
9
#include "cmInstallType.h"
10
#include "cmList.h"
11
#include "cmLocalGenerator.h"
12
13
cmInstallFilesGenerator::cmInstallFilesGenerator(
14
  std::vector<std::string> const& files, std::string const& dest,
15
  bool programs, std::string filePermissions,
16
  std::vector<std::string> const& configurations, std::string const& component,
17
  std::vector<std::string> buildDepends, MessageLevel message,
18
  bool excludeFromAll, std::string rename, bool optional,
19
  cmDiagnosticContext context)
20
0
  : cmInstallGenerator(dest, configurations, component, message,
21
0
                       excludeFromAll, false, std::move(context))
22
0
  , Files(files)
23
0
  , FilePermissions(std::move(filePermissions))
24
0
  , Rename(std::move(rename))
25
0
  , BuildDepends(std::move(buildDepends))
26
0
  , Programs(programs)
27
0
  , Optional(optional)
28
0
{
29
  // We need per-config actions if the destination and rename have generator
30
  // expressions.
31
0
  if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
32
0
    this->ActionsPerConfig = true;
33
0
  }
34
0
  if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
35
0
    this->ActionsPerConfig = true;
36
0
  }
37
38
  // We need per-config actions if any directories have generator expressions.
39
0
  if (!this->ActionsPerConfig) {
40
0
    for (std::string const& file : files) {
41
0
      if (cmGeneratorExpression::Find(file) != std::string::npos) {
42
0
        this->ActionsPerConfig = true;
43
0
        break;
44
0
      }
45
0
    }
46
0
  }
47
0
}
48
49
0
cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
50
51
bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
52
0
{
53
0
  this->LocalGenerator = lg;
54
0
  if (!this->OwningTargetName.empty()) {
55
0
    this->OwningTarget = lg->FindGeneratorTargetToUse(this->OwningTargetName);
56
0
  }
57
0
  return this->ResolveBuildDepends(lg, this->Programs ? "PROGRAMS" : "FILES",
58
0
                                   this->BuildDepends,
59
0
                                   this->ResolvedBuildDepends);
60
0
}
61
62
void cmInstallFilesGenerator::GetInstallBuildDependencies(
63
  std::string const& config, std::vector<BuildDependency>& dependencies) const
64
0
{
65
0
  AddBuildDependsDependencies(this->LocalGenerator, config,
66
0
                              this->ResolvedBuildDepends, dependencies);
67
0
  std::vector<BuildDependency> generated;
68
0
  AddGeneratedFileDependencies(this->LocalGenerator->GetGlobalGenerator(),
69
0
                               config, this->OwningTarget,
70
0
                               this->GetFiles(config), generated);
71
0
  for (BuildDependency& dependency : generated) {
72
    // A generated file that no target prepares is assumed to be produced by
73
    // the targets named by BUILD_DEPENDS, if any.
74
0
    if (dependency.Target || this->ResolvedBuildDepends.Targets.empty()) {
75
0
      dependencies.push_back(std::move(dependency));
76
0
    }
77
0
  }
78
0
}
79
80
std::string cmInstallFilesGenerator::GetDestination(
81
  std::string const& config) const
82
0
{
83
0
  std::string dest = cmGeneratorExpression::Evaluate(
84
0
    this->Destination, this->LocalGenerator, config);
85
0
  this->CheckAbsoluteDestination(dest, this->LocalGenerator);
86
0
  return dest;
87
0
}
88
89
std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
90
0
{
91
0
  return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
92
0
                                         config);
93
0
}
94
95
std::vector<std::string> cmInstallFilesGenerator::GetFiles(
96
  std::string const& config) const
97
0
{
98
0
  if (this->ActionsPerConfig) {
99
0
    cmList files;
100
0
    for (std::string const& f : this->Files) {
101
0
      files.append(
102
0
        cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
103
0
    }
104
0
    return std::move(files.data());
105
0
  }
106
0
  return this->Files;
107
0
}
108
109
void cmInstallFilesGenerator::AddFilesInstallRule(
110
  std::ostream& os, std::string const& config, Indent indent,
111
  std::vector<std::string> const& files)
112
0
{
113
  // Write code to install the files.
114
0
  char const* noDirPermissions = nullptr;
115
0
  this->AddInstallRule(
116
0
    os, this->GetDestination(config),
117
0
    (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
118
0
    this->Optional, this->FilePermissions.c_str(), noDirPermissions,
119
0
    this->GetRename(config).c_str(), nullptr, indent);
120
0
}
121
122
void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
123
                                                    Indent indent)
124
0
{
125
0
  if (this->ActionsPerConfig) {
126
0
    this->cmInstallGenerator::GenerateScriptActions(os, indent);
127
0
  } else {
128
0
    this->AddFilesInstallRule(os, "", indent, this->Files);
129
0
  }
130
0
}
131
132
void cmInstallFilesGenerator::GenerateScriptForConfig(
133
  std::ostream& os, std::string const& config, Indent indent)
134
0
{
135
0
  std::vector<std::string> files = this->GetFiles(config);
136
0
  this->AddFilesInstallRule(os, config, indent, files);
137
0
}