2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-04-19 21:39:03 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-04-19 21:39:03 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-04-19 21:39:03 +00:00
|
|
|
#include "cmIfCommand.h"
|
2007-08-29 15:58:38 +00:00
|
|
|
#include "cmStringCommand.h"
|
|
|
|
|
2003-05-24 14:07:58 +00:00
|
|
|
#include <stdlib.h> // required for atof
|
2004-06-11 19:07:17 +00:00
|
|
|
#include <list>
|
2003-06-23 18:10:12 +00:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2009-10-27 13:01:33 +00:00
|
|
|
|
|
|
|
static std::string cmIfCommandError(
|
|
|
|
cmMakefile* mf, std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
cmLocalGenerator* lg = mf->GetLocalGenerator();
|
|
|
|
std::string err = "given arguments:\n ";
|
|
|
|
for(std::vector<std::string>::const_iterator i = args.begin();
|
|
|
|
i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
err += " ";
|
|
|
|
err += lg->EscapeForCMake(i->c_str());
|
|
|
|
}
|
|
|
|
err += "\n";
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
2001-04-19 21:39:03 +00:00
|
|
|
bool cmIfFunctionBlocker::
|
2009-06-12 14:07:05 +00:00
|
|
|
IsFunctionBlocked(const cmListFileFunction& lff,
|
2008-06-26 17:01:35 +00:00
|
|
|
cmMakefile &mf,
|
2008-01-23 15:28:26 +00:00
|
|
|
cmExecutionStatus &inStatus)
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
// we start by recording all the functions
|
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"if"))
|
2006-12-12 15:07:20 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
this->ScopeDepth++;
|
2006-12-12 15:07:20 +00:00
|
|
|
}
|
2008-01-23 15:28:26 +00:00
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
this->ScopeDepth--;
|
|
|
|
// if this is the endif for this if statement, then start executing
|
2009-06-12 14:07:05 +00:00
|
|
|
if (!this->ScopeDepth)
|
2006-09-22 15:23:51 +00:00
|
|
|
{
|
2009-01-20 19:36:18 +00:00
|
|
|
// Remove the function blocker for this scope or bail.
|
2009-01-21 14:49:00 +00:00
|
|
|
cmsys::auto_ptr<cmFunctionBlocker>
|
|
|
|
fb(mf.RemoveFunctionBlocker(this, lff));
|
2009-01-20 19:36:18 +00:00
|
|
|
if(!fb.get()) { return false; }
|
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
// execute the functions for the true parts of the if statement
|
|
|
|
cmExecutionStatus status;
|
|
|
|
int scopeDepth = 0;
|
|
|
|
for(unsigned int c = 0; c < this->Functions.size(); ++c)
|
2002-08-09 16:00:49 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
// keep track of scope depth
|
|
|
|
if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"if"))
|
|
|
|
{
|
|
|
|
scopeDepth++;
|
|
|
|
}
|
|
|
|
if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"endif"))
|
|
|
|
{
|
|
|
|
scopeDepth--;
|
|
|
|
}
|
|
|
|
// watch for our state change
|
|
|
|
if (scopeDepth == 0 &&
|
|
|
|
!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),"else"))
|
|
|
|
{
|
|
|
|
this->IsBlocking = this->HasRun;
|
|
|
|
this->HasRun = true;
|
2012-05-14 22:50:30 +00:00
|
|
|
|
|
|
|
// if trace is enabled, print a (trivially) evaluated "else"
|
|
|
|
// statement
|
|
|
|
if(!this->IsBlocking && mf.GetCMakeInstance()->GetTrace())
|
|
|
|
{
|
|
|
|
mf.PrintCommandTrace(this->Functions[c]);
|
|
|
|
}
|
2008-01-23 15:28:26 +00:00
|
|
|
}
|
|
|
|
else if (scopeDepth == 0 && !cmSystemTools::Strucmp
|
|
|
|
(this->Functions[c].Name.c_str(),"elseif"))
|
2006-09-22 15:23:51 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
if (this->HasRun)
|
2006-09-22 15:23:51 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
this->IsBlocking = true;
|
2006-09-22 15:23:51 +00:00
|
|
|
}
|
2008-01-23 15:28:26 +00:00
|
|
|
else
|
|
|
|
{
|
2009-01-20 19:35:22 +00:00
|
|
|
// Place this call on the call stack.
|
|
|
|
cmMakefileCall stack_manager(&mf, this->Functions[c], status);
|
|
|
|
static_cast<void>(stack_manager);
|
|
|
|
|
2012-05-14 22:50:30 +00:00
|
|
|
// if trace is enabled, print the evaluated "elseif" statement
|
|
|
|
if(mf.GetCMakeInstance()->GetTrace())
|
|
|
|
{
|
|
|
|
mf.PrintCommandTrace(this->Functions[c]);
|
|
|
|
}
|
|
|
|
|
2008-06-28 15:16:36 +00:00
|
|
|
std::string errorString;
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
std::vector<std::string> expandedArguments;
|
2009-06-12 14:07:05 +00:00
|
|
|
mf.ExpandArguments(this->Functions[c].Arguments,
|
2008-01-23 15:28:26 +00:00
|
|
|
expandedArguments);
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2009-06-12 15:10:26 +00:00
|
|
|
cmake::MessageType messType;
|
2009-06-12 14:07:05 +00:00
|
|
|
bool isTrue =
|
|
|
|
cmIfCommand::IsTrue(expandedArguments, errorString,
|
2009-06-12 15:10:26 +00:00
|
|
|
&mf, messType);
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-06-28 15:16:36 +00:00
|
|
|
if (errorString.size())
|
2008-01-23 15:28:26 +00:00
|
|
|
{
|
2009-10-27 13:01:33 +00:00
|
|
|
std::string err = cmIfCommandError(&mf, expandedArguments);
|
2008-01-23 15:28:26 +00:00
|
|
|
err += errorString;
|
2009-06-12 15:10:26 +00:00
|
|
|
mf.IssueMessage(messType, err);
|
|
|
|
if (messType == cmake::FATAL_ERROR)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-23 15:28:26 +00:00
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
if (isTrue)
|
|
|
|
{
|
|
|
|
this->IsBlocking = false;
|
|
|
|
this->HasRun = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
// should we execute?
|
|
|
|
else if (!this->IsBlocking)
|
2006-09-22 15:23:51 +00:00
|
|
|
{
|
2008-01-23 15:28:26 +00:00
|
|
|
status.Clear();
|
|
|
|
mf.ExecuteCommand(this->Functions[c],status);
|
|
|
|
if (status.GetReturnInvoked())
|
|
|
|
{
|
|
|
|
inStatus.SetReturnInvoked(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (status.GetBreakInvoked())
|
|
|
|
{
|
|
|
|
inStatus.SetBreakInvoked(true);
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-22 15:23:51 +00:00
|
|
|
}
|
2002-08-09 16:00:49 +00:00
|
|
|
}
|
2006-09-22 15:23:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
// record the command
|
|
|
|
this->Functions.push_back(lff);
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-01-23 15:28:26 +00:00
|
|
|
// always return true
|
|
|
|
return true;
|
2001-04-19 21:39:03 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
2002-12-11 23:13:33 +00:00
|
|
|
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
2008-03-01 02:33:33 +00:00
|
|
|
cmMakefile&)
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2006-05-31 15:19:39 +00:00
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
|
2002-07-10 15:38:38 +00:00
|
|
|
{
|
2008-02-29 17:18:11 +00:00
|
|
|
// if the endif has arguments, then make sure
|
|
|
|
// they match the arguments of the matching if
|
|
|
|
if (lff.Arguments.size() == 0 ||
|
|
|
|
lff.Arguments == this->Args)
|
2002-07-10 15:38:38 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 17:50:01 +00:00
|
|
|
|
2002-07-10 15:38:38 +00:00
|
|
|
return false;
|
2001-04-19 21:39:03 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
2006-05-11 19:50:11 +00:00
|
|
|
bool cmIfCommand
|
2009-06-12 14:07:05 +00:00
|
|
|
::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
|
2008-01-23 15:28:26 +00:00
|
|
|
cmExecutionStatus &)
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2008-06-28 15:16:36 +00:00
|
|
|
std::string errorString;
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2002-12-11 23:13:33 +00:00
|
|
|
std::vector<std::string> expandedArguments;
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Makefile->ExpandArguments(args, expandedArguments);
|
2009-06-12 14:07:05 +00:00
|
|
|
|
|
|
|
cmake::MessageType status;
|
|
|
|
bool isTrue =
|
|
|
|
cmIfCommand::IsTrue(expandedArguments,errorString,
|
|
|
|
this->Makefile, status);
|
|
|
|
|
2008-06-28 15:16:36 +00:00
|
|
|
if (errorString.size())
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2009-10-27 13:01:33 +00:00
|
|
|
std::string err = cmIfCommandError(this->Makefile, expandedArguments);
|
2004-08-03 12:13:54 +00:00
|
|
|
err += errorString;
|
2009-06-12 14:07:05 +00:00
|
|
|
if (status == cmake::FATAL_ERROR)
|
|
|
|
{
|
|
|
|
this->SetError(err.c_str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(status, err);
|
|
|
|
}
|
2001-04-19 21:39:03 +00:00
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2002-07-10 15:38:38 +00:00
|
|
|
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
|
|
|
|
// if is isn't true block the commands
|
2008-01-23 15:28:26 +00:00
|
|
|
f->ScopeDepth = 1;
|
2006-03-15 16:02:08 +00:00
|
|
|
f->IsBlocking = !isTrue;
|
2006-09-22 15:23:51 +00:00
|
|
|
if (isTrue)
|
|
|
|
{
|
|
|
|
f->HasRun = true;
|
|
|
|
}
|
2006-03-15 16:02:08 +00:00
|
|
|
f->Args = args;
|
|
|
|
this->Makefile->AddFunctionBlocker(f);
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2002-07-01 12:49:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2001-08-06 21:01:26 +00:00
|
|
|
|
2009-06-12 14:07:05 +00:00
|
|
|
namespace
|
2005-11-17 14:32:07 +00:00
|
|
|
{
|
2009-06-12 14:07:05 +00:00
|
|
|
//=========================================================================
|
2009-10-27 13:07:39 +00:00
|
|
|
bool GetBooleanValue(std::string& arg, cmMakefile* mf)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
// Check basic constants.
|
|
|
|
if (arg == "0")
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
return false;
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2009-10-27 13:07:39 +00:00
|
|
|
if (arg == "1")
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
return true;
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 13:07:39 +00:00
|
|
|
// Check named constants.
|
|
|
|
if (cmSystemTools::IsOn(arg.c_str()))
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (cmSystemTools::IsOff(arg.c_str()))
|
|
|
|
{
|
|
|
|
return false;
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 13:07:39 +00:00
|
|
|
// Check for numbers.
|
|
|
|
if(!arg.empty())
|
|
|
|
{
|
|
|
|
char* end;
|
|
|
|
double d = strtod(arg.c_str(), &end);
|
|
|
|
if(*end == '\0')
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
// The whole string is a number. Use C conversion to bool.
|
|
|
|
return d? true:false;
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2009-10-27 13:07:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check definition.
|
|
|
|
const char* def = mf->GetDefinition(arg.c_str());
|
|
|
|
return !cmSystemTools::IsOff(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Boolean value behavior from CMake 2.6.4 and below.
|
|
|
|
bool GetBooleanValueOld(std::string const& arg, cmMakefile* mf, bool one)
|
|
|
|
{
|
|
|
|
if(one)
|
|
|
|
{
|
|
|
|
// Old IsTrue behavior for single argument.
|
|
|
|
if(arg == "0")
|
|
|
|
{ return false; }
|
|
|
|
else if(arg == "1")
|
|
|
|
{ return true; }
|
|
|
|
else
|
|
|
|
{ return !cmSystemTools::IsOff(mf->GetDefinition(arg.c_str())); }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Old GetVariableOrNumber behavior.
|
|
|
|
const char* def = mf->GetDefinition(arg.c_str());
|
|
|
|
if(!def && atoi(arg.c_str()))
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
def = arg.c_str();
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2009-10-27 13:07:39 +00:00
|
|
|
return !cmSystemTools::IsOff(def);
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// returns the resulting boolean value
|
|
|
|
bool GetBooleanValueWithAutoDereference(
|
|
|
|
std::string &newArg,
|
|
|
|
cmMakefile *makefile,
|
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
2009-10-27 13:07:39 +00:00
|
|
|
cmake::MessageType &status,
|
|
|
|
bool oneArg = false)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
// Use the policy if it is set.
|
|
|
|
if (Policy12Status == cmPolicies::NEW)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2009-10-27 13:07:39 +00:00
|
|
|
return GetBooleanValue(newArg, makefile);
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2009-10-27 13:07:39 +00:00
|
|
|
else if (Policy12Status == cmPolicies::OLD)
|
|
|
|
{
|
|
|
|
return GetBooleanValueOld(newArg, makefile, oneArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check policy only if old and new results differ.
|
|
|
|
bool newResult = GetBooleanValue(newArg, makefile);
|
|
|
|
bool oldResult = GetBooleanValueOld(newArg, makefile, oneArg);
|
|
|
|
if(newResult != oldResult)
|
|
|
|
{
|
|
|
|
switch(Policy12Status)
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
{
|
|
|
|
cmPolicies* policies = makefile->GetPolicies();
|
|
|
|
errorString = "An argument named \"" + newArg
|
|
|
|
+ "\" appears in a conditional statement. "
|
|
|
|
+ policies->GetPolicyWarning(cmPolicies::CMP0012);
|
|
|
|
status = cmake::AUTHOR_WARNING;
|
|
|
|
}
|
|
|
|
case cmPolicies::OLD:
|
|
|
|
return oldResult;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
{
|
|
|
|
cmPolicies* policies = makefile->GetPolicies();
|
|
|
|
errorString = "An argument named \"" + newArg
|
|
|
|
+ "\" appears in a conditional statement. "
|
|
|
|
+ policies->GetRequiredPolicyError(cmPolicies::CMP0012);
|
|
|
|
status = cmake::FATAL_ERROR;
|
|
|
|
}
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newResult;
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
2005-11-17 14:44:32 +00:00
|
|
|
void IncrementArguments(std::list<std::string> &newArgs,
|
|
|
|
std::list<std::string>::iterator &argP1,
|
|
|
|
std::list<std::string>::iterator &argP2)
|
|
|
|
{
|
2005-11-17 14:32:07 +00:00
|
|
|
if (argP1 != newArgs.end())
|
|
|
|
{
|
2005-11-17 14:44:32 +00:00
|
|
|
argP1++;
|
|
|
|
argP2 = argP1;
|
|
|
|
if (argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
argP2++;
|
|
|
|
}
|
2005-11-17 14:32:07 +00:00
|
|
|
}
|
2005-11-17 14:44:32 +00:00
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// helper function to reduce code duplication
|
|
|
|
void HandlePredicate(bool value, int &reducible,
|
|
|
|
std::list<std::string>::iterator &arg,
|
|
|
|
std::list<std::string> &newArgs,
|
|
|
|
std::list<std::string>::iterator &argP1,
|
|
|
|
std::list<std::string>::iterator &argP2)
|
|
|
|
{
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
*arg = "1";
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
else
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
|
|
|
reducible = 1;
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// helper function to reduce code duplication
|
|
|
|
void HandleBinaryOp(bool value, int &reducible,
|
|
|
|
std::list<std::string>::iterator &arg,
|
|
|
|
std::list<std::string> &newArgs,
|
|
|
|
std::list<std::string>::iterator &argP1,
|
|
|
|
std::list<std::string>::iterator &argP2)
|
|
|
|
{
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
*arg = "1";
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
else
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
|
|
|
reducible = 1;
|
|
|
|
}
|
2004-05-06 13:47:25 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// level 0 processes parenthetical expressions
|
|
|
|
bool HandleLevel0(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &errorString,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
2004-05-04 13:16:06 +00:00
|
|
|
int reducible;
|
2004-05-01 14:08:14 +00:00
|
|
|
do
|
2001-08-06 21:01:26 +00:00
|
|
|
{
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 0;
|
2004-06-11 19:07:17 +00:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2004-05-01 14:08:14 +00:00
|
|
|
while (arg != newArgs.end())
|
2001-08-06 21:01:26 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
if (*arg == "(")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
// search for the closing paren for this opening one
|
|
|
|
std::list<std::string>::iterator argClose;
|
|
|
|
argClose = arg;
|
|
|
|
argClose++;
|
|
|
|
unsigned int depth = 1;
|
|
|
|
while (argClose != newArgs.end() && depth)
|
|
|
|
{
|
|
|
|
if (*argClose == "(")
|
|
|
|
{
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
if (*argClose == ")")
|
|
|
|
{
|
|
|
|
depth--;
|
|
|
|
}
|
|
|
|
argClose++;
|
|
|
|
}
|
|
|
|
if (depth)
|
|
|
|
{
|
2008-06-28 15:16:36 +00:00
|
|
|
errorString = "mismatched parenthesis in condition";
|
2009-06-12 14:07:05 +00:00
|
|
|
status = cmake::FATAL_ERROR;
|
2008-06-26 17:01:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// store the reduced args in this vector
|
|
|
|
std::vector<std::string> newArgs2;
|
|
|
|
|
|
|
|
// copy to the list structure
|
|
|
|
std::list<std::string>::iterator argP1 = arg;
|
|
|
|
argP1++;
|
|
|
|
for(; argP1 != argClose; argP1++)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
newArgs2.push_back(*argP1);
|
|
|
|
}
|
|
|
|
newArgs2.pop_back();
|
2008-10-01 13:04:27 +00:00
|
|
|
// now recursively invoke IsTrue to handle the values inside the
|
|
|
|
// parenthetical expression
|
2009-06-12 14:07:05 +00:00
|
|
|
bool value =
|
|
|
|
cmIfCommand::IsTrue(newArgs2, errorString, makefile, status);
|
2008-06-26 17:01:35 +00:00
|
|
|
if(value)
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
|
|
|
*arg = "1";
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
else
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2006-03-22 19:06:52 +00:00
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
argP1 = arg;
|
2008-06-26 17:01:35 +00:00
|
|
|
argP1++;
|
|
|
|
// remove the now evaluated parenthetical expression
|
2009-06-12 14:07:05 +00:00
|
|
|
newArgs.erase(argP1,argClose);
|
2008-06-26 17:01:35 +00:00
|
|
|
}
|
|
|
|
++arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (reducible);
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// level one handles most predicates except for NOT
|
|
|
|
bool HandleLevel1(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &, cmake::MessageType &)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
int reducible;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
reducible = 0;
|
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
|
|
|
while (arg != newArgs.end())
|
|
|
|
{
|
|
|
|
argP1 = arg;
|
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
|
|
|
// does a file exist
|
|
|
|
if (*arg == "EXISTS" && argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileExists((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2006-03-22 19:06:52 +00:00
|
|
|
}
|
2006-08-25 20:31:07 +00:00
|
|
|
// does a directory with this name exist
|
2006-03-22 19:06:52 +00:00
|
|
|
if (*arg == "IS_DIRECTORY" && argP1 != newArgs.end())
|
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileIsDirectory((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2009-10-21 17:11:16 +00:00
|
|
|
// does a symlink with this name exist
|
|
|
|
if (*arg == "IS_SYMLINK" && argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileIsSymlink((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2007-06-06 12:49:18 +00:00
|
|
|
// is the given path an absolute path ?
|
|
|
|
if (*arg == "IS_ABSOLUTE" && argP1 != newArgs.end())
|
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileIsFullPath((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2007-06-06 12:49:18 +00:00
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
// does a command exist
|
2004-06-11 19:07:17 +00:00
|
|
|
if (*arg == "COMMAND" && argP1 != newArgs.end())
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
HandlePredicate(
|
|
|
|
makefile->CommandExists((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2008-03-20 22:25:59 +00:00
|
|
|
// does a policy exist
|
|
|
|
if (*arg == "POLICY" && argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
cmPolicies::PolicyID pid;
|
2008-06-26 17:01:35 +00:00
|
|
|
HandlePredicate(
|
|
|
|
makefile->GetPolicies()->GetPolicyID((argP1)->c_str(), pid),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2008-03-20 22:25:59 +00:00
|
|
|
}
|
2008-08-20 15:45:16 +00:00
|
|
|
// does a target exist
|
|
|
|
if (*arg == "TARGET" && argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
HandlePredicate(
|
|
|
|
makefile->FindTargetToUse((argP1)->c_str())? true:false,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
// is a variable defined
|
2004-06-11 19:07:17 +00:00
|
|
|
if (*arg == "DEFINED" && argP1 != newArgs.end())
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2006-03-30 18:49:56 +00:00
|
|
|
size_t argP1len = argP1->size();
|
2007-05-17 21:40:59 +00:00
|
|
|
bool bdef = false;
|
2006-02-10 19:41:31 +00:00
|
|
|
if(argP1len > 4 && argP1->substr(0, 4) == "ENV{" &&
|
|
|
|
argP1->operator[](argP1len-1) == '}')
|
|
|
|
{
|
|
|
|
std::string env = argP1->substr(4, argP1len-5);
|
2007-05-17 21:40:59 +00:00
|
|
|
bdef = cmSystemTools::GetEnv(env.c_str())?true:false;
|
2006-02-10 19:41:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-17 21:40:59 +00:00
|
|
|
bdef = makefile->IsDefinitionSet((argP1)->c_str());
|
2006-02-10 19:41:31 +00:00
|
|
|
}
|
2008-06-26 17:01:35 +00:00
|
|
|
HandlePredicate(bdef, reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
|
|
|
++arg;
|
2001-08-06 21:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
while (reducible);
|
2008-06-26 17:01:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-04 12:50:37 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// level two handles most binary operations except for AND OR
|
|
|
|
bool HandleLevel2(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &errorString,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
int reducible;
|
|
|
|
const char *def;
|
|
|
|
const char *def2;
|
2004-05-01 14:08:14 +00:00
|
|
|
do
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 0;
|
2004-06-11 19:07:17 +00:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 17:01:35 +00:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 14:08:14 +00:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 15:16:20 +00:00
|
|
|
{
|
2004-06-11 19:07:17 +00:00
|
|
|
argP1 = arg;
|
2005-11-17 14:32:07 +00:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-06-11 19:07:17 +00:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 14:07:05 +00:00
|
|
|
*(argP1) == "MATCHES")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-08-03 12:13:54 +00:00
|
|
|
const char* rex = (argP2)->c_str();
|
2007-08-29 15:58:38 +00:00
|
|
|
cmStringCommand::ClearMatches(makefile);
|
2004-08-03 12:13:54 +00:00
|
|
|
cmsys::RegularExpression regEntry;
|
|
|
|
if ( !regEntry.compile(rex) )
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Regular expression \"" << rex << "\" cannot compile";
|
2008-06-28 15:16:36 +00:00
|
|
|
errorString = error.str();
|
2009-06-12 14:07:05 +00:00
|
|
|
status = cmake::FATAL_ERROR;
|
2004-08-03 12:13:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
if (regEntry.find(def))
|
|
|
|
{
|
2007-08-29 15:58:38 +00:00
|
|
|
cmStringCommand::StoreMatches(makefile, regEntry);
|
2007-08-29 18:35:06 +00:00
|
|
|
*arg = "1";
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
2004-06-11 19:07:17 +00:00
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2005-11-17 14:32:07 +00:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 1;
|
|
|
|
}
|
2002-07-01 12:49:36 +00:00
|
|
|
|
2009-06-12 14:07:05 +00:00
|
|
|
if (argP1 != newArgs.end() && *arg == "MATCHES")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
|
|
|
*arg = "0";
|
2004-06-11 19:07:17 +00:00
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2005-11-17 14:32:07 +00:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 1;
|
|
|
|
}
|
2001-08-06 21:01:26 +00:00
|
|
|
|
2004-06-11 19:07:17 +00:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 14:07:05 +00:00
|
|
|
(*(argP1) == "LESS" || *(argP1) == "GREATER" ||
|
|
|
|
*(argP1) == "EQUAL"))
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-06-11 19:07:17 +00:00
|
|
|
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
|
2006-10-25 14:31:26 +00:00
|
|
|
double lhs;
|
|
|
|
double rhs;
|
2008-06-26 17:01:35 +00:00
|
|
|
bool result;
|
2006-10-25 14:57:26 +00:00
|
|
|
if(sscanf(def, "%lg", &lhs) != 1 ||
|
|
|
|
sscanf(def2, "%lg", &rhs) != 1)
|
2006-10-25 14:31:26 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
result = false;
|
2006-10-25 14:31:26 +00:00
|
|
|
}
|
2006-10-25 14:57:26 +00:00
|
|
|
else if (*(argP1) == "LESS")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
result = (lhs < rhs);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2004-06-11 19:07:17 +00:00
|
|
|
else if (*(argP1) == "GREATER")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
result = (lhs > rhs);
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
else
|
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
result = (lhs == rhs);
|
2009-06-12 14:07:05 +00:00
|
|
|
}
|
2008-06-26 17:01:35 +00:00
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2001-12-18 14:39:26 +00:00
|
|
|
|
2004-06-11 19:07:17 +00:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 14:07:05 +00:00
|
|
|
(*(argP1) == "STRLESS" ||
|
|
|
|
*(argP1) == "STREQUAL" ||
|
|
|
|
*(argP1) == "STRGREATER"))
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-06-11 19:07:17 +00:00
|
|
|
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
|
2004-06-14 16:02:12 +00:00
|
|
|
int val = strcmp(def,def2);
|
2008-06-26 17:01:35 +00:00
|
|
|
bool result;
|
2004-06-11 19:07:17 +00:00
|
|
|
if (*(argP1) == "STRLESS")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2004-06-14 16:02:12 +00:00
|
|
|
result = (val < 0);
|
|
|
|
}
|
|
|
|
else if (*(argP1) == "STRGREATER")
|
|
|
|
{
|
|
|
|
result = (val > 0);
|
|
|
|
}
|
|
|
|
else // strequal
|
|
|
|
{
|
|
|
|
result = (val == 0);
|
|
|
|
}
|
2008-06-26 17:01:35 +00:00
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2002-01-02 21:46:08 +00:00
|
|
|
|
2008-09-10 15:58:40 +00:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
|
|
|
(*(argP1) == "VERSION_LESS" || *(argP1) == "VERSION_GREATER" ||
|
|
|
|
*(argP1) == "VERSION_EQUAL"))
|
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
|
|
|
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
|
2013-06-11 07:56:02 +00:00
|
|
|
cmSystemTools::CompareOp op = cmSystemTools::OP_EQUAL;
|
2008-09-10 15:58:40 +00:00
|
|
|
if(*argP1 == "VERSION_LESS")
|
|
|
|
{
|
2013-06-11 07:56:02 +00:00
|
|
|
op = cmSystemTools::OP_LESS;
|
2008-09-10 15:58:40 +00:00
|
|
|
}
|
|
|
|
else if(*argP1 == "VERSION_GREATER")
|
|
|
|
{
|
2013-06-11 07:56:02 +00:00
|
|
|
op = cmSystemTools::OP_GREATER;
|
2008-09-10 15:58:40 +00:00
|
|
|
}
|
2013-06-11 07:56:02 +00:00
|
|
|
bool result = cmSystemTools::VersionCompare(op, def, def2);
|
2008-09-10 15:58:40 +00:00
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
|
|
|
|
2006-10-23 17:37:24 +00:00
|
|
|
// is file A newer than file B
|
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
|
|
|
*(argP1) == "IS_NEWER_THAN")
|
|
|
|
{
|
|
|
|
int fileIsNewer=0;
|
|
|
|
bool success=cmSystemTools::FileTimeCompare(arg->c_str(),
|
|
|
|
(argP2)->c_str(),
|
|
|
|
&fileIsNewer);
|
2008-06-26 17:01:35 +00:00
|
|
|
HandleBinaryOp(
|
|
|
|
(success==false || fileIsNewer==1 || fileIsNewer==0),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2006-10-23 17:37:24 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 14:08:14 +00:00
|
|
|
++arg;
|
2002-11-08 20:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
while (reducible);
|
2008-06-26 17:01:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-11-08 20:46:08 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// level 3 handles NOT
|
|
|
|
bool HandleLevel3(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
int reducible;
|
2004-05-01 14:08:14 +00:00
|
|
|
do
|
2001-08-06 21:01:26 +00:00
|
|
|
{
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 0;
|
2004-06-11 19:07:17 +00:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 17:01:35 +00:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 14:08:14 +00:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 15:16:20 +00:00
|
|
|
{
|
2004-06-11 19:07:17 +00:00
|
|
|
argP1 = arg;
|
2005-11-17 14:32:07 +00:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-06-11 19:07:17 +00:00
|
|
|
if (argP1 != newArgs.end() && *arg == "NOT")
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2009-06-12 14:07:05 +00:00
|
|
|
bool rhs = GetBooleanValueWithAutoDereference(*argP1, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
|
|
|
++arg;
|
2001-05-01 15:16:20 +00:00
|
|
|
}
|
2001-04-19 21:39:03 +00:00
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
while (reducible);
|
2008-06-26 17:01:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-04 12:50:37 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
|
|
|
// level 4 handles AND OR
|
|
|
|
bool HandleLevel4(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
int reducible;
|
2009-06-12 14:07:05 +00:00
|
|
|
bool lhs;
|
|
|
|
bool rhs;
|
2004-05-01 14:08:14 +00:00
|
|
|
do
|
2001-04-19 21:39:03 +00:00
|
|
|
{
|
2004-05-01 14:08:14 +00:00
|
|
|
reducible = 0;
|
2004-06-11 19:07:17 +00:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 17:01:35 +00:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 14:08:14 +00:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 15:16:20 +00:00
|
|
|
{
|
2004-06-11 19:07:17 +00:00
|
|
|
argP1 = arg;
|
2005-11-17 14:32:07 +00:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2009-06-12 14:07:05 +00:00
|
|
|
if (argP1 != newArgs.end() && *(argP1) == "AND" &&
|
2004-08-04 12:50:37 +00:00
|
|
|
argP2 != newArgs.end())
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2009-06-12 14:07:05 +00:00
|
|
|
lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandleBinaryOp((lhs && rhs),
|
2008-06-26 17:01:35 +00:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
2001-08-06 21:01:26 +00:00
|
|
|
|
2009-06-12 14:07:05 +00:00
|
|
|
if (argP1 != newArgs.end() && *(argP1) == "OR" &&
|
2004-08-04 12:50:37 +00:00
|
|
|
argP2 != newArgs.end())
|
2004-05-01 14:08:14 +00:00
|
|
|
{
|
2009-06-12 14:07:05 +00:00
|
|
|
lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandleBinaryOp((lhs || rhs),
|
2008-06-26 17:01:35 +00:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 14:08:14 +00:00
|
|
|
}
|
|
|
|
++arg;
|
2002-05-23 14:32:28 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 14:08:14 +00:00
|
|
|
while (reducible);
|
2008-06-26 17:01:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// order of operations,
|
2009-06-12 14:07:05 +00:00
|
|
|
// 1. ( ) -- parenthetical groups
|
|
|
|
// 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
|
|
|
|
// 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
|
2008-06-26 17:01:35 +00:00
|
|
|
// 4. NOT
|
|
|
|
// 5. AND OR
|
|
|
|
//
|
|
|
|
// There is an issue on whether the arguments should be values of references,
|
|
|
|
// for example IF (FOO AND BAR) should that compare the strings FOO and BAR
|
|
|
|
// or should it really do IF (${FOO} AND ${BAR}) Currently IS_DIRECTORY
|
|
|
|
// EXISTS COMMAND and DEFINED all take values. EQUAL, LESS and GREATER can
|
|
|
|
// take numeric values or variable names. STRLESS and STRGREATER take
|
|
|
|
// variable names but if the variable name is not found it will use the name
|
|
|
|
// directly. AND OR take variables or the values 0 or 1.
|
|
|
|
|
|
|
|
|
|
|
|
bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
|
2009-06-12 14:07:05 +00:00
|
|
|
std::string &errorString, cmMakefile *makefile,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
2008-06-28 15:16:36 +00:00
|
|
|
errorString = "";
|
2008-06-26 17:01:35 +00:00
|
|
|
|
|
|
|
// handle empty invocation
|
|
|
|
if (args.size() < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// store the reduced args in this vector
|
|
|
|
std::list<std::string> newArgs;
|
|
|
|
|
|
|
|
// copy to the list structure
|
|
|
|
for(unsigned int i = 0; i < args.size(); ++i)
|
2009-06-12 14:07:05 +00:00
|
|
|
{
|
2008-06-26 17:01:35 +00:00
|
|
|
newArgs.push_back(args[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now loop through the arguments and see if we can reduce any of them
|
|
|
|
// we do this multiple times. Once for each level of precedence
|
2009-06-12 14:07:05 +00:00
|
|
|
// parens
|
|
|
|
if (!HandleLevel0(newArgs, makefile, errorString, status))
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
//predicates
|
|
|
|
if (!HandleLevel1(newArgs, makefile, errorString, status))
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
// binary ops
|
|
|
|
if (!HandleLevel2(newArgs, makefile, errorString, status))
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
|
|
|
// used to store the value of policy CMP0012 for performance
|
|
|
|
cmPolicies::PolicyStatus Policy12Status =
|
|
|
|
makefile->GetPolicyStatus(cmPolicies::CMP0012);
|
|
|
|
|
|
|
|
// NOT
|
|
|
|
if (!HandleLevel3(newArgs, makefile, errorString,
|
|
|
|
Policy12Status, status))
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
// AND OR
|
|
|
|
if (!HandleLevel4(newArgs, makefile, errorString,
|
|
|
|
Policy12Status, status))
|
2008-06-26 17:01:35 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-23 14:32:28 +00:00
|
|
|
|
2004-05-01 14:08:14 +00:00
|
|
|
// now at the end there should only be one argument left
|
2009-06-12 14:07:05 +00:00
|
|
|
if (newArgs.size() != 1)
|
2008-06-28 15:16:36 +00:00
|
|
|
{
|
|
|
|
errorString = "Unknown arguments specified";
|
2012-01-20 17:27:26 +00:00
|
|
|
status = cmake::FATAL_ERROR;
|
2008-06-28 15:16:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 14:07:05 +00:00
|
|
|
|
|
|
|
return GetBooleanValueWithAutoDereference(*(newArgs.begin()),
|
|
|
|
makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
2009-10-27 13:07:39 +00:00
|
|
|
status, true);
|
2001-04-19 21:39:03 +00:00
|
|
|
}
|
2002-10-02 21:22:56 +00:00
|
|
|
|
2008-06-26 17:01:35 +00:00
|
|
|
//=========================================================================
|
2002-10-02 21:22:56 +00:00
|
|
|
const char* cmIfCommand::GetVariableOrString(const char* str,
|
|
|
|
const cmMakefile* mf)
|
|
|
|
{
|
|
|
|
const char* def = mf->GetDefinition(str);
|
|
|
|
if(!def)
|
|
|
|
{
|
|
|
|
def = str;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|