Coverage Report

Created: 2026-07-30 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmScriptGenerator.h
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
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <ostream>
8
#include <string>
9
#include <vector>
10
11
#include <cm/string_view>
12
13
class cmScriptGeneratorIndent
14
{
15
public:
16
0
  cmScriptGeneratorIndent() = default;
17
  cmScriptGeneratorIndent(int level)
18
0
    : Level(level)
19
0
  {
20
0
  }
21
  void Write(std::ostream& os) const
22
0
  {
23
0
    for (int i = 0; i < this->Level; ++i) {
24
0
      os << " ";
25
0
    }
26
0
  }
27
  cmScriptGeneratorIndent Next(int step = 2) const
28
0
  {
29
0
    return { this->Level + step };
30
0
  }
31
32
private:
33
  int Level = 0;
34
};
35
inline std::ostream& operator<<(std::ostream& os,
36
                                cmScriptGeneratorIndent indent)
37
0
{
38
0
  indent.Write(os);
39
0
  return os;
40
0
}
41
42
class cmScriptGeneratorQuoted
43
{
44
public:
45
  cmScriptGeneratorQuoted(cm::string_view value, int bracket_length)
46
0
    : Value(value)
47
0
    , BracketLength(bracket_length)
48
0
  {
49
0
  }
50
51
  std::string str() const;
52
0
  operator std::string() const { return str(); }
53
54
private:
55
  friend std::ostream& operator<<(std::ostream& os,
56
                                  cmScriptGeneratorQuoted const& self);
57
58
  cm::string_view Value;
59
  int BracketLength;
60
};
61
62
/** \class cmScriptGenerator
63
 * \brief Support class for generating install and test scripts.
64
 *
65
 */
66
class cmScriptGenerator
67
{
68
public:
69
  cmScriptGenerator(std::string config_var,
70
                    std::vector<std::string> configurations);
71
  virtual ~cmScriptGenerator();
72
73
  cmScriptGenerator(cmScriptGenerator const&) = delete;
74
  cmScriptGenerator& operator=(cmScriptGenerator const&) = delete;
75
76
  void Generate(std::ostream& os, std::string const& config,
77
                std::vector<std::string> const& configurationTypes);
78
79
  static cmScriptGeneratorQuoted Quote(cm::string_view value);
80
81
  static std::string CreateConfigTest(std::string const& configVar,
82
                                      std::string const& config);
83
  static std::string CreateConfigTest(std::string const& configVar,
84
                                      std::vector<std::string> const& configs);
85
86
protected:
87
  using Indent = cmScriptGeneratorIndent;
88
  virtual void GenerateScript(std::ostream& os);
89
  virtual void GenerateScriptConfigs(std::ostream& os, Indent indent);
90
  virtual void GenerateScriptActions(std::ostream& os, Indent indent);
91
  virtual void GenerateScriptForConfig(std::ostream& os,
92
                                       std::string const& config,
93
                                       Indent indent);
94
0
  virtual void GenerateScriptNoConfig(std::ostream&, Indent) {}
95
0
  virtual bool NeedsScriptNoConfig() const { return false; }
96
97
  // Test if this generator does something for a given configuration.
98
  bool GeneratesForConfig(std::string const&);
99
100
  std::string CreateConfigTest(std::string const& config);
101
  std::string CreateConfigTest(std::vector<std::string> const& configs);
102
  std::string CreateComponentTest(std::string const& component);
103
104
  // Information shared by most generator types.
105
  std::string RuntimeConfigVariable;
106
  std::vector<std::string> const Configurations;
107
108
  // Information used during generation.
109
  std::string ConfigurationName;
110
  std::vector<std::string> const* ConfigurationTypes = nullptr;
111
112
  // True if the subclass needs to generate an explicit rule for each
113
  // configuration.  False if the subclass only generates one rule for
114
  // all enabled configurations.
115
  bool ActionsPerConfig = false;
116
117
private:
118
  void GenerateScriptActionsOnce(std::ostream& os, Indent indent);
119
  void GenerateScriptActionsPerConfig(std::ostream& os, Indent indent);
120
};