1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: cmIfCommand.cxx,v $
6
Date: $Date: 2002/01/03 14:34:40 $
7
Version: $Revision: 1.20 $
9
Copyright (c) 2001 Insight Consortium
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
15
* Redistributions of source code must retain the above copyright notice,
16
this list of conditions and the following disclaimer.
18
* Redistributions in binary form must reproduce the above copyright notice,
19
this list of conditions and the following disclaimer in the documentation
20
and/or other materials provided with the distribution.
22
* The name of the Insight Consortium, nor the names of any consortium members,
23
nor of any contributors, may be used to endorse or promote products derived
24
from this software without specific prior written permission.
26
* Modified source versions must be plainly marked as such, and must not be
27
misrepresented as being the original software.
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
30
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
33
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
=========================================================================*/
41
#include "cmIfCommand.h"
42
#include "cmCacheManager.h"
44
bool cmIfFunctionBlocker::
45
IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
48
if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
56
std::string err = "Empty arguments for ";
58
err += ". Did you mean ";
61
for(std::vector<std::string>::const_iterator a = m_Args.begin();
62
a != m_Args.end();++a)
68
cmSystemTools::Error(err.c_str());
74
bool cmIfFunctionBlocker::
75
ShouldRemove(const char *name, const std::vector<std::string> &args,
78
return !this->IsFunctionBlocked(name,args,mf);
81
void cmIfFunctionBlocker::
82
ScopeEnded(cmMakefile &mf)
84
std::string errmsg = "The end of a CMakeLists file was reached with an IF statement that was not closed properly.\nWithin the directory: ";
85
errmsg += mf.GetCurrentDirectory();
86
errmsg += "\nThe arguments are: ";
87
for(std::vector<std::string>::const_iterator j = m_Args.begin();
88
j != m_Args.end(); ++j)
93
cmSystemTools::Error(errmsg.c_str());
96
bool cmIfCommand::InitialPass(std::vector<std::string> const& args)
100
this->SetError("called with incorrect number of arguments");
104
// create a function blocker
105
cmIfFunctionBlocker *f = NULL;
107
// check for the different signatures
111
if (args.size() == 1)
113
def = m_Makefile->GetDefinition(args[0].c_str());
114
if(cmSystemTools::IsOff(def))
116
f = new cmIfFunctionBlocker();
120
if (args.size() == 2 && (args[0] == "NOT"))
122
def = m_Makefile->GetDefinition(args[1].c_str());
123
if(!cmSystemTools::IsOff(def))
125
f = new cmIfFunctionBlocker();
129
if (args.size() == 2 && (args[0] == "COMMAND"))
131
if(!m_Makefile->CommandExists(args[1].c_str()))
133
f = new cmIfFunctionBlocker();
137
if (args.size() == 2 && (args[0] == "EXISTS"))
139
std::string tmp = args[1];
140
m_Makefile->ExpandVariablesInString(tmp);
141
if(!cmSystemTools::FileExists(tmp.c_str()))
143
f = new cmIfFunctionBlocker();
147
if (args.size() == 3 && (args[1] == "AND"))
149
def = m_Makefile->GetDefinition(args[0].c_str());
150
def2 = m_Makefile->GetDefinition(args[2].c_str());
151
if(cmSystemTools::IsOff(def) || cmSystemTools::IsOff(def2))
153
f = new cmIfFunctionBlocker();
157
if (args.size() == 3 && (args[1] == "OR"))
159
def = m_Makefile->GetDefinition(args[0].c_str());
160
def2 = m_Makefile->GetDefinition(args[2].c_str());
161
if(cmSystemTools::IsOff(def) && cmSystemTools::IsOff(def2))
163
f = new cmIfFunctionBlocker();
167
if (args.size() == 3 && (args[1] == "MATCHES"))
169
def = m_Makefile->GetDefinition(args[0].c_str());
170
cmRegularExpression regEntry(args[2].c_str());
172
// check for black line or comment
173
if (!regEntry.find(def))
175
f = new cmIfFunctionBlocker();
179
// if we created a function blocker then set its args
182
for(std::vector<std::string>::const_iterator j = args.begin();
183
j != args.end(); ++j)
185
f->m_Args.push_back(*j);
187
m_Makefile->AddFunctionBlocker(f);