2009-10-02 01:21:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
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"
|
2002-12-12 02:13:33 +03:00
|
|
|
#include "cmListFileCache.h"
|
|
|
|
#include "cmMakefile.h"
|
2007-07-02 23:43:21 +04:00
|
|
|
#include "cmCommandArgumentsHelper.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
|
|
|
|
* makefile. This base class cmCommand defines the API for commands
|
|
|
|
* to support such features as enable/disable, inheritance,
|
|
|
|
* 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
|
|
|
*/
|
2001-01-18 19:20:24 +03:00
|
|
|
cmCommand()
|
2006-03-15 19:02:08 +03:00
|
|
|
{this->Makefile = 0; 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.
|
|
|
|
*/
|
|
|
|
virtual ~cmCommand() {}
|
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
|
|
|
* Specify the makefile.
|
|
|
|
*/
|
|
|
|
void SetMakefile(cmMakefile*m)
|
2006-03-15 19:02:08 +03:00
|
|
|
{this->Makefile = m; }
|
|
|
|
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,
|
|
|
|
cmExecutionStatus &status)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
|
|
|
std::vector<std::string> expandedArguments;
|
2008-09-24 16:51:33 +04:00
|
|
|
if(!this->Makefile->ExpandArguments(args, expandedArguments))
|
|
|
|
{
|
|
|
|
// There was an error expanding arguments. It was already
|
|
|
|
// reported, so we can skip this command without error.
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-23 18:28:26 +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,
|
|
|
|
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
|
|
|
*/
|
2001-01-18 19:20:24 +03: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; }
|
2001-01-05 19:41:20 +03: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;
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2003-10-29 16:58:54 +03:00
|
|
|
/**
|
|
|
|
* This determines if the command is invoked when in script mode.
|
|
|
|
*/
|
|
|
|
virtual bool IsScriptable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-08-31 21:20:12 +04:00
|
|
|
/**
|
|
|
|
* This determines if usage of the method is discouraged or not.
|
|
|
|
* This is currently only used for generating the documentation.
|
|
|
|
*/
|
|
|
|
virtual bool IsDiscouraged()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2001-01-05 19:41:20 +03:00
|
|
|
virtual const char* GetName() = 0;
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Succinct documentation.
|
|
|
|
*/
|
2001-01-12 22:35:15 +03:00
|
|
|
virtual const char* GetTerseDocumentation() = 0;
|
2001-01-11 01:05:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* More documentation.
|
|
|
|
*/
|
2001-01-12 22:35:15 +03:00
|
|
|
virtual const char* GetFullDocumentation() = 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
|
|
|
*/
|
|
|
|
void EnabledOn()
|
2006-03-15 19:02:08 +03:00
|
|
|
{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
|
|
|
*/
|
|
|
|
void EnabledOff()
|
2006-03-15 19:02:08 +03:00
|
|
|
{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
|
|
|
*/
|
|
|
|
bool GetEnabled()
|
2006-03-15 19:02:08 +03:00
|
|
|
{return this->Enabled;}
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
/**
|
|
|
|
* Disable or enable the command.
|
|
|
|
*/
|
|
|
|
void SetEnabled(bool enabled)
|
2006-03-15 19:02:08 +03:00
|
|
|
{this->Enabled = enabled;}
|
2001-01-18 19:20:24 +03:00
|
|
|
|
2001-01-11 01:05:42 +03:00
|
|
|
/**
|
|
|
|
* Return the last error string.
|
|
|
|
*/
|
|
|
|
const char* GetError()
|
2001-03-13 02:30:58 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
if(this->Error.length() == 0)
|
2001-03-13 02:30:58 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Error = this->GetName();
|
|
|
|
this->Error += " unknown error.";
|
2001-03-13 02:30:58 +03:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
return this->Error.c_str();
|
2001-03-13 02:30:58 +03:00
|
|
|
}
|
2001-01-11 01:05:42 +03:00
|
|
|
|
2005-06-15 23:51:39 +04:00
|
|
|
/**
|
|
|
|
* Set the error message
|
|
|
|
*/
|
2001-01-05 19:41:20 +03:00
|
|
|
void SetError(const char* e)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Error = this->GetName();
|
|
|
|
this->Error += " ";
|
|
|
|
this->Error += e;
|
2001-01-05 19:41:20 +03: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
|