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
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 cmCustomCommand
21  * \brief A class to encapsulate a custom command
22  *
23  * cmCustomCommand encapsulates the properties of a custom command
24  */
25 class cmCustomCommand
26 {
27 public:
28   /** Main constructor specifies all information for the command.  */
29   cmCustomCommand(std::vector<std::string> outputs,
30                   std::vector<std::string> byproducts,
31                   std::vector<std::string> depends,
32                   cmCustomCommandLines commandLines, cmListFileBacktrace lfbt,
33                   const char* comment, const char* workingDirectory,
34                   bool stdPipesUTF8);
35 
36   /** Get the output file produced by the command.  */
37   const std::vector<std::string>& GetOutputs() const;
38 
39   /** Get the extra files produced by the command.  */
40   const std::vector<std::string>& GetByproducts() const;
41 
42   /** Get the vector that holds the list of dependencies.  */
43   const std::vector<std::string>& GetDepends() const;
44 
45   /** Get the working directory.  */
GetWorkingDirectory()46   std::string const& GetWorkingDirectory() const
47   {
48     return this->WorkingDirectory;
49   }
50 
51   /** Get the list of command lines.  */
52   const cmCustomCommandLines& GetCommandLines() const;
53 
54   /** Get the comment string for the command.  */
55   const char* GetComment() const;
56 
57   /** Get a value indicating if the command uses UTF-8 output pipes. */
GetStdPipesUTF8()58   bool GetStdPipesUTF8() const { return this->StdPipesUTF8; }
59 
60   /** Append to the list of command lines.  */
61   void AppendCommands(const cmCustomCommandLines& commandLines);
62 
63   /** Append to the list of dependencies.  */
64   void AppendDepends(const std::vector<std::string>& depends);
65 
66   /** Set/Get whether old-style escaping should be used.  */
67   bool GetEscapeOldStyle() const;
68   void SetEscapeOldStyle(bool b);
69 
70   /** Set/Get whether the build tool can replace variables in
71       arguments to the command.  */
72   bool GetEscapeAllowMakeVars() const;
73   void SetEscapeAllowMakeVars(bool b);
74 
75   /** Backtrace of the command that created this custom command.  */
76   cmListFileBacktrace const& GetBacktrace() const;
77 
78   void SetImplicitDepends(cmImplicitDependsList const&);
79   void AppendImplicitDepends(cmImplicitDependsList const&);
80   cmImplicitDependsList const& GetImplicitDepends() const;
81 
82   /** Set/Get whether this custom command should be given access to the
83       real console (if possible).  */
84   bool GetUsesTerminal() const;
85   void SetUsesTerminal(bool b);
86 
87   /** Set/Get whether lists in command lines should be expanded. */
88   bool GetCommandExpandLists() const;
89   void SetCommandExpandLists(bool b);
90 
91   /** Set/Get the depfile (used by the Ninja generator) */
92   const std::string& GetDepfile() const;
93   void SetDepfile(const std::string& depfile);
94 
95   /** Set/Get the job_pool (used by the Ninja generator) */
96   const std::string& GetJobPool() const;
97   void SetJobPool(const std::string& job_pool);
98 
99   /** Set/Get the CMP0116 status (used by the Ninja generator) */
100   cmPolicies::PolicyStatus GetCMP0116Status() const;
101   void SetCMP0116Status(cmPolicies::PolicyStatus cmp0116);
102 
103   /** Set/Get the associated target */
104   const std::string& GetTarget() const;
105   void SetTarget(const std::string& target);
106 
107 private:
108   std::vector<std::string> Outputs;
109   std::vector<std::string> Byproducts;
110   std::vector<std::string> Depends;
111   cmCustomCommandLines CommandLines;
112   cmListFileBacktrace Backtrace;
113   cmImplicitDependsList ImplicitDepends;
114   std::string Target;
115   std::string Comment;
116   std::string WorkingDirectory;
117   std::string Depfile;
118   std::string JobPool;
119   bool HaveComment = false;
120   bool EscapeAllowMakeVars = false;
121   bool EscapeOldStyle = true;
122   bool UsesTerminal = false;
123   bool CommandExpandLists = false;
124   bool StdPipesUTF8 = false;
125   cmPolicies::PolicyStatus CMP0116Status = cmPolicies::WARN;
126 };
127