CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmCustomCommand.h
blob167e601e739eed339357fdd285f2e8bc39ef1a16
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <string>
8 #include <utility>
9 #include <vector>
11 #include "cmCustomCommandLines.h"
12 #include "cmListFileCache.h"
13 #include "cmPolicies.h"
15 class cmImplicitDependsList
16 : public std::vector<std::pair<std::string, std::string>>
20 class cmStateSnapshot;
22 /** \class cmCustomCommand
23 * \brief A class to encapsulate a custom command
25 * cmCustomCommand encapsulates the properties of a custom command
27 class cmCustomCommand
29 public:
30 /** Get the output file produced by the command. */
31 const std::vector<std::string>& GetOutputs() const;
32 void SetOutputs(std::vector<std::string> outputs);
33 void SetOutputs(std::string output);
35 /** Get the extra files produced by the command. */
36 const std::vector<std::string>& GetByproducts() const;
37 void SetByproducts(std::vector<std::string> byproducts);
39 /** Get the vector that holds the list of dependencies. */
40 const std::vector<std::string>& GetDepends() const;
41 void SetDepends(std::vector<std::string> depends);
43 bool HasMainDependency() const { return this->HasMainDependency_; }
44 const std::string& GetMainDependency() const;
45 void SetMainDependency(std::string main_dependency);
47 /** Get the working directory. */
48 std::string const& GetWorkingDirectory() const
50 return this->WorkingDirectory;
53 void SetWorkingDirectory(const char* workingDirectory)
55 this->WorkingDirectory = (workingDirectory ? workingDirectory : "");
58 /** Get the list of command lines. */
59 const cmCustomCommandLines& GetCommandLines() const;
60 void SetCommandLines(cmCustomCommandLines commandLines);
62 /** Get the comment string for the command. */
63 const char* GetComment() const;
64 void SetComment(const char* comment);
66 /** Get a value indicating if the command uses UTF-8 output pipes. */
67 bool GetStdPipesUTF8() const { return this->StdPipesUTF8; }
68 void SetStdPipesUTF8(bool stdPipesUTF8)
70 this->StdPipesUTF8 = stdPipesUTF8;
73 /** Append to the list of command lines. */
74 void AppendCommands(const cmCustomCommandLines& commandLines);
76 /** Append to the list of dependencies. */
77 void AppendDepends(const std::vector<std::string>& depends);
79 /** Set/Get whether old-style escaping should be used. */
80 bool GetEscapeOldStyle() const;
81 void SetEscapeOldStyle(bool b);
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);
88 /** Backtrace of the command that created this custom command. */
89 cmListFileBacktrace const& GetBacktrace() const;
90 void SetBacktrace(cmListFileBacktrace lfbt);
92 void SetImplicitDepends(cmImplicitDependsList const&);
93 void AppendImplicitDepends(cmImplicitDependsList const&);
94 cmImplicitDependsList const& GetImplicitDepends() const;
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);
101 /** Set/Get whether lists in command lines should be expanded. */
102 bool GetCommandExpandLists() const;
103 void SetCommandExpandLists(bool b);
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);
110 /** Set/Get the depfile (used by the Ninja generator) */
111 const std::string& GetDepfile() const;
112 void SetDepfile(const std::string& depfile);
114 /** Set/Get the job_pool (used by the Ninja generator) */
115 const std::string& GetJobPool() const;
116 void SetJobPool(const std::string& job_pool);
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);
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
128 /** Record policy values from state snapshot */
129 void RecordPolicyValues(const cmStateSnapshot& snapshot);
131 /** Set/Get the associated target */
132 const std::string& GetTarget() const;
133 void SetTarget(const std::string& target);
135 private:
136 std::vector<std::string> Outputs;
137 std::vector<std::string> Byproducts;
138 std::vector<std::string> Depends;
139 cmCustomCommandLines CommandLines;
140 cmListFileBacktrace Backtrace;
141 cmImplicitDependsList ImplicitDepends;
142 std::string Target;
143 std::string Comment;
144 std::string WorkingDirectory;
145 std::string Depfile;
146 std::string JobPool;
147 bool JobserverAware = false;
148 bool HaveComment = false;
149 bool EscapeAllowMakeVars = false;
150 bool EscapeOldStyle = true;
151 bool UsesTerminal = false;
152 bool CommandExpandLists = false;
153 bool StdPipesUTF8 = false;
154 bool HasMainDependency_ = false;
155 bool DependsExplicitOnly = false;
157 // Policies are NEW for synthesized custom commands, and set by cmMakefile for
158 // user-created custom commands.
159 #define DECLARE_CC_POLICY_FIELD(P) \
160 cmPolicies::PolicyStatus P##Status = cmPolicies::NEW;
161 CM_FOR_EACH_CUSTOM_COMMAND_POLICY(DECLARE_CC_POLICY_FIELD)
162 #undef DECLARE_CC_POLICY_FIELD