Coverage Report

Created: 2026-02-09 06:05

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
class cmScriptGeneratorIndent
12
{
13
public:
14
0
  cmScriptGeneratorIndent() = default;
15
  cmScriptGeneratorIndent(int level)
16
0
    : Level(level)
17
0
  {
18
0
  }
19
  void Write(std::ostream& os) const
20
0
  {
21
0
    for (int i = 0; i < this->Level; ++i) {
22
0
      os << " ";
23
0
    }
24
0
  }
25
  cmScriptGeneratorIndent Next(int step = 2) const
26
0
  {
27
0
    return { this->Level + step };
28
0
  }
29
30
private:
31
  int Level = 0;
32
};
33
inline std::ostream& operator<<(std::ostream& os,
34
                                cmScriptGeneratorIndent indent)
35
0
{
36
0
  indent.Write(os);
37
0
  return os;
38
0
}
39
40
/** \class cmScriptGenerator
41
 * \brief Support class for generating install and test scripts.
42
 *
43
 */
44
class cmScriptGenerator
45
{
46
public:
47
  cmScriptGenerator(std::string config_var,
48
                    std::vector<std::string> configurations);
49
  virtual ~cmScriptGenerator();
50
51
  cmScriptGenerator(cmScriptGenerator const&) = delete;
52
  cmScriptGenerator& operator=(cmScriptGenerator const&) = delete;
53
54
  void Generate(std::ostream& os, std::string const& config,
55
                std::vector<std::string> const& configurationTypes);
56
57
protected:
58
  using Indent = cmScriptGeneratorIndent;
59
  virtual void GenerateScript(std::ostream& os);
60
  virtual void GenerateScriptConfigs(std::ostream& os, Indent indent);
61
  virtual void GenerateScriptActions(std::ostream& os, Indent indent);
62
  virtual void GenerateScriptForConfig(std::ostream& os,
63
                                       std::string const& config,
64
                                       Indent indent);
65
0
  virtual void GenerateScriptNoConfig(std::ostream&, Indent) {}
66
0
  virtual bool NeedsScriptNoConfig() const { return false; }
67
68
  // Test if this generator does something for a given configuration.
69
  bool GeneratesForConfig(std::string const&);
70
71
  std::string CreateConfigTest(std::string const& config);
72
  std::string CreateConfigTest(std::vector<std::string> const& configs);
73
  std::string CreateComponentTest(std::string const& component);
74
75
  // Information shared by most generator types.
76
  std::string RuntimeConfigVariable;
77
  std::vector<std::string> const Configurations;
78
79
  // Information used during generation.
80
  std::string ConfigurationName;
81
  std::vector<std::string> const* ConfigurationTypes = nullptr;
82
83
  // True if the subclass needs to generate an explicit rule for each
84
  // configuration.  False if the subclass only generates one rule for
85
  // all enabled configurations.
86
  bool ActionsPerConfig = false;
87
88
private:
89
  void GenerateScriptActionsOnce(std::ostream& os, Indent indent);
90
  void GenerateScriptActionsPerConfig(std::ostream& os, Indent indent);
91
};