diff --git a/Source/cmElseCommand.cxx b/Source/cmElseCommand.cxx index 2e309dd35..661616c1e 100644 --- a/Source/cmElseCommand.cxx +++ b/Source/cmElseCommand.cxx @@ -19,28 +19,6 @@ bool cmElseCommand::InitialPass(std::vector const& args) { - bool isValid; - bool isTrue = cmIfCommand::IsTrue(args,isValid,m_Makefile); - - if (!isValid) - { - this->SetError("An ELSE command had incorrect arguments"); - return false; - } - - // first remove any function blockers for the IF - m_Makefile->RemoveFunctionBlocker("ELSE",args); - - // if is true create a blocker for the else - cmIfFunctionBlocker *f = new cmIfFunctionBlocker(); - f->m_IsBlocking = isTrue; - for(std::vector::const_iterator j = args.begin(); - j != args.end(); ++j) - { - f->m_Args.push_back(*j); - } - m_Makefile->AddFunctionBlocker(f); - - return true; + this->SetError("An ELSE command was found outside of a proper IF ENDIF structure. Or its arguments did not match the opening IF command."); + return false; } - diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 55252da10..0e2027248 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -25,6 +25,13 @@ IsFunctionBlocked(const char *name, const std::vector &args, { if (args == m_Args) { + // if it was an else statement then we should change state + // and block this Else Command + if (!strcmp(name,"ELSE")) + { + m_IsBlocking = !m_IsBlocking; + return true; + } return false; } else if(args.empty()) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 75dd6410e..dc187efe4 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1242,7 +1242,6 @@ bool cmMakefile::IsFunctionBlocked(const char *name, } // loop over all function blockers to see if any block this command - std::list::iterator pos; std::vector expandedArguments; for(std::vector::const_iterator i = args.begin(); i != args.end(); ++i) @@ -1255,8 +1254,10 @@ bool cmMakefile::IsFunctionBlocked(const char *name, expandedArguments.push_back(tmps); } } - for (pos = m_FunctionBlockers.begin(); - pos != m_FunctionBlockers.end(); ++pos) + // evaluate in reverse, this is critical for balanced IF statements etc + std::list::reverse_iterator pos; + for (pos = m_FunctionBlockers.rbegin(); + pos != m_FunctionBlockers.rend(); ++pos) { if ((*pos)->NeedExpandedVariables()) {