1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCommand.h,v $
6 Date: $Date: 2008-03-01 20:20:35 $
7 Version: $Revision: 1.27 $
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 this->Makefile
->ExpandArguments(args
, expandedArguments
);
68 return this->InitialPass(expandedArguments
,status
);
72 * This is called when the command is first encountered in
73 * the CMakeLists.txt file.
75 virtual bool InitialPass(std::vector
<std::string
> const& args
,
76 cmExecutionStatus
&) = 0;
79 * This is called at the end after all the information
80 * specified by the command is accumulated. Most commands do
81 * not implement this method. At this point, reading and
82 * writing to the cache can be done.
84 virtual void FinalPass() {};
87 * This is a virtual constructor for the command.
89 virtual cmCommand
* Clone() = 0;
92 * This determines if the command is invoked when in script mode.
94 virtual bool IsScriptable()
100 * This determines if usage of the method is discouraged or not.
101 * This is currently only used for generating the documentation.
103 virtual bool IsDiscouraged()
109 * The name of the command as specified in CMakeList.txt.
111 virtual const char* GetName() = 0;
114 * Succinct documentation.
116 virtual const char* GetTerseDocumentation() = 0;
119 * More documentation.
121 virtual const char* GetFullDocumentation() = 0;
124 * Enable the command.
127 {this->Enabled
= true;}
130 * Disable the command.
133 {this->Enabled
= false;}
136 * Query whether the command is enabled.
139 {return this->Enabled
;}
142 * Disable or enable the command.
144 void SetEnabled(bool enabled
)
145 {this->Enabled
= enabled
;}
148 * Return the last error string.
150 const char* GetError()
152 if(this->Error
.length() == 0)
154 this->Error
= this->GetName();
155 this->Error
+= " unknown error.";
157 return this->Error
.c_str();
161 * Set the error message
163 void SetError(const char* e
)
165 this->Error
= this->GetName();
171 cmMakefile
* Makefile
;
172 cmCommandArgumentsHelper Helper
;