1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCommand.h,v $
7 Date: $Date: 2008/03/01 20:20:35 $
8 Version: $Revision: 1.27 $
10 Date: $Date: 2008-09-24 12:51:33 $
11 Version: $Revision: 1.28 $
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
26 #include "cmListFileCache.h"
27 #include "cmMakefile.h"
28 #include "cmCommandArgumentsHelper.h"
31 * \brief Superclass for all commands in CMake.
33 * cmCommand is the base class for all commands in CMake. A command
34 * manifests as an entry in CMakeLists.txt and produces one or
35 * more makefile rules. Commands are associated with a particular
36 * makefile. This base class cmCommand defines the API for commands
37 * to support such features as enable/disable, inheritance,
38 * documentation, and construction.
40 class cmCommand
: public cmObject
43 cmTypeMacro(cmCommand
, cmObject
);
46 * Construct the command. By default it is enabled with no makefile.
49 {this->Makefile
= 0; this->Enabled
= true;}
52 * Need virtual destructor to destroy real command type.
54 virtual ~cmCommand() {}
57 * Specify the makefile.
59 void SetMakefile(cmMakefile
*m
)
60 {this->Makefile
= m
; }
61 cmMakefile
* GetMakefile() { return this->Makefile
; }
64 * This is called by the cmMakefile when the command is first
65 * encountered in the CMakeLists.txt file. It expands the command's
66 * arguments and then invokes the InitialPass.
68 virtual bool InvokeInitialPass(const std::vector
<cmListFileArgument
>& args
,
69 cmExecutionStatus
&status
)
71 std::vector
<std::string
> expandedArguments
;
72 if(!this->Makefile
->ExpandArguments(args
, expandedArguments
))
74 // There was an error expanding arguments. It was already
75 // reported, so we can skip this command without error.
78 return this->InitialPass(expandedArguments
,status
);
82 * This is called when the command is first encountered in
83 * the CMakeLists.txt file.
85 virtual bool InitialPass(std::vector
<std::string
> const& args
,
86 cmExecutionStatus
&) = 0;
89 * This is called at the end after all the information
90 * specified by the command is accumulated. Most commands do
91 * not implement this method. At this point, reading and
92 * writing to the cache can be done.
94 virtual void FinalPass() {};
97 * This is a virtual constructor for the command.
99 virtual cmCommand
* Clone() = 0;
102 * This determines if the command is invoked when in script mode.
104 virtual bool IsScriptable()
110 * This determines if usage of the method is discouraged or not.
111 * This is currently only used for generating the documentation.
113 virtual bool IsDiscouraged()
119 * The name of the command as specified in CMakeList.txt.
121 virtual const char* GetName() = 0;
124 * Succinct documentation.
126 virtual const char* GetTerseDocumentation() = 0;
129 * More documentation.
131 virtual const char* GetFullDocumentation() = 0;
134 * Enable the command.
137 {this->Enabled
= true;}
140 * Disable the command.
143 {this->Enabled
= false;}
146 * Query whether the command is enabled.
149 {return this->Enabled
;}
152 * Disable or enable the command.
154 void SetEnabled(bool enabled
)
155 {this->Enabled
= enabled
;}
158 * Return the last error string.
160 const char* GetError()
162 if(this->Error
.length() == 0)
164 this->Error
= this->GetName();
165 this->Error
+= " unknown error.";
167 return this->Error
.c_str();
171 * Set the error message
173 void SetError(const char* e
)
175 this->Error
= this->GetName();
181 cmMakefile
* Makefile
;
182 cmCommandArgumentsHelper Helper
;