1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCommand.h,v $
6 Date: $Date: 2008-09-24 12:51:33 $
7 Version: $Revision: 1.28 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
21 #include "cmListFileCache.h"
22 #include "cmMakefile.h"
23 #include "cmCommandArgumentsHelper.h"
26 * \brief Superclass for all commands in CMake.
28 * cmCommand is the base class for all commands in CMake. A command
29 * manifests as an entry in CMakeLists.txt and produces one or
30 * more makefile rules. Commands are associated with a particular
31 * makefile. This base class cmCommand defines the API for commands
32 * to support such features as enable/disable, inheritance,
33 * documentation, and construction.
35 class cmCommand
: public cmObject
38 cmTypeMacro(cmCommand
, cmObject
);
41 * Construct the command. By default it is enabled with no makefile.
44 {this->Makefile
= 0; this->Enabled
= true;}
47 * Need virtual destructor to destroy real command type.
49 virtual ~cmCommand() {}
52 * Specify the makefile.
54 void SetMakefile(cmMakefile
*m
)
55 {this->Makefile
= m
; }
56 cmMakefile
* GetMakefile() { return this->Makefile
; }
59 * This is called by the cmMakefile when the command is first
60 * encountered in the CMakeLists.txt file. It expands the command's
61 * arguments and then invokes the InitialPass.
63 virtual bool InvokeInitialPass(const std::vector
<cmListFileArgument
>& args
,
64 cmExecutionStatus
&status
)
66 std::vector
<std::string
> expandedArguments
;
67 if(!this->Makefile
->ExpandArguments(args
, expandedArguments
))
69 // There was an error expanding arguments. It was already
70 // reported, so we can skip this command without error.
73 return this->InitialPass(expandedArguments
,status
);
77 * This is called when the command is first encountered in
78 * the CMakeLists.txt file.
80 virtual bool InitialPass(std::vector
<std::string
> const& args
,
81 cmExecutionStatus
&) = 0;
84 * This is called at the end after all the information
85 * specified by the command is accumulated. Most commands do
86 * not implement this method. At this point, reading and
87 * writing to the cache can be done.
89 virtual void FinalPass() {};
92 * This is a virtual constructor for the command.
94 virtual cmCommand
* Clone() = 0;
97 * This determines if the command is invoked when in script mode.
99 virtual bool IsScriptable()
105 * This determines if usage of the method is discouraged or not.
106 * This is currently only used for generating the documentation.
108 virtual bool IsDiscouraged()
114 * The name of the command as specified in CMakeList.txt.
116 virtual const char* GetName() = 0;
119 * Succinct documentation.
121 virtual const char* GetTerseDocumentation() = 0;
124 * More documentation.
126 virtual const char* GetFullDocumentation() = 0;
129 * Enable the command.
132 {this->Enabled
= true;}
135 * Disable the command.
138 {this->Enabled
= false;}
141 * Query whether the command is enabled.
144 {return this->Enabled
;}
147 * Disable or enable the command.
149 void SetEnabled(bool enabled
)
150 {this->Enabled
= enabled
;}
153 * Return the last error string.
155 const char* GetError()
157 if(this->Error
.length() == 0)
159 this->Error
= this->GetName();
160 this->Error
+= " unknown error.";
162 return this->Error
.c_str();
166 * Set the error message
168 void SetError(const char* e
)
170 this->Error
= this->GetName();
176 cmMakefile
* Makefile
;
177 cmCommandArgumentsHelper Helper
;