2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-01-18 19:20:24 +03:00
|
|
|
#ifndef cmCommand_h
|
|
|
|
#define cmCommand_h
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2005-06-17 21:04:56 +04:00
|
|
|
#include "cmObject.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmCommandArgumentsHelper.h"
|
2002-12-12 02:13:33 +03:00
|
|
|
#include "cmListFileCache.h"
|
|
|
|
#include "cmMakefile.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
/** \class cmCommand
|
|
|
|
* \brief Superclass for all commands in CMake.
|
2001-01-11 01:05:42 +03:00
|
|
|
*
|
2001-01-18 19:20:24 +03:00
|
|
|
* 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
|
2012-08-13 21:42:58 +04:00
|
|
|
* makefile. This base class cmCommand defines the API for commands
|
|
|
|
* to support such features as enable/disable, inheritance,
|
2001-01-18 19:20:24 +03:00
|
|
|
* documentation, and construction.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2005-06-17 21:04:56 +04:00
|
|
|
class cmCommand : public cmObject
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
|
|
|
public:
|
2005-06-17 21:04:56 +04:00
|
|
|
cmTypeMacro(cmCommand, cmObject);
|
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* Construct the command. By default it is enabled with no makefile.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2012-08-13 21:42:58 +04:00
|
|
|
cmCommand()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
this->Makefile = CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Enabled = true;
|
|
|
|
}
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2001-02-23 18:40:13 +03:00
|
|
|
/**
|
|
|
|
* Need virtual destructor to destroy real command type.
|
|
|
|
*/
|
2016-06-27 22:25:27 +03:00
|
|
|
~cmCommand() CM_OVERRIDE {}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
|
|
|
* Specify the makefile.
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
void SetMakefile(cmMakefile* m) { this->Makefile = m; }
|
2006-03-15 19:02:08 +03:00
|
|
|
cmMakefile* GetMakefile() { return this->Makefile; }
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2002-12-12 02:13:33 +03: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.
|
|
|
|
*/
|
2008-01-23 18:28:26 +03:00
|
|
|
virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExecutionStatus& status)
|
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<std::string> expandedArguments;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->ExpandArguments(args, expandedArguments)) {
|
2008-09-24 16:51:33 +04:00
|
|
|
// There was an error expanding arguments. It was already
|
|
|
|
// reported, so we can skip this command without error.
|
|
|
|
return true;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return this->InitialPass(expandedArguments, status);
|
|
|
|
}
|
2002-12-12 02:13:33 +03:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* This is called when the command is first encountered in
|
2001-01-11 01:05:42 +03:00
|
|
|
* the CMakeLists.txt file.
|
|
|
|
*/
|
2008-01-23 18:28:26 +03:00
|
|
|
virtual bool InitialPass(std::vector<std::string> const& args,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExecutionStatus&) = 0;
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called at the end after all the information
|
2001-01-18 19:20:24 +03:00
|
|
|
* specified by the command is accumulated. Most commands do
|
2001-02-19 23:13:48 +03:00
|
|
|
* not implement this method. At this point, reading and
|
|
|
|
* writing to the cache can be done.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2014-04-03 23:35:22 +04:00
|
|
|
virtual void FinalPass() {}
|
2009-07-24 21:31:34 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this command have a final pass? Query after InitialPass.
|
|
|
|
*/
|
|
|
|
virtual bool HasFinalPass() const { return false; }
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* This is a virtual constructor for the command.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2001-01-18 19:20:24 +03:00
|
|
|
virtual cmCommand* Clone() = 0;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2003-10-29 16:58:54 +03:00
|
|
|
/**
|
|
|
|
* This determines if the command is invoked when in script mode.
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
virtual bool IsScriptable() const { return false; }
|
2003-10-29 16:58:54 +03:00
|
|
|
|
2012-01-03 03:54:08 +04:00
|
|
|
/**
|
|
|
|
* This is used to avoid including this command
|
|
|
|
* in documentation. This is mainly used by
|
|
|
|
* cmMacroHelperCommand and cmFunctionHelperCommand
|
|
|
|
* which cannot provide appropriate documentation.
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
virtual bool ShouldAppearInDocumentation() const { return true; }
|
2012-01-03 03:54:08 +04:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* The name of the command as specified in CMakeList.txt.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2014-02-25 05:19:17 +04:00
|
|
|
virtual std::string GetName() const = 0;
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* Enable the command.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
void EnabledOn() { this->Enabled = true; }
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* Disable the command.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
void EnabledOff() { this->Enabled = false; }
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
2001-01-18 19:20:24 +03:00
|
|
|
* Query whether the command is enabled.
|
2001-01-11 01:05:42 +03:00
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
bool GetEnabled() const { return this->Enabled; }
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
/**
|
|
|
|
* Disable or enable the command.
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
void SetEnabled(bool enabled) { this->Enabled = enabled; }
|
2001-01-18 19:20:24 +03:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
|
|
|
* Return the last error string.
|
|
|
|
*/
|
2012-08-13 21:42:58 +04:00
|
|
|
const char* GetError()
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
if (this->Error.empty()) {
|
|
|
|
this->Error = this->GetName();
|
|
|
|
this->Error += " unknown error.";
|
2001-03-13 02:30:58 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return this->Error.c_str();
|
|
|
|
}
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2005-06-15 23:51:39 +04:00
|
|
|
/**
|
|
|
|
* Set the error message
|
|
|
|
*/
|
2014-02-08 00:35:10 +04:00
|
|
|
void SetError(const std::string& e)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Error = this->GetName();
|
|
|
|
this->Error += " ";
|
|
|
|
this->Error += e;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-06-15 23:51:39 +04:00
|
|
|
|
2013-10-18 19:54:09 +04:00
|
|
|
/** Check if the command is disallowed by a policy. */
|
|
|
|
bool Disallowed(cmPolicies::PolicyID pol, const char* e)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
switch (this->Makefile->GetPolicyStatus(pol)) {
|
2013-10-18 19:54:09 +04:00
|
|
|
case cmPolicies::WARN:
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmPolicies::GetPolicyWarning(pol));
|
2013-10-18 19:54:09 +04:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
return false;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-18 19:54:09 +04:00
|
|
|
|
2005-06-15 23:51:39 +04:00
|
|
|
protected:
|
2006-03-15 19:02:08 +03:00
|
|
|
cmMakefile* Makefile;
|
2007-07-02 23:43:21 +04:00
|
|
|
cmCommandArgumentsHelper Helper;
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2001-01-05 19:41:20 +03:00
|
|
|
private:
|
2006-03-15 19:02:08 +03:00
|
|
|
bool Enabled;
|
|
|
|
std::string Error;
|
2001-01-05 19:41:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|