summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2002-07-17 14:48:39 (GMT)
committerKen Martin <ken.martin@kitware.com>2002-07-17 14:48:39 (GMT)
commitfcc410de44e59fa4f6145292dc1f13a4498bd8b1 (patch)
tree3a26d56bed8920250e9a23e87444d7bf5e3d62d3
parent3d3caacf9ec9f99cebcfaeb5ab105daa1046f945 (diff)
downloadCMake-fcc410de44e59fa4f6145292dc1f13a4498bd8b1.zip
CMake-fcc410de44e59fa4f6145292dc1f13a4498bd8b1.tar.gz
CMake-fcc410de44e59fa4f6145292dc1f13a4498bd8b1.tar.bz2
fixed if statements inside a foreach
-rw-r--r--Source/cmForEachCommand.cxx8
-rw-r--r--Source/cmForEachCommand.h3
-rw-r--r--Source/cmMakefile.cxx14
-rw-r--r--Tests/Complex/CMakeLists.txt6
-rw-r--r--Tests/ComplexOneConfig/CMakeLists.txt6
-rw-r--r--Tests/ComplexRelativePaths/CMakeLists.txt6
6 files changed, 26 insertions, 17 deletions
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index e4cca41..c95c558 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -21,10 +21,16 @@ bool cmForEachFunctionBlocker::
IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
cmMakefile &mf)
{
+ // prevent recusion and don't let this blobker blobk its own commands
+ if (m_Executing)
+ {
+ return false;
+ }
// at end of for each execute recorded commands
if (!strcmp(name,"ENDFOREACH") && args[0] == m_Args[0])
{
+ m_Executing = true;
std::string variable = "${";
variable += m_Args[0];
variable += "}";
@@ -90,7 +96,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& argsIn)
std::vector<std::string> args;
cmSystemTools::ExpandListArguments(argsIn, args);
- if(args.size() < 2 )
+ if(args.size() < 1)
{
this->SetError("called with incorrect number of arguments");
return false;
diff --git a/Source/cmForEachCommand.h b/Source/cmForEachCommand.h
index 064e30b..910f3d5 100644
--- a/Source/cmForEachCommand.h
+++ b/Source/cmForEachCommand.h
@@ -29,7 +29,7 @@
class cmForEachFunctionBlocker : public cmFunctionBlocker
{
public:
- cmForEachFunctionBlocker() {}
+ cmForEachFunctionBlocker() {m_Executing = false;}
virtual ~cmForEachFunctionBlocker() {}
virtual bool IsFunctionBlocked(const char *name,
const std::vector<std::string> &args,
@@ -44,6 +44,7 @@ public:
std::vector<std::string> m_Args;
std::vector<std::string> m_Commands;
std::vector<std::vector<std::string> > m_CommandArguments;
+ bool m_Executing;
};
/** \class cmForEachCommand
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 496704a..9dbf31d 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -193,6 +193,12 @@ bool cmMakefile::CommandExists(const char* name) const
void cmMakefile::ExecuteCommand(std::string &name,
std::vector<std::string> const& arguments)
{
+ // quick return if blocked
+ if(this->IsFunctionBlocked(name.c_str(), arguments))
+ {
+ return;
+ }
+ // execute the command
RegisteredCommandsMap::iterator pos = m_Commands.find(name);
if(pos != m_Commands.end())
{
@@ -342,12 +348,8 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
for(size_t i =0; i < numberFunctions; ++i)
{
cmListFileFunction& curFunction = lf->m_Functions[i];
- if(!this->IsFunctionBlocked(curFunction.m_Name.c_str(),
- curFunction.m_Arguments))
- {
- this->ExecuteCommand(curFunction.m_Name,
- curFunction.m_Arguments);
- }
+ this->ExecuteCommand(curFunction.m_Name,
+ curFunction.m_Arguments);
}
// send scope ended to and funciton blockers
diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt
index 2d6de20..068b47e 100644
--- a/Tests/Complex/CMakeLists.txt
+++ b/Tests/Complex/CMakeLists.txt
@@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH.
#
FOREACH(x "a")
- IF(1)
+ IF(${x} MATCHES "a")
# Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
- ELSE(1)
+ ELSE(${x} MATCHES "a")
# Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
- ENDIF(1)
+ ENDIF(${x} MATCHES "a")
ENDFOREACH(x)
diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt
index 2d6de20..068b47e 100644
--- a/Tests/ComplexOneConfig/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/CMakeLists.txt
@@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH.
#
FOREACH(x "a")
- IF(1)
+ IF(${x} MATCHES "a")
# Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
- ELSE(1)
+ ELSE(${x} MATCHES "a")
# Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
- ENDIF(1)
+ ENDIF(${x} MATCHES "a")
ENDFOREACH(x)
diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt
index 2d6de20..068b47e 100644
--- a/Tests/ComplexRelativePaths/CMakeLists.txt
+++ b/Tests/ComplexRelativePaths/CMakeLists.txt
@@ -164,13 +164,13 @@ REMOVE(REMOVE_STRING ${removeVar1} f)
# Test an IF inside a FOREACH.
#
FOREACH(x "a")
- IF(1)
+ IF(${x} MATCHES "a")
# Should always execute.
SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1)
- ELSE(1)
+ ELSE(${x} MATCHES "a")
# Should never execute.
SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1)
- ENDIF(1)
+ ENDIF(${x} MATCHES "a")
ENDFOREACH(x)