ENH: change the search path order (if several Tcl/Tk are installed, the "current...
[cmake.git] / Source / cmForEachCommand.cxx
blob3c692948450fa68a51918ef57476dd945d40540a
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmForEachCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-07-17 14:48:05 $
7 Version: $Revision: 1.7 $
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 "cmForEachCommand.h"
18 #include "cmCacheManager.h"
20 bool cmForEachFunctionBlocker::
21 IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
22 cmMakefile &mf)
24 // prevent recusion and don't let this blobker blobk its own commands
25 if (m_Executing)
27 return false;
30 // at end of for each execute recorded commands
31 if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
33 m_Executing = true;
34 std::string variable = "${";
35 variable += m_Args[0];
36 variable += "}";
37 std::vector<std::string>::const_iterator j = m_Args.begin();
38 ++j;
40 for( ; j != m_Args.end(); ++j)
42 // perform string replace
43 for(unsigned int c = 0; c < m_Commands.size(); ++c)
45 std::vector<std::string> newArgs;
46 for (std::vector<std::string>::const_iterator k =
47 m_CommandArguments[c].begin();
48 k != m_CommandArguments[c].end(); ++k)
50 std::string tmps = *k;
51 cmSystemTools::ReplaceString(tmps, variable.c_str(),
52 j->c_str());
53 newArgs.push_back(tmps);
55 // execute command
56 mf.ExecuteCommand(m_Commands[c],newArgs);
59 return false;
62 // record the command
63 m_Commands.push_back(name);
64 std::vector<std::string> newArgs;
65 for(std::vector<std::string>::const_iterator j = args.begin();
66 j != args.end(); ++j)
68 newArgs.push_back(*j);
70 m_CommandArguments.push_back(newArgs);
72 // always return true
73 return true;
76 bool cmForEachFunctionBlocker::
77 ShouldRemove(const char *name, const std::vector<std::string> &args,
78 cmMakefile &)
80 if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
82 return true;
84 return false;
87 void cmForEachFunctionBlocker::
88 ScopeEnded(cmMakefile &mf)
90 cmSystemTools::Error("The end of a CMakeLists file was reached with a FOREACH statement that was not closed properly. Within the directory: ",
91 mf.GetCurrentDirectory());
94 bool cmForEachCommand::InitialPass(std::vector<std::string> const& argsIn)
96 std::vector<std::string> args;
97 cmSystemTools::ExpandListArguments(argsIn, args);
99 if(args.size() < 1)
101 this->SetError("called with incorrect number of arguments");
102 return false;
105 // create a function blocker
106 cmForEachFunctionBlocker *f = new cmForEachFunctionBlocker();
107 for(std::vector<std::string>::const_iterator j = args.begin();
108 j != args.end(); ++j)
110 f->m_Args.push_back(*j);
112 m_Makefile->AddFunctionBlocker(f);
114 return true;