Coverage Report

Created: 2026-02-09 06:05

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 "cmGeneratorExpression.h"
8
#include "cmInstallType.h"
9
#include "cmList.h"
10
#include "cmListFileCache.h"
11
12
cmInstallFilesGenerator::cmInstallFilesGenerator(
13
  std::vector<std::string> const& files, std::string const& dest,
14
  bool programs, std::string file_permissions,
15
  std::vector<std::string> const& configurations, std::string const& component,
16
  MessageLevel message, bool exclude_from_all, std::string rename,
17
  bool optional, cmListFileBacktrace backtrace)
18
0
  : cmInstallGenerator(dest, configurations, component, message,
19
0
                       exclude_from_all, false, std::move(backtrace))
20
0
  , Files(files)
21
0
  , FilePermissions(std::move(file_permissions))
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
  return cmGeneratorExpression::Evaluate(this->Destination,
58
0
                                         this->LocalGenerator, config);
59
0
}
60
61
std::string cmInstallFilesGenerator::GetRename(std::string const& config) const
62
0
{
63
0
  return cmGeneratorExpression::Evaluate(this->Rename, this->LocalGenerator,
64
0
                                         config);
65
0
}
66
67
std::vector<std::string> cmInstallFilesGenerator::GetFiles(
68
  std::string const& config) const
69
0
{
70
0
  if (this->ActionsPerConfig) {
71
0
    cmList files;
72
0
    for (std::string const& f : this->Files) {
73
0
      files.append(
74
0
        cmGeneratorExpression::Evaluate(f, this->LocalGenerator, config));
75
0
    }
76
0
    return std::move(files.data());
77
0
  }
78
0
  return this->Files;
79
0
}
80
81
void cmInstallFilesGenerator::AddFilesInstallRule(
82
  std::ostream& os, std::string const& config, Indent indent,
83
  std::vector<std::string> const& files)
84
0
{
85
  // Write code to install the files.
86
0
  char const* no_dir_permissions = nullptr;
87
0
  this->AddInstallRule(
88
0
    os, this->GetDestination(config),
89
0
    (this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
90
0
    this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
91
0
    this->GetRename(config).c_str(), nullptr, indent);
92
0
}
93
94
void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
95
                                                    Indent indent)
96
0
{
97
0
  if (this->ActionsPerConfig) {
98
0
    this->cmInstallGenerator::GenerateScriptActions(os, indent);
99
0
  } else {
100
0
    this->AddFilesInstallRule(os, "", indent, this->Files);
101
0
  }
102
0
}
103
104
void cmInstallFilesGenerator::GenerateScriptForConfig(
105
  std::ostream& os, std::string const& config, Indent indent)
106
0
{
107
0
  std::vector<std::string> files = this->GetFiles(config);
108
0
  this->AddFilesInstallRule(os, config, indent, files);
109
0
}