cmake/Source/cmCommand.h

98 lines
2.6 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2017-07-20 19:35:53 +02:00
2020-02-01 23:06:01 +01:00
#include <memory>
2017-04-14 19:02:05 +02:00
#include <string>
#include <vector>
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
class cmExecutionStatus;
class cmMakefile;
struct cmListFileArgument;
/** \class cmCommand
* \brief Superclass for all commands in CMake.
*
* cmCommand is the base class for all commands in CMake. A command
* manifests as an entry in CMakeLists.txt and produces one or
* more makefile rules. Commands are associated with a particular
2013-03-16 19:13:01 +02:00
* makefile. This base class cmCommand defines the API for commands
* to support such features as enable/disable, inheritance,
* documentation, and construction.
*/
2017-04-14 19:02:05 +02:00
class cmCommand
{
public:
/**
2017-04-14 19:02:05 +02:00
* Construct the command. By default it has no makefile.
*/
2019-11-11 23:01:05 +01:00
cmCommand() = default;
/**
* Need virtual destructor to destroy real command type.
*/
2019-11-11 23:01:05 +01:00
virtual ~cmCommand() = default;
cmCommand(cmCommand const&) = delete;
cmCommand& operator=(cmCommand const&) = delete;
2013-03-16 19:13:01 +02:00
/**
* Specify the makefile.
*/
cmMakefile* GetMakefile() { return this->Makefile; }
2020-02-01 23:06:01 +01:00
void SetExecutionStatus(cmExecutionStatus* s);
2021-11-20 13:41:27 +01:00
cmExecutionStatus* GetExecutionStatus() { return this->Status; }
2020-02-01 23:06:01 +01:00
/**
* This is called by the cmMakefile when the command is first
* encountered in the CMakeLists.txt file. It expands the command's
* arguments and then invokes the InitialPass.
*/
2020-02-01 23:06:01 +01:00
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status);
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
virtual bool InitialPass(std::vector<std::string> const& args,
2016-07-09 11:21:54 +02:00
cmExecutionStatus&) = 0;
/**
* This is a virtual constructor for the command.
*/
2020-02-01 23:06:01 +01:00
virtual std::unique_ptr<cmCommand> Clone() = 0;
/**
* Set the error message
*/
2017-04-14 19:02:05 +02:00
void SetError(const std::string& e);
protected:
2019-11-11 23:01:05 +01:00
cmMakefile* Makefile = nullptr;
private:
2020-02-01 23:06:01 +01:00
cmExecutionStatus* Status = nullptr;
};
class cmLegacyCommandWrapper
{
public:
explicit cmLegacyCommandWrapper(std::unique_ptr<cmCommand> cmd);
cmLegacyCommandWrapper(cmLegacyCommandWrapper const& other);
cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper const& other);
cmLegacyCommandWrapper(cmLegacyCommandWrapper&&) = default;
cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper&&) = default;
bool operator()(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status) const;
private:
std::unique_ptr<cmCommand> Command;
};