Coverage Report

Created: 2026-06-15 07:03

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
12
cmInstallFilesGenerator::cmInstallFilesGenerator(
13
  std::vector<std::string> const& files, std::string const& dest,
14
  bool programs, std::string filePermissions,
15
  std::vector<std::string> const& configurations, std::string const& component,
16
  MessageLevel message, bool excludeFromAll, std::string rename, bool optional,
17
  cmDiagnosticContext context)
18
0
  : cmInstallGenerator(dest, configurations, component, message,
19
0
                       excludeFromAll, false, std::move(context))
20
0
  , Files(files)
21
0
  , FilePermissions(std::move(filePermissions))
22
0
  , Rename(std::move(rename))
23
0
  , Programs(programs)
24
0
  , Optional(optional)
25
0
{
26
  // We need per-config actions if the destination and rename have generator
27
  // expressions.
28
0
  if (cmGeneratorExpression::Find(this->Destination) != std::string::npos) {
29
0
    this->ActionsPerConfig = true;
30
0
  }
31
0
  if (cmGeneratorExpression::Find(this->Rename) != std::string::npos) {
32
0
    this->ActionsPerConfig = true;
33
0
  }
34
35
  // We need per-config actions if any directories have generator expressions.
36
0
  if (!this->ActionsPerConfig) {
37
0
    for (std::string const& file : files) {
38
0
      if (cmGeneratorExpression::Find(file) != std::string::npos) {
39
0
        this->ActionsPerConfig = true;
40
0
        break;
41
0
      }
42
0
    }
43
0
  }
44
0
}
45
46
0
cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
47
48
bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
49
0
{
50
0
  this->LocalGenerator = lg;
51
0
  return true;
52
0
}
53
54
std::string cmInstallFilesGenerator::GetDestination(
55
  std::string const& config) const
56
0
{
57
0
  std::string dest = cmGeneratorExpression::Evaluate(
58
0
    this->Destination, this->LocalGenerator, config);
59
0
  this->CheckAbsoluteDestination(dest, this->LocalGenerator);
60
0
  return dest;
61
0
}
62
63
std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
64
0
{
65
0
  return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
66
0
                                         config);
67
0
}
68
69
std::vector<std::string> cmInstallFilesGenerator::GetFiles(
70
  std::string const& config) const
71
0
{
72
0
  if (this->ActionsPerConfig) {
73
0
    cmList files;
74
0
    for (std::string const& f : this->Files) {
75
0
      files.append(
76
0
        cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
77
0
    }
78
0
    return std::move(files.data());
79
0
  }
80
0
  return this->Files;
81
0
}
82
83
void cmInstallFilesGenerator::AddFilesInstallRule(
84
  std::ostream& os, std::string const& config, Indent indent,
85
  std::vector<std::string> const& files)
86
0
{
87
  // Write code to install the files.
88
0
  char const* noDirPermissions = nullptr;
89
0
  this->AddInstallRule(
90
0
    os, this->GetDestination(config),
91
0
    (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
92
0
    this->Optional, this->FilePermissions.c_str(), noDirPermissions,
93
0
    this->GetRename(config).c_str(), nullptr, indent);
94
0
}
95
96
void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
97
                                                    Indent indent)
98
0
{
99
0
  if (this->ActionsPerConfig) {
100
0
    this->cmInstallGenerator::GenerateScriptActions(os, indent);
101
0
  } else {
102
0
    this->AddFilesInstallRule(os, "", indent, this->Files);
103
0
  }
104
0
}
105
106
void cmInstallFilesGenerator::GenerateScriptForConfig(
107
  std::ostream& os, std::string const& config, Indent indent)
108
0
{
109
0
  std::vector<std::string> files = this->GetFiles(config);
110
0
  this->AddFilesInstallRule(os, config, indent, files);
111
0
}