1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmIfCommand.cxx,v $
6 Date: $Date: 2002-07-11 18:58:26 $
7 Version: $Revision: 1.29 $
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 =========================================================================*/
17 #include "cmIfCommand.h"
18 #include "cmCacheManager.h"
20 bool cmIfFunctionBlocker::
21 IsFunctionBlocked(const char *name
, const std::vector
<std::string
> &args
,
24 if (!strcmp(name
,"ELSE") || !strcmp(name
,"ENDIF"))
32 std::string err
= "Empty arguments for ";
34 err
+= ". Did you mean ";
37 for(std::vector
<std::string
>::const_iterator a
= m_Args
.begin();
38 a
!= m_Args
.end();++a
)
44 cmSystemTools::Error(err
.c_str());
50 bool cmIfFunctionBlocker::
51 ShouldRemove(const char *name
, const std::vector
<std::string
> &args
,
54 if (!strcmp(name
,"ELSE") || !strcmp(name
,"ENDIF"))
64 void cmIfFunctionBlocker::
65 ScopeEnded(cmMakefile
&mf
)
67 std::string errmsg
= "The end of a CMakeLists file was reached with an IF statement that was not closed properly.\nWithin the directory: ";
68 errmsg
+= mf
.GetCurrentDirectory();
69 errmsg
+= "\nThe arguments are: ";
70 for(std::vector
<std::string
>::const_iterator j
= m_Args
.begin();
71 j
!= m_Args
.end(); ++j
)
76 cmSystemTools::Error(errmsg
.c_str());
79 bool cmIfCommand::InitialPass(std::vector
<std::string
> const& args
)
82 bool isTrue
= cmIfCommand::IsTrue(args
,isValid
,m_Makefile
);
86 this->SetError("An IF command had incorrect arguments");
90 cmIfFunctionBlocker
*f
= new cmIfFunctionBlocker();
91 // if is isn't true block the commands
92 f
->m_IsBlocking
= !isTrue
;
93 for(std::vector
<std::string
>::const_iterator j
= args
.begin();
96 f
->m_Args
.push_back(*j
);
98 m_Makefile
->AddFunctionBlocker(f
);
103 bool cmIfCommand::IsTrue(const std::vector
<std::string
> &args
, bool &isValid
,
104 const cmMakefile
*makefile
)
106 // check for the different signatures
117 if (args
.size() == 1)
119 def
= makefile
->GetDefinition(args
[0].c_str());
120 if(cmSystemTools::IsOff(def
))
127 if (args
.size() == 2 && (args
[0] == "NOT"))
129 def
= makefile
->GetDefinition(args
[1].c_str());
130 if(!cmSystemTools::IsOff(def
))
138 if (args
.size() == 2 && (args
[0] == "COMMAND"))
140 if(!makefile
->CommandExists(args
[1].c_str()))
147 if (args
.size() == 2 && (args
[0] == "EXISTS"))
149 if(!cmSystemTools::FileExists(args
[1].c_str()))
156 if (args
.size() == 3 && (args
[1] == "AND"))
158 def
= makefile
->GetDefinition(args
[0].c_str());
159 def2
= makefile
->GetDefinition(args
[2].c_str());
160 if(cmSystemTools::IsOff(def
) || cmSystemTools::IsOff(def2
))
167 if (args
.size() == 3 && (args
[1] == "OR"))
169 def
= makefile
->GetDefinition(args
[0].c_str());
170 def2
= makefile
->GetDefinition(args
[2].c_str());
171 if(cmSystemTools::IsOff(def
) && cmSystemTools::IsOff(def2
))
178 if (args
.size() == 3 && (args
[1] == "MATCHES"))
180 def
= makefile
->GetDefinition(args
[0].c_str());
183 def
= args
[0].c_str();
185 cmRegularExpression
regEntry(args
[2].c_str());
187 // check for black line or comment
188 if (!regEntry
.find(def
))
195 if (args
.size() == 3 && (args
[1] == "LESS"))
197 def
= makefile
->GetDefinition(args
[0].c_str());
198 def2
= makefile
->GetDefinition(args
[2].c_str());
201 def
= args
[0].c_str();
205 def2
= args
[2].c_str();
207 if(atof(def
) >= atof(def2
))
214 if (args
.size() == 3 && (args
[1] == "GREATER"))
216 def
= makefile
->GetDefinition(args
[0].c_str());
217 def2
= makefile
->GetDefinition(args
[2].c_str());
220 def
= args
[0].c_str();
224 def2
= args
[2].c_str();
226 if(atof(def
) <= atof(def2
))
233 if (args
.size() == 3 && (args
[1] == "STRLESS"))
235 def
= makefile
->GetDefinition(args
[0].c_str());
236 def2
= makefile
->GetDefinition(args
[2].c_str());
237 if(strcmp(def
,def2
) >= 0)
244 if (args
.size() == 3 && (args
[1] == "STRGREATER"))
246 def
= makefile
->GetDefinition(args
[0].c_str());
247 def2
= makefile
->GetDefinition(args
[2].c_str());
248 if(strcmp(def
,def2
) <= 0)