1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmWhileCommand.h"
13 #include "cmIfCommand.h"
15 bool cmWhileFunctionBlocker::
16 IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
17 cmExecutionStatus &inStatus)
19 // at end of for each execute recorded commands
20 if (!cmSystemTools::Strucmp(lff.Name.c_str(),"while"))
22 // record the number of while commands past this one
25 else if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
27 // if this is the endwhile for this while loop then execute
30 // Remove the function blocker for this scope or bail.
31 cmsys::auto_ptr<cmFunctionBlocker>
32 fb(mf.RemoveFunctionBlocker(this, lff));
33 if(!fb.get()) { return false; }
35 std::string errorString;
37 std::vector<std::string> expandedArguments;
38 mf.ExpandArguments(this->Args, expandedArguments);
39 cmake::MessageType messageType;
41 cmIfCommand::IsTrue(expandedArguments,errorString,
46 if (errorString.size())
48 std::string err = "had incorrect arguments: ";
50 for(i =0; i < this->Args.size(); ++i)
52 err += (this->Args[i].Delim?"\"":"");
53 err += this->Args[i].Value;
54 err += (this->Args[i].Delim?"\"":"");
60 mf.IssueMessage(messageType, err);
61 if (messageType == cmake::FATAL_ERROR)
63 cmSystemTools::SetFatalErrorOccured();
68 // Invoke all the functions that were collected in the block.
69 for(unsigned int c = 0; c < this->Functions.size(); ++c)
71 cmExecutionStatus status;
72 mf.ExecuteCommand(this->Functions[c],status);
73 if (status.GetReturnInvoked())
75 inStatus.SetReturnInvoked(true);
78 if (status.GetBreakInvoked())
82 if(cmSystemTools::GetFatalErrorOccured() )
87 expandedArguments.clear();
88 mf.ExpandArguments(this->Args, expandedArguments);
90 cmIfCommand::IsTrue(expandedArguments,errorString,
97 // decrement for each nested while that ends
102 // record the command
103 this->Functions.push_back(lff);
105 // always return true
109 bool cmWhileFunctionBlocker::
110 ShouldRemove(const cmListFileFunction& lff, cmMakefile& )
112 if(!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile"))
114 // if the endwhile has arguments, then make sure
115 // they match the arguments of the matching while
116 if (lff.Arguments.size() == 0 ||
117 lff.Arguments == this->Args)
126 ::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
131 this->SetError("called with incorrect number of arguments");
135 // create a function blocker
136 cmWhileFunctionBlocker *f = new cmWhileFunctionBlocker();
138 this->Makefile->AddFunctionBlocker(f);