Resync (forgot to add new files?)
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmIfCommand.h
blobba43b91900c5f7f44f847871abeb7b6a60417d2e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmIfCommand.h,v $
5 Language: C++
6 Date: $Date: 2008/02/10 22:19:10 $
7 Version: $Revision: 1.46 $
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 cmIfCommand_h
18 #define cmIfCommand_h
20 #include "cmCommand.h"
21 #include "cmFunctionBlocker.h"
23 /** \class cmIfFunctionBlocker
24 * \brief subclass of function blocker
28 class cmIfFunctionBlocker : public cmFunctionBlocker
30 public:
31 cmIfFunctionBlocker() {
32 this->HasRun = false; this->ScopeDepth = 0; this->Executing = false;}
33 virtual ~cmIfFunctionBlocker() {}
34 virtual bool IsFunctionBlocked(const cmListFileFunction& lff,
35 cmMakefile &mf,
36 cmExecutionStatus &);
37 virtual bool ShouldRemove(const cmListFileFunction& lff,
38 cmMakefile &mf);
39 virtual void ScopeEnded(cmMakefile &mf);
41 std::vector<cmListFileArgument> Args;
42 std::vector<cmListFileFunction> Functions;
43 bool IsBlocking;
44 bool HasRun;
45 unsigned int ScopeDepth;
46 bool Executing;
49 /** \class cmIfCommand
50 * \brief starts an if block
52 * cmIfCommand starts an if block
54 class cmIfCommand : public cmCommand
56 public:
57 /**
58 * This is a virtual constructor for the command.
60 virtual cmCommand* Clone()
62 return new cmIfCommand;
65 /**
66 * This overrides the default InvokeInitialPass implementation.
67 * It records the arguments before expansion.
69 virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
70 cmExecutionStatus &);
72 /**
73 * This is called when the command is first encountered in
74 * the CMakeLists.txt file.
76 virtual bool InitialPass(std::vector<std::string> const&,
77 cmExecutionStatus &) { return false;};
79 /**
80 * The name of the command as specified in CMakeList.txt.
82 virtual const char* GetName() { return "if";}
84 /**
85 * Succinct documentation.
87 virtual const char* GetTerseDocumentation()
89 return "Conditionally execute a group of commands.";
92 /**
93 * This determines if the command is invoked when in script mode.
95 virtual bool IsScriptable() { return true; }
97 /**
98 * More documentation.
100 virtual const char* GetFullDocumentation()
102 return
103 " if(expression)\n"
104 " # then section.\n"
105 " COMMAND1(ARGS ...)\n"
106 " COMMAND2(ARGS ...)\n"
107 " ...\n"
108 " elseif(expression2)\n"
109 " # elseif section.\n"
110 " COMMAND1(ARGS ...)\n"
111 " COMMAND2(ARGS ...)\n"
112 " ...\n"
113 " else(expression)\n"
114 " # else section.\n"
115 " COMMAND1(ARGS ...)\n"
116 " COMMAND2(ARGS ...)\n"
117 " ...\n"
118 " endif(expression)\n"
119 "Evaluates the given expression. If the result is true, the commands "
120 "in the THEN section are invoked. Otherwise, the commands in the "
121 "else section are invoked. The elseif and else sections are "
122 "optional. You may have multiple elseif clauses. Note that "
123 "the same expression must be given to if, and endif. Long "
124 "expressions can be used and the order or precedence is that the "
125 "EXISTS, COMMAND, and DEFINED operators will be evaluated first. "
126 "Then any EQUAL, LESS, GREATER, STRLESS, STRGREATER, STREQUAL, MATCHES "
127 "will be evaluated. Then NOT operators and finally AND, OR operators "
128 "will be evaluated. Possible expressions are:\n"
129 " if(variable)\n"
130 "True if the variable's value is not empty, 0, N, NO, OFF, FALSE, "
131 "NOTFOUND, or <variable>-NOTFOUND.\n"
132 " if(NOT variable)\n"
133 "True if the variable's value is empty, 0, N, NO, OFF, FALSE, "
134 "NOTFOUND, or <variable>-NOTFOUND.\n"
135 " if(variable1 AND variable2)\n"
136 "True if both variables would be considered true individually.\n"
137 " if(variable1 OR variable2)\n"
138 "True if either variable would be considered true individually.\n"
139 " if(COMMAND command-name)\n"
140 "True if the given name is a command, macro or function that can be "
141 "invoked.\n"
142 " if(EXISTS file-name)\n"
143 " if(EXISTS directory-name)\n"
144 "True if the named file or directory exists. "
145 "Behavior is well-defined only for full paths.\n"
146 " if(file1 IS_NEWER_THAN file2)\n"
147 "True if file1 is newer than file2 or if one of the two files "
148 "doesn't exist. "
149 "Behavior is well-defined only for full paths.\n"
150 " if(IS_DIRECTORY directory-name)\n"
151 "True if the given name is a directory. "
152 "Behavior is well-defined only for full paths.\n"
153 " if(IS_ABSOLUTE path)\n"
154 "True if the given path is an absolute path.\n "
155 " if(variable MATCHES regex)\n"
156 " if(string MATCHES regex)\n"
157 "True if the given string or variable's value matches the given "
158 "regular expression.\n"
159 " if(variable LESS number)\n"
160 " if(string LESS number)\n"
161 " if(variable GREATER number)\n"
162 " if(string GREATER number)\n"
163 " if(variable EQUAL number)\n"
164 " if(string EQUAL number)\n"
165 "True if the given string or variable's value is a valid number and "
166 "the inequality or equality is true.\n"
167 " if(variable STRLESS string)\n"
168 " if(string STRLESS string)\n"
169 " if(variable STRGREATER string)\n"
170 " if(string STRGREATER string)\n"
171 " if(variable STREQUAL string)\n"
172 " if(string STREQUAL string)\n"
173 "True if the given string or variable's value is lexicographically "
174 "less (or greater, or equal) than the string on the right.\n"
175 " if(DEFINED variable)\n"
176 "True if the given variable is defined. It does not matter if the "
177 "variable is true or false just if it has been set.";
180 // this is a shared function for both If and Else to determine if the
181 // arguments were valid, and if so, was the response true. If there is
182 // an error, the errorString will be set.
183 static bool IsTrue(const std::vector<std::string> &args,
184 char** errorString, cmMakefile *mf);
186 // Get a definition from the makefile. If it doesn't exist,
187 // return the original string.
188 static const char* GetVariableOrString(const char* str,
189 const cmMakefile* mf);
190 static const char* GetVariableOrNumber(const char* str,
191 const cmMakefile* mf);
194 cmTypeMacro(cmIfCommand, cmCommand);
198 #endif