resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmCommand.h
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 <memory>
8 #include <string>
9 #include <vector>
10
11 class cmExecutionStatus;
12 class cmMakefile;
13 struct cmListFileArgument;
14
15 /** \class cmCommand
16  * \brief Superclass for all commands in CMake.
17  *
18  * cmCommand is the base class for all commands in CMake. A command
19  * manifests as an entry in CMakeLists.txt and produces one or
20  * more makefile rules. Commands are associated with a particular
21  * makefile. This base class cmCommand defines the API for commands
22  * to support such features as enable/disable, inheritance,
23  * documentation, and construction.
24  */
25 class cmCommand
26 {
27 public:
28   /**
29    * Construct the command. By default it has no makefile.
30    */
31   cmCommand() = default;
32
33   /**
34    * Need virtual destructor to destroy real command type.
35    */
36   virtual ~cmCommand() = default;
37
38   cmCommand(cmCommand const&) = delete;
39   cmCommand& operator=(cmCommand const&) = delete;
40
41   /**
42    * Specify the makefile.
43    */
44   cmMakefile* GetMakefile() { return this->Makefile; }
45
46   void SetExecutionStatus(cmExecutionStatus* s);
47   cmExecutionStatus* GetExecutionStatus() { return this->Status; }
48
49   /**
50    * This is called by the cmMakefile when the command is first
51    * encountered in the CMakeLists.txt file.  It expands the command's
52    * arguments and then invokes the InitialPass.
53    */
54   bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
55                          cmExecutionStatus& status);
56
57   /**
58    * This is called when the command is first encountered in
59    * the CMakeLists.txt file.
60    */
61   virtual bool InitialPass(std::vector<std::string> const& args,
62                            cmExecutionStatus&) = 0;
63
64   /**
65    * This is a virtual constructor for the command.
66    */
67   virtual std::unique_ptr<cmCommand> Clone() = 0;
68
69   /**
70    * Set the error message
71    */
72   void SetError(const std::string& e);
73
74 protected:
75   cmMakefile* Makefile = nullptr;
76
77 private:
78   cmExecutionStatus* Status = nullptr;
79 };
80
81 class cmLegacyCommandWrapper
82 {
83 public:
84   explicit cmLegacyCommandWrapper(std::unique_ptr<cmCommand> cmd);
85
86   cmLegacyCommandWrapper(cmLegacyCommandWrapper const& other);
87   cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper const& other);
88
89   cmLegacyCommandWrapper(cmLegacyCommandWrapper&&) = default;
90   cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper&&) = default;
91
92   bool operator()(std::vector<cmListFileArgument> const& args,
93                   cmExecutionStatus& status) const;
94
95 private:
96   std::unique_ptr<cmCommand> Command;
97 };