~ubuntu-branches/ubuntu/breezy/cmake/breezy

« back to all changes in this revision

Viewing changes to Source/cmIfCommand.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Maitland Bottoms
  • Date: 2002-02-14 18:36:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020214183625-8m44isdas2k4l0f7
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: cmIfCommand.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2002/01/03 14:34:40 $
 
7
  Version:   $Revision: 1.20 $
 
8
 
 
9
Copyright (c) 2001 Insight Consortium
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or without
 
13
modification, are permitted provided that the following conditions are met:
 
14
 
 
15
 * Redistributions of source code must retain the above copyright notice,
 
16
   this list of conditions and the following disclaimer.
 
17
 
 
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.
 
21
 
 
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.
 
25
 
 
26
  * Modified source versions must be plainly marked as such, and must not be
 
27
    misrepresented as being the original software.
 
28
 
 
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.
 
39
 
 
40
=========================================================================*/
 
41
#include "cmIfCommand.h"
 
42
#include "cmCacheManager.h"
 
43
 
 
44
bool cmIfFunctionBlocker::
 
45
IsFunctionBlocked(const char *name, const std::vector<std::string> &args, 
 
46
                  cmMakefile &)
 
47
{
 
48
  if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
 
49
    {
 
50
    if (args == m_Args)
 
51
      {
 
52
      return false;
 
53
      }
 
54
    else if(args.empty())
 
55
      {
 
56
      std::string err = "Empty arguments for ";
 
57
      err += name;
 
58
      err += ".  Did you mean ";
 
59
      err += name;
 
60
      err += "( ";
 
61
      for(std::vector<std::string>::const_iterator a = m_Args.begin();
 
62
          a != m_Args.end();++a)
 
63
        {
 
64
        err += *a;
 
65
        err += " ";
 
66
        }
 
67
      err += ")?";
 
68
      cmSystemTools::Error(err.c_str());
 
69
      }
 
70
    }
 
71
  return true;
 
72
}
 
73
 
 
74
bool cmIfFunctionBlocker::
 
75
ShouldRemove(const char *name, const std::vector<std::string> &args, 
 
76
             cmMakefile &mf) 
 
77
{
 
78
  return !this->IsFunctionBlocked(name,args,mf);
 
79
}
 
80
 
 
81
void cmIfFunctionBlocker::
 
82
ScopeEnded(cmMakefile &mf)
 
83
{
 
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)
 
89
    {   
 
90
    errmsg += *j;
 
91
    errmsg += " ";
 
92
    }
 
93
  cmSystemTools::Error(errmsg.c_str());
 
94
}
 
95
 
 
96
bool cmIfCommand::InitialPass(std::vector<std::string> const& args)
 
97
{
 
98
  if(args.size() < 1 )
 
99
    {
 
100
    this->SetError("called with incorrect number of arguments");
 
101
    return false;
 
102
    }
 
103
 
 
104
  // create a function blocker
 
105
  cmIfFunctionBlocker *f = NULL;
 
106
 
 
107
  // check for the different signatures
 
108
  const char *def;
 
109
  const char *def2;
 
110
 
 
111
  if (args.size() == 1)
 
112
    {
 
113
    def = m_Makefile->GetDefinition(args[0].c_str());
 
114
    if(cmSystemTools::IsOff(def))
 
115
      {
 
116
      f = new cmIfFunctionBlocker();
 
117
      }
 
118
    }
 
119
 
 
120
  if (args.size() == 2 && (args[0] == "NOT"))
 
121
    {
 
122
    def = m_Makefile->GetDefinition(args[1].c_str());
 
123
    if(!cmSystemTools::IsOff(def))
 
124
      {
 
125
      f = new cmIfFunctionBlocker();
 
126
      }
 
127
    }
 
128
 
 
129
  if (args.size() == 2 && (args[0] == "COMMAND"))
 
130
    {
 
131
    if(!m_Makefile->CommandExists(args[1].c_str()))
 
132
      {
 
133
      f = new cmIfFunctionBlocker();
 
134
      }
 
135
    }
 
136
 
 
137
  if (args.size() == 2 && (args[0] == "EXISTS"))
 
138
    {
 
139
    std::string tmp = args[1];
 
140
    m_Makefile->ExpandVariablesInString(tmp);
 
141
    if(!cmSystemTools::FileExists(tmp.c_str()))
 
142
      {
 
143
      f = new cmIfFunctionBlocker();
 
144
      }
 
145
    }
 
146
 
 
147
  if (args.size() == 3 && (args[1] == "AND"))
 
148
    {
 
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))
 
152
      {
 
153
      f = new cmIfFunctionBlocker();
 
154
      }
 
155
    }
 
156
  
 
157
  if (args.size() == 3 && (args[1] == "OR"))
 
158
    {
 
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))
 
162
      {
 
163
      f = new cmIfFunctionBlocker();
 
164
      }
 
165
    }
 
166
 
 
167
  if (args.size() == 3 && (args[1] == "MATCHES"))
 
168
    {
 
169
    def = m_Makefile->GetDefinition(args[0].c_str());
 
170
    cmRegularExpression regEntry(args[2].c_str());
 
171
    
 
172
    // check for black line or comment
 
173
    if (!regEntry.find(def))
 
174
      {
 
175
      f = new cmIfFunctionBlocker();
 
176
      }
 
177
    }
 
178
  
 
179
  // if we created a function blocker then set its args
 
180
  if (f)
 
181
    {
 
182
    for(std::vector<std::string>::const_iterator j = args.begin();
 
183
        j != args.end(); ++j)
 
184
      {   
 
185
      f->m_Args.push_back(*j);
 
186
      }
 
187
    m_Makefile->AddFunctionBlocker(f);
 
188
    }
 
189
  
 
190
  return true;
 
191
}
 
192