Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmInstallScriptGenerator.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 "cmInstallScriptGenerator.h"
4
5
#include <ostream>
6
#include <utility>
7
#include <vector>
8
9
#include "cmGeneratorExpression.h"
10
#include "cmLocalGenerator.h"
11
#include "cmMessageType.h"
12
#include "cmPolicies.h"
13
#include "cmScriptGenerator.h"
14
15
cmInstallScriptGenerator::cmInstallScriptGenerator(
16
  std::string script, bool code, std::string const& component,
17
  bool exclude_from_all, bool all_components, cmListFileBacktrace backtrace)
18
0
  : cmInstallGenerator("", std::vector<std::string>(), component,
19
0
                       MessageDefault, exclude_from_all, all_components,
20
0
                       std::move(backtrace))
21
0
  , Script(std::move(script))
22
0
  , Code(code)
23
0
{
24
  // We need per-config actions if the script has generator expressions.
25
0
  if (cmGeneratorExpression::Find(this->Script) != std::string::npos) {
26
0
    this->ActionsPerConfig = true;
27
0
  }
28
0
}
29
30
0
cmInstallScriptGenerator::~cmInstallScriptGenerator() = default;
31
32
bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
33
0
{
34
0
  this->LocalGenerator = lg;
35
36
0
  if (this->ActionsPerConfig) {
37
0
    switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) {
38
0
      case cmPolicies::WARN:
39
0
        this->LocalGenerator->IssueMessage(
40
0
          MessageType::AUTHOR_WARNING,
41
0
          cmPolicies::GetPolicyWarning(cmPolicies::CMP0087));
42
0
        CM_FALLTHROUGH;
43
0
      case cmPolicies::OLD:
44
0
        break;
45
0
      case cmPolicies::NEW:
46
0
        this->AllowGenex = true;
47
0
        break;
48
0
    }
49
0
  }
50
51
0
  return true;
52
0
}
53
54
std::string cmInstallScriptGenerator::GetScript(
55
  std::string const& config) const
56
0
{
57
0
  std::string script = this->Script;
58
0
  if (this->AllowGenex && this->ActionsPerConfig) {
59
0
    cmGeneratorExpression::ReplaceInstallPrefix(script,
60
0
                                                "${CMAKE_INSTALL_PREFIX}");
61
0
    script =
62
0
      cmGeneratorExpression::Evaluate(script, this->LocalGenerator, config);
63
0
  }
64
0
  return script;
65
0
}
66
67
void cmInstallScriptGenerator::AddScriptInstallRule(
68
  std::ostream& os, Indent indent, std::string const& script) const
69
0
{
70
0
  if (this->Code) {
71
0
    os << indent << script << "\n";
72
0
  } else {
73
0
    os << indent << "include(\"" << script << "\")\n";
74
0
  }
75
0
}
76
77
void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os,
78
                                                     Indent indent)
79
0
{
80
0
  if (this->AllowGenex && this->ActionsPerConfig) {
81
0
    this->cmInstallGenerator::GenerateScriptActions(os, indent);
82
0
  } else {
83
0
    this->AddScriptInstallRule(os, indent, this->Script);
84
0
  }
85
0
}
86
87
void cmInstallScriptGenerator::GenerateScriptForConfig(
88
  std::ostream& os, std::string const& config, Indent indent)
89
0
{
90
0
  this->AddScriptInstallRule(os, indent, this->GetScript(config));
91
0
}