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