Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmCustomCommand.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 <string>
8
#include <utility>
9
#include <vector>
10
11
#include "cmCustomCommandLines.h"
12
#include "cmListFileCache.h"
13
#include "cmPolicies.h"
14
15
class cmImplicitDependsList
16
  : public std::vector<std::pair<std::string, std::string>>
17
{
18
};
19
20
class cmStateSnapshot;
21
22
/** \class cmCustomCommand
23
 * \brief A class to encapsulate a custom command
24
 *
25
 * cmCustomCommand encapsulates the properties of a custom command
26
 */
27
class cmCustomCommand
28
{
29
public:
30
  /** Get the output file produced by the command.  */
31
  std::vector<std::string> const& GetOutputs() const;
32
  void SetOutputs(std::vector<std::string> outputs);
33
  void SetOutputs(std::string output);
34
35
  /** Get the extra files produced by the command.  */
36
  std::vector<std::string> const& GetByproducts() const;
37
  void SetByproducts(std::vector<std::string> byproducts);
38
39
  /** Get the vector that holds the list of dependencies.  */
40
  std::vector<std::string> const& GetDepends() const;
41
  void SetDepends(std::vector<std::string> depends);
42
43
0
  bool HasMainDependency() const { return this->HasMainDependency_; }
44
  std::string const& GetMainDependency() const;
45
  void SetMainDependency(std::string main_dependency);
46
47
  /** Get the working directory.  */
48
  std::string const& GetWorkingDirectory() const
49
0
  {
50
0
    return this->WorkingDirectory;
51
0
  }
52
53
  void SetWorkingDirectory(char const* workingDirectory)
54
0
  {
55
0
    this->WorkingDirectory = (workingDirectory ? workingDirectory : "");
56
0
  }
57
58
  /** Get the list of command lines.  */
59
  cmCustomCommandLines const& GetCommandLines() const;
60
  void SetCommandLines(cmCustomCommandLines commandLines);
61
62
  /** Get the comment string for the command.  */
63
  char const* GetComment() const;
64
  void SetComment(char const* comment);
65
66
  /** Get a value indicating if the command uses UTF-8 output pipes. */
67
0
  bool GetStdPipesUTF8() const { return this->StdPipesUTF8; }
68
  void SetStdPipesUTF8(bool stdPipesUTF8)
69
0
  {
70
0
    this->StdPipesUTF8 = stdPipesUTF8;
71
0
  }
72
73
  /** Append to the list of command lines.  */
74
  void AppendCommands(cmCustomCommandLines const& commandLines);
75
76
  /** Append to the list of dependencies.  */
77
  void AppendDepends(std::vector<std::string> const& depends);
78
79
  /** Set/Get whether old-style escaping should be used.  */
80
  bool GetEscapeOldStyle() const;
81
  void SetEscapeOldStyle(bool b);
82
83
  /** Set/Get whether the build tool can replace variables in
84
      arguments to the command.  */
85
  bool GetEscapeAllowMakeVars() const;
86
  void SetEscapeAllowMakeVars(bool b);
87
88
  /** Backtrace of the command that created this custom command.  */
89
  cmListFileBacktrace const& GetBacktrace() const;
90
  void SetBacktrace(cmListFileBacktrace lfbt);
91
92
  void SetImplicitDepends(cmImplicitDependsList const&);
93
  void AppendImplicitDepends(cmImplicitDependsList const&);
94
  cmImplicitDependsList const& GetImplicitDepends() const;
95
96
  /** Set/Get whether this custom command should be given access to the
97
      real console (if possible).  */
98
  bool GetUsesTerminal() const;
99
  void SetUsesTerminal(bool b);
100
101
  /** Set/Get whether lists in command lines should be expanded. */
102
  bool GetCommandExpandLists() const;
103
  void SetCommandExpandLists(bool b);
104
105
  /** Set/Get whether to use additional dependencies coming from
106
      users of OUTPUT of the custom command. */
107
  bool GetDependsExplicitOnly() const;
108
  void SetDependsExplicitOnly(bool b);
109
110
  /** Set/Get the depfile (used by the Ninja generator) */
111
  std::string const& GetDepfile() const;
112
  void SetDepfile(std::string const& depfile);
113
114
  /** Set/Get the job_pool (used by the Ninja generator) */
115
  std::string const& GetJobPool() const;
116
  void SetJobPool(std::string const& job_pool);
117
118
  /** Set/Get whether this custom command should be given access to the
119
      jobserver (if possible).  */
120
  bool GetJobserverAware() const;
121
  void SetJobserverAware(bool b);
122
123
#define DECLARE_CC_POLICY_ACCESSOR(P)                                         \
124
  cmPolicies::PolicyStatus Get##P##Status() const;
125
  CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_ACCESSOR)
126
#undef DECLARE_CC_POLICY_ACCESSOR
127
128
  /** Record policy values from state snapshot */
129
  void RecordPolicyValues(cmStateSnapshot const& snapshot);
130
131
  /** Set/Get the associated target */
132
  std::string const& GetTarget() const;
133
  void SetTarget(std::string const& target);
134
135
  /** Set/Get the custom command rolee */
136
  std::string const& GetRole() const;
137
  void SetRole(std::string const& role);
138
139
  /** Record if the custom command can be used for code generation. */
140
0
  bool GetCodegen() const { return Codegen; }
141
0
  void SetCodegen(bool b) { Codegen = b; }
142
143
private:
144
  std::vector<std::string> Outputs;
145
  std::vector<std::string> Byproducts;
146
  std::vector<std::string> Depends;
147
  cmCustomCommandLines CommandLines;
148
  cmListFileBacktrace Backtrace;
149
  cmImplicitDependsList ImplicitDepends;
150
  std::string Target;
151
  std::string Comment;
152
  std::string WorkingDirectory;
153
  std::string Depfile;
154
  std::string JobPool;
155
  std::string Role;
156
  bool JobserverAware = false;
157
  bool HaveComment = false;
158
  bool EscapeAllowMakeVars = false;
159
  bool EscapeOldStyle = true;
160
  bool UsesTerminal = false;
161
  bool CommandExpandLists = false;
162
  bool StdPipesUTF8 = false;
163
  bool HasMainDependency_ = false;
164
  bool DependsExplicitOnly = false;
165
  bool Codegen = false;
166
167
// Policies are NEW for synthesized custom commands, and set by cmMakefile for
168
// user-created custom commands.
169
#define DECLARE_CC_POLICY_FIELD(P)                                            \
170
  cmPolicies::PolicyStatus P##Status = cmPolicies::NEW;
171
  CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_FIELD)
172
#undef DECLARE_CC_POLICY_FIELD
173
};