1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmCommand.h,v $
6 Date: $Date: 2002-01-21 20:30:21 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 =========================================================================*/
20 #include "cmStandardIncludes.h"
21 #include "cmMakefile.h"
24 * \brief Superclass for all commands in CMake.
26 * cmCommand is the base class for all commands in CMake. A command
27 * manifests as an entry in CMakeLists.txt and produces one or
28 * more makefile rules. Commands are associated with a particular
29 * makefile. This base class cmCommand defines the API for commands
30 * to support such features as enable/disable, inheritance,
31 * documentation, and construction.
37 * Construct the command. By default it is enabled with no makefile.
40 {m_Makefile
= 0; m_Enabled
= true;}
43 * Need virtual destructor to destroy real command type.
45 virtual ~cmCommand() {}
48 * Specify the makefile.
50 void SetMakefile(cmMakefile
*m
)
54 * This is called when the command is first encountered in
55 * the CMakeLists.txt file.
57 virtual bool InitialPass(std::vector
<std::string
> const& args
) = 0;
60 * This is called at the end after all the information
61 * specified by the command is accumulated. Most commands do
62 * not implement this method. At this point, reading and
63 * writing to the cache can be done.
65 virtual void FinalPass() {};
68 * This is a virtual constructor for the command.
70 virtual cmCommand
* Clone() = 0;
73 * This determines if the command gets propagated down
74 * to makefiles located in subdirectories.
76 virtual bool IsInherited()
82 * The name of the command as specified in CMakeList.txt.
84 virtual const char* GetName() = 0;
87 * Succinct documentation.
89 virtual const char* GetTerseDocumentation() = 0;
94 virtual const char* GetFullDocumentation() = 0;
103 * Disable the command.
109 * Query whether the command is enabled.
115 * Disable or enable the command.
117 void SetEnabled(bool enabled
)
118 {m_Enabled
= enabled
;}
121 * Return the last error string.
123 const char* GetError()
125 if(m_Error
.length() == 0)
127 m_Error
= this->GetName();
128 m_Error
+= " unknown error.";
130 return m_Error
.c_str();
134 * Returns true if this class is the given class, or a subclass of it.
136 static bool IsTypeOf(const char *type
)
137 { return !strcmp("cmCommand", type
); }
140 * Returns true if this object is an instance of the given class or
143 virtual bool IsA(const char *type
)
144 { return cmCommand::IsTypeOf(type
); }
147 void SetError(const char* e
)
149 m_Error
= this->GetName();
153 cmMakefile
* m_Makefile
;
160 // All subclasses of cmCommand should invoke this macro.
161 #define cmTypeMacro(thisClass,superclass) \
162 static bool IsTypeOf(const char *type) \
164 if ( !strcmp(#thisClass,type) ) \
168 return superclass::IsTypeOf(type); \
170 virtual bool IsA(const char *type) \
172 return thisClass::IsTypeOf(type); \
174 static thisClass* SafeDownCast(cmCommand *c) \
176 if ( c && c->IsA(#thisClass) ) \
178 return (thisClass *)c; \