1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
5 #include "cmConfigure.h" // IWYU pragma: keep
11 class cmExecutionStatus;
13 struct cmListFileArgument;
16 * \brief Superclass for all commands in CMake.
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.
29 * Construct the command. By default it has no makefile.
31 cmCommand() = default;
34 * Need virtual destructor to destroy real command type.
36 virtual ~cmCommand() = default;
38 cmCommand(cmCommand const&) = delete;
39 cmCommand& operator=(cmCommand const&) = delete;
42 * Specify the makefile.
44 cmMakefile* GetMakefile() { return this->Makefile; }
46 void SetExecutionStatus(cmExecutionStatus* s);
47 cmExecutionStatus* GetExecutionStatus() { return this->Status; }
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.
54 bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
55 cmExecutionStatus& status);
58 * This is called when the command is first encountered in
59 * the CMakeLists.txt file.
61 virtual bool InitialPass(std::vector<std::string> const& args,
62 cmExecutionStatus&) = 0;
65 * This is a virtual constructor for the command.
67 virtual std::unique_ptr<cmCommand> Clone() = 0;
70 * Set the error message
72 void SetError(const std::string& e);
75 cmMakefile* Makefile = nullptr;
78 cmExecutionStatus* Status = nullptr;
81 class cmLegacyCommandWrapper
84 explicit cmLegacyCommandWrapper(std::unique_ptr<cmCommand> cmd);
86 cmLegacyCommandWrapper(cmLegacyCommandWrapper const& other);
87 cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper const& other);
89 cmLegacyCommandWrapper(cmLegacyCommandWrapper&&) = default;
90 cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper&&) = default;
92 bool operator()(std::vector<cmListFileArgument> const& args,
93 cmExecutionStatus& status) const;
96 std::unique_ptr<cmCommand> Command;