ENH: fix for VS6 and Cygwin
[cmake.git] / Source / cmCommand.h
blob35e659be45e252413d3ecb49616bcd6e274ee935
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCommand.h,v $
5 Language: C++
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 =========================================================================*/
17 #ifndef cmCommand_h
18 #define cmCommand_h
20 #include "cmObject.h"
21 #include "cmListFileCache.h"
22 #include "cmMakefile.h"
23 #include "cmCommandArgumentsHelper.h"
25 /** \class cmCommand
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
37 public:
38 cmTypeMacro(cmCommand, cmObject);
40 /**
41 * Construct the command. By default it is enabled with no makefile.
43 cmCommand()
44 {this->Makefile = 0; this->Enabled = true;}
46 /**
47 * Need virtual destructor to destroy real command type.
49 virtual ~cmCommand() {}
51 /**
52 * Specify the makefile.
54 void SetMakefile(cmMakefile*m)
55 {this->Makefile = m; }
56 cmMakefile* GetMakefile() { return this->Makefile; }
58 /**
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.
71 return true;
73 return this->InitialPass(expandedArguments,status);
76 /**
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;
83 /**
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() {};
91 /**
92 * This is a virtual constructor for the command.
94 virtual cmCommand* Clone() = 0;
96 /**
97 * This determines if the command is invoked when in script mode.
99 virtual bool IsScriptable()
101 return false;
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()
110 return false;
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.
131 void EnabledOn()
132 {this->Enabled = true;}
135 * Disable the command.
137 void EnabledOff()
138 {this->Enabled = false;}
141 * Query whether the command is enabled.
143 bool GetEnabled()
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();
171 this->Error += " ";
172 this->Error += e;
175 protected:
176 cmMakefile* Makefile;
177 cmCommandArgumentsHelper Helper;
179 private:
180 bool Enabled;
181 std::string Error;
184 #endif