1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmForEachCommand.cxx,v $
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
,
24 // prevent recusion and don't let this blobker blobk its own commands
30 // at end of for each execute recorded commands
31 if (!strcmp(name
,"ENDFOREACH") && args
[0] == m_Args
[0])
34 std::string variable
= "${";
35 variable
+= m_Args
[0];
37 std::vector
<std::string
>::const_iterator j
= m_Args
.begin();
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(),
53 newArgs
.push_back(tmps
);
56 mf
.ExecuteCommand(m_Commands
[c
],newArgs
);
63 m_Commands
.push_back(name
);
64 std::vector
<std::string
> newArgs
;
65 for(std::vector
<std::string
>::const_iterator j
= args
.begin();
68 newArgs
.push_back(*j
);
70 m_CommandArguments
.push_back(newArgs
);
76 bool cmForEachFunctionBlocker::
77 ShouldRemove(const char *name
, const std::vector
<std::string
> &args
,
80 if (!strcmp(name
,"ENDFOREACH") && args
[0] == m_Args
[0])
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
);
101 this->SetError("called with incorrect number of arguments");
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
);