2009-10-02 01:21:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-04-20 01:39:03 +04:00
|
|
|
|
2009-10-02 01:21:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-04-20 01:39:03 +04:00
|
|
|
|
2009-10-02 01:21:28 +04: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-20 01:39:03 +04:00
|
|
|
#include "cmIfCommand.h"
|
2007-08-29 19:58:38 +04:00
|
|
|
#include "cmStringCommand.h"
|
|
|
|
|
2003-05-24 18:07:58 +04:00
|
|
|
#include <stdlib.h> // required for atof
|
2004-06-11 23:07:17 +04:00
|
|
|
#include <list>
|
2003-06-23 22:10:12 +04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2009-10-28 19:17:18 +03: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 21:01:35 +04:00
|
|
|
//=========================================================================
|
2001-04-20 01:39:03 +04:00
|
|
|
bool cmIfFunctionBlocker::
|
2009-06-12 18:07:05 +04:00
|
|
|
IsFunctionBlocked(const cmListFileFunction& lff,
|
2008-06-26 21:01:35 +04:00
|
|
|
cmMakefile &mf,
|
2008-01-23 18:28:26 +03:00
|
|
|
cmExecutionStatus &inStatus)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
// we start by recording all the functions
|
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"if"))
|
2006-12-12 18:07:20 +03:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
this->ScopeDepth++;
|
2006-12-12 18:07:20 +03:00
|
|
|
}
|
2008-01-23 18:28:26 +03:00
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
this->ScopeDepth--;
|
|
|
|
// if this is the endif for this if statement, then start executing
|
2009-06-12 18:07:05 +04:00
|
|
|
if (!this->ScopeDepth)
|
2006-09-22 19:23:51 +04:00
|
|
|
{
|
2009-01-20 22:36:18 +03:00
|
|
|
// Remove the function blocker for this scope or bail.
|
2009-01-21 17:49:00 +03:00
|
|
|
cmsys::auto_ptr<cmFunctionBlocker>
|
|
|
|
fb(mf.RemoveFunctionBlocker(this, lff));
|
2009-01-20 22:36:18 +03:00
|
|
|
if(!fb.get()) { return false; }
|
|
|
|
|
2008-01-23 18:28:26 +03: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 20:00:49 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03: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;
|
|
|
|
}
|
|
|
|
else if (scopeDepth == 0 && !cmSystemTools::Strucmp
|
|
|
|
(this->Functions[c].Name.c_str(),"elseif"))
|
2006-09-22 19:23:51 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
if (this->HasRun)
|
2006-09-22 19:23:51 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
this->IsBlocking = true;
|
2006-09-22 19:23:51 +04:00
|
|
|
}
|
2008-01-23 18:28:26 +03:00
|
|
|
else
|
|
|
|
{
|
2009-01-20 22:35:22 +03:00
|
|
|
// Place this call on the call stack.
|
|
|
|
cmMakefileCall stack_manager(&mf, this->Functions[c], status);
|
|
|
|
static_cast<void>(stack_manager);
|
|
|
|
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string errorString;
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
std::vector<std::string> expandedArguments;
|
2009-06-12 18:07:05 +04:00
|
|
|
mf.ExpandArguments(this->Functions[c].Arguments,
|
2008-01-23 18:28:26 +03:00
|
|
|
expandedArguments);
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2009-06-12 19:10:26 +04:00
|
|
|
cmake::MessageType messType;
|
2009-06-12 18:07:05 +04:00
|
|
|
bool isTrue =
|
|
|
|
cmIfCommand::IsTrue(expandedArguments, errorString,
|
2009-06-12 19:10:26 +04:00
|
|
|
&mf, messType);
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-06-28 19:16:36 +04:00
|
|
|
if (errorString.size())
|
2008-01-23 18:28:26 +03:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
std::string err = cmIfCommandError(&mf, expandedArguments);
|
2008-01-23 18:28:26 +03:00
|
|
|
err += errorString;
|
2009-06-12 19:10:26 +04:00
|
|
|
mf.IssueMessage(messType, err);
|
|
|
|
if (messType == cmake::FATAL_ERROR)
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-23 18:28:26 +03:00
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
if (isTrue)
|
|
|
|
{
|
|
|
|
this->IsBlocking = false;
|
|
|
|
this->HasRun = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
// should we execute?
|
|
|
|
else if (!this->IsBlocking)
|
2006-09-22 19:23:51 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03: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 19:23:51 +04:00
|
|
|
}
|
2002-08-09 20:00:49 +04:00
|
|
|
}
|
2006-09-22 19:23:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
// record the command
|
|
|
|
this->Functions.push_back(lff);
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
// always return true
|
|
|
|
return true;
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2002-12-12 02:13:33 +03:00
|
|
|
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
2008-03-01 05:33:33 +03:00
|
|
|
cmMakefile&)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2006-05-31 19:19:39 +04:00
|
|
|
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endif"))
|
2002-07-10 19:38:38 +04:00
|
|
|
{
|
2008-02-29 20:18:11 +03: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 19:38:38 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 21:50:01 +04:00
|
|
|
|
2002-07-10 19:38:38 +04:00
|
|
|
return false;
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2006-05-11 23:50:11 +04:00
|
|
|
bool cmIfCommand
|
2009-06-12 18:07:05 +04:00
|
|
|
::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
|
2008-01-23 18:28:26 +03:00
|
|
|
cmExecutionStatus &)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string errorString;
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2002-12-12 02:13:33 +03:00
|
|
|
std::vector<std::string> expandedArguments;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->ExpandArguments(args, expandedArguments);
|
2009-06-12 18:07:05 +04:00
|
|
|
|
|
|
|
cmake::MessageType status;
|
|
|
|
bool isTrue =
|
|
|
|
cmIfCommand::IsTrue(expandedArguments,errorString,
|
|
|
|
this->Makefile, status);
|
|
|
|
|
2008-06-28 19:16:36 +04:00
|
|
|
if (errorString.size())
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
std::string err = cmIfCommandError(this->Makefile, expandedArguments);
|
2004-08-03 16:13:54 +04:00
|
|
|
err += errorString;
|
2009-06-12 18:07:05 +04:00
|
|
|
if (status == cmake::FATAL_ERROR)
|
|
|
|
{
|
|
|
|
this->SetError(err.c_str());
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Makefile->IssueMessage(status, err);
|
|
|
|
}
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2002-07-10 19:38:38 +04:00
|
|
|
cmIfFunctionBlocker *f = new cmIfFunctionBlocker();
|
|
|
|
// if is isn't true block the commands
|
2008-01-23 18:28:26 +03:00
|
|
|
f->ScopeDepth = 1;
|
2006-03-15 19:02:08 +03:00
|
|
|
f->IsBlocking = !isTrue;
|
2006-09-22 19:23:51 +04:00
|
|
|
if (isTrue)
|
|
|
|
{
|
|
|
|
f->HasRun = true;
|
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
f->Args = args;
|
|
|
|
this->Makefile->AddFunctionBlocker(f);
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2002-07-01 16:49:36 +04:00
|
|
|
return true;
|
|
|
|
}
|
2001-08-07 01:01:26 +04:00
|
|
|
|
2009-06-12 18:07:05 +04:00
|
|
|
namespace
|
2005-11-17 17:32:07 +03:00
|
|
|
{
|
2009-06-12 18:07:05 +04:00
|
|
|
//=========================================================================
|
2009-10-28 19:17:18 +03:00
|
|
|
bool GetBooleanValue(std::string& arg, cmMakefile* mf)
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
// Check basic constants.
|
|
|
|
if (arg == "0")
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
return false;
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2009-10-28 19:17:18 +03:00
|
|
|
if (arg == "1")
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
return true;
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
|
|
|
|
2009-10-28 19:17:18 +03:00
|
|
|
// Check named constants.
|
|
|
|
if (cmSystemTools::IsOn(arg.c_str()))
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (cmSystemTools::IsOff(arg.c_str()))
|
|
|
|
{
|
|
|
|
return false;
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
|
|
|
|
2009-10-28 19:17:18 +03:00
|
|
|
// Check for numbers.
|
|
|
|
if(!arg.empty())
|
|
|
|
{
|
|
|
|
char* end;
|
|
|
|
double d = strtod(arg.c_str(), &end);
|
|
|
|
if(*end == '\0')
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
// The whole string is a number. Use C conversion to bool.
|
|
|
|
return d? true:false;
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2009-10-28 19:17:18 +03: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 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
def = arg.c_str();
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2009-10-28 19:17:18 +03:00
|
|
|
return !cmSystemTools::IsOff(def);
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// returns the resulting boolean value
|
|
|
|
bool GetBooleanValueWithAutoDereference(
|
|
|
|
std::string &newArg,
|
|
|
|
cmMakefile *makefile,
|
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
2009-10-28 19:17:18 +03:00
|
|
|
cmake::MessageType &status,
|
|
|
|
bool oneArg = false)
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
// Use the policy if it is set.
|
|
|
|
if (Policy12Status == cmPolicies::NEW)
|
2009-06-12 18:07:05 +04:00
|
|
|
{
|
2009-10-28 19:17:18 +03:00
|
|
|
return GetBooleanValue(newArg, makefile);
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2009-10-28 19:17:18 +03: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 18:07:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
2005-11-17 17:44:32 +03:00
|
|
|
void IncrementArguments(std::list<std::string> &newArgs,
|
|
|
|
std::list<std::string>::iterator &argP1,
|
|
|
|
std::list<std::string>::iterator &argP2)
|
|
|
|
{
|
2005-11-17 17:32:07 +03:00
|
|
|
if (argP1 != newArgs.end())
|
|
|
|
{
|
2005-11-17 17:44:32 +03:00
|
|
|
argP1++;
|
|
|
|
argP2 = argP1;
|
|
|
|
if (argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
argP2++;
|
|
|
|
}
|
2005-11-17 17:32:07 +03:00
|
|
|
}
|
2005-11-17 17:44:32 +03:00
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
|
2008-06-26 21:01:35 +04: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 18:07:05 +04:00
|
|
|
else
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
|
|
|
reducible = 1;
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
|
2008-06-26 21:01:35 +04: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 18:07:05 +04:00
|
|
|
else
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
|
|
|
reducible = 1;
|
|
|
|
}
|
2004-05-06 17:47:25 +04:00
|
|
|
|
2008-09-10 19:58:40 +04:00
|
|
|
//=========================================================================
|
|
|
|
enum Op { OpLess, OpEqual, OpGreater };
|
|
|
|
bool HandleVersionCompare(Op op, const char* lhs_str, const char* rhs_str)
|
|
|
|
{
|
|
|
|
// Parse out up to 4 components.
|
|
|
|
unsigned int lhs[4] = {0,0,0,0};
|
|
|
|
unsigned int rhs[4] = {0,0,0,0};
|
|
|
|
sscanf(lhs_str, "%u.%u.%u.%u", &lhs[0], &lhs[1], &lhs[2], &lhs[3]);
|
|
|
|
sscanf(rhs_str, "%u.%u.%u.%u", &rhs[0], &rhs[1], &rhs[2], &rhs[3]);
|
|
|
|
|
|
|
|
// Do component-wise comparison.
|
|
|
|
for(unsigned int i=0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
if(lhs[i] < rhs[i])
|
|
|
|
{
|
|
|
|
// lhs < rhs, so true if operation is LESS
|
|
|
|
return op == OpLess;
|
|
|
|
}
|
|
|
|
else if(lhs[i] > rhs[i])
|
|
|
|
{
|
|
|
|
// lhs > rhs, so true if operation is GREATER
|
|
|
|
return op == OpGreater;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// lhs == rhs, so true if operation is EQUAL
|
|
|
|
return op == OpEqual;
|
|
|
|
}
|
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level 0 processes parenthetical expressions
|
|
|
|
bool HandleLevel0(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 18:07:05 +04:00
|
|
|
std::string &errorString,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
2004-05-04 17:16:06 +04:00
|
|
|
int reducible;
|
2004-05-01 18:08:14 +04:00
|
|
|
do
|
2001-08-07 01:01:26 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 0;
|
2004-06-11 23:07:17 +04:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2004-05-01 18:08:14 +04:00
|
|
|
while (arg != newArgs.end())
|
2001-08-07 01:01:26 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
if (*arg == "(")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04: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 19:16:36 +04:00
|
|
|
errorString = "mismatched parenthesis in condition";
|
2009-06-12 18:07:05 +04:00
|
|
|
status = cmake::FATAL_ERROR;
|
2008-06-26 21:01:35 +04: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 18:07:05 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
newArgs2.push_back(*argP1);
|
|
|
|
}
|
|
|
|
newArgs2.pop_back();
|
2008-10-01 17:04:27 +04:00
|
|
|
// now recursively invoke IsTrue to handle the values inside the
|
|
|
|
// parenthetical expression
|
2009-06-12 18:07:05 +04:00
|
|
|
bool value =
|
|
|
|
cmIfCommand::IsTrue(newArgs2, errorString, makefile, status);
|
2008-06-26 21:01:35 +04:00
|
|
|
if(value)
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
*arg = "1";
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
else
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2006-03-22 22:06:52 +03:00
|
|
|
*arg = "0";
|
|
|
|
}
|
|
|
|
argP1 = arg;
|
2008-06-26 21:01:35 +04:00
|
|
|
argP1++;
|
|
|
|
// remove the now evaluated parenthetical expression
|
2009-06-12 18:07:05 +04:00
|
|
|
newArgs.erase(argP1,argClose);
|
2008-06-26 21:01:35 +04:00
|
|
|
}
|
|
|
|
++arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (reducible);
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level one handles most predicates except for NOT
|
|
|
|
bool HandleLevel1(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 18:07:05 +04:00
|
|
|
std::string &, cmake::MessageType &)
|
2008-06-26 21:01:35 +04: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 22:06:52 +03:00
|
|
|
}
|
2006-08-26 00:31:07 +04:00
|
|
|
// does a directory with this name exist
|
2006-03-22 22:06:52 +03:00
|
|
|
if (*arg == "IS_DIRECTORY" && argP1 != newArgs.end())
|
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileIsDirectory((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2007-06-06 16:49:18 +04:00
|
|
|
// is the given path an absolute path ?
|
|
|
|
if (*arg == "IS_ABSOLUTE" && argP1 != newArgs.end())
|
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(
|
|
|
|
cmSystemTools::FileIsFullPath((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2007-06-06 16:49:18 +04:00
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
// does a command exist
|
2004-06-11 23:07:17 +04:00
|
|
|
if (*arg == "COMMAND" && argP1 != newArgs.end())
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(
|
|
|
|
makefile->CommandExists((argP1)->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2008-03-21 01:25:59 +03:00
|
|
|
// does a policy exist
|
|
|
|
if (*arg == "POLICY" && argP1 != newArgs.end())
|
|
|
|
{
|
|
|
|
cmPolicies::PolicyID pid;
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(
|
|
|
|
makefile->GetPolicies()->GetPolicyID((argP1)->c_str(), pid),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2008-03-21 01:25:59 +03:00
|
|
|
}
|
2008-08-20 19:45:16 +04: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 18:08:14 +04:00
|
|
|
// is a variable defined
|
2004-06-11 23:07:17 +04:00
|
|
|
if (*arg == "DEFINED" && argP1 != newArgs.end())
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2006-03-30 22:49:56 +04:00
|
|
|
size_t argP1len = argP1->size();
|
2007-05-18 01:40:59 +04:00
|
|
|
bool bdef = false;
|
2006-02-10 22:41:31 +03:00
|
|
|
if(argP1len > 4 && argP1->substr(0, 4) == "ENV{" &&
|
|
|
|
argP1->operator[](argP1len-1) == '}')
|
|
|
|
{
|
|
|
|
std::string env = argP1->substr(4, argP1len-5);
|
2007-05-18 01:40:59 +04:00
|
|
|
bdef = cmSystemTools::GetEnv(env.c_str())?true:false;
|
2006-02-10 22:41:31 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-05-18 01:40:59 +04:00
|
|
|
bdef = makefile->IsDefinitionSet((argP1)->c_str());
|
2006-02-10 22:41:31 +03:00
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(bdef, reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
|
|
|
++arg;
|
2001-08-07 01:01:26 +04:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
while (reducible);
|
2008-06-26 21:01:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-04 16:50:37 +04:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level two handles most binary operations except for AND OR
|
|
|
|
bool HandleLevel2(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 18:07:05 +04:00
|
|
|
std::string &errorString,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
|
|
|
const char *def;
|
|
|
|
const char *def2;
|
2004-05-01 18:08:14 +04:00
|
|
|
do
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 0;
|
2004-06-11 23:07:17 +04:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 21:01:35 +04:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 18:08:14 +04:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 19:16:20 +04:00
|
|
|
{
|
2004-06-11 23:07:17 +04:00
|
|
|
argP1 = arg;
|
2005-11-17 17:32:07 +03:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-06-11 23:07:17 +04:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 18:07:05 +04:00
|
|
|
*(argP1) == "MATCHES")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-08-03 16:13:54 +04:00
|
|
|
const char* rex = (argP2)->c_str();
|
2007-08-29 19:58:38 +04:00
|
|
|
cmStringCommand::ClearMatches(makefile);
|
2004-08-03 16:13:54 +04:00
|
|
|
cmsys::RegularExpression regEntry;
|
|
|
|
if ( !regEntry.compile(rex) )
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Regular expression \"" << rex << "\" cannot compile";
|
2008-06-28 19:16:36 +04:00
|
|
|
errorString = error.str();
|
2009-06-12 18:07:05 +04:00
|
|
|
status = cmake::FATAL_ERROR;
|
2004-08-03 16:13:54 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
if (regEntry.find(def))
|
|
|
|
{
|
2007-08-29 19:58:38 +04:00
|
|
|
cmStringCommand::StoreMatches(makefile, regEntry);
|
2007-08-29 22:35:06 +04:00
|
|
|
*arg = "1";
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*arg = "0";
|
|
|
|
}
|
2004-06-11 23:07:17 +04:00
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2005-11-17 17:32:07 +03:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 1;
|
|
|
|
}
|
2002-07-01 16:49:36 +04:00
|
|
|
|
2009-06-12 18:07:05 +04:00
|
|
|
if (argP1 != newArgs.end() && *arg == "MATCHES")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
*arg = "0";
|
2004-06-11 23:07:17 +04:00
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2005-11-17 17:32:07 +03:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 1;
|
|
|
|
}
|
2001-08-07 01:01:26 +04:00
|
|
|
|
2004-06-11 23:07:17 +04:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 18:07:05 +04:00
|
|
|
(*(argP1) == "LESS" || *(argP1) == "GREATER" ||
|
|
|
|
*(argP1) == "EQUAL"))
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-06-11 23:07:17 +04:00
|
|
|
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
|
2006-10-25 18:31:26 +04:00
|
|
|
double lhs;
|
|
|
|
double rhs;
|
2008-06-26 21:01:35 +04:00
|
|
|
bool result;
|
2006-10-25 18:57:26 +04:00
|
|
|
if(sscanf(def, "%lg", &lhs) != 1 ||
|
|
|
|
sscanf(def2, "%lg", &rhs) != 1)
|
2006-10-25 18:31:26 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
result = false;
|
2006-10-25 18:31:26 +04:00
|
|
|
}
|
2006-10-25 18:57:26 +04:00
|
|
|
else if (*(argP1) == "LESS")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
result = (lhs < rhs);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2004-06-11 23:07:17 +04:00
|
|
|
else if (*(argP1) == "GREATER")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
result = (lhs > rhs);
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
else
|
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
result = (lhs == rhs);
|
2009-06-12 18:07:05 +04:00
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2001-12-18 17:39:26 +03:00
|
|
|
|
2004-06-11 23:07:17 +04:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2009-06-12 18:07:05 +04:00
|
|
|
(*(argP1) == "STRLESS" ||
|
|
|
|
*(argP1) == "STREQUAL" ||
|
|
|
|
*(argP1) == "STRGREATER"))
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
2004-06-11 23:07:17 +04:00
|
|
|
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
|
2004-06-14 20:02:12 +04:00
|
|
|
int val = strcmp(def,def2);
|
2008-06-26 21:01:35 +04:00
|
|
|
bool result;
|
2004-06-11 23:07:17 +04:00
|
|
|
if (*(argP1) == "STRLESS")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2004-06-14 20:02:12 +04:00
|
|
|
result = (val < 0);
|
|
|
|
}
|
|
|
|
else if (*(argP1) == "STRGREATER")
|
|
|
|
{
|
|
|
|
result = (val > 0);
|
|
|
|
}
|
|
|
|
else // strequal
|
|
|
|
{
|
|
|
|
result = (val == 0);
|
|
|
|
}
|
2008-06-26 21:01:35 +04:00
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2002-01-03 00:46:08 +03:00
|
|
|
|
2008-09-10 19:58:40 +04: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);
|
|
|
|
Op op = OpEqual;
|
|
|
|
if(*argP1 == "VERSION_LESS")
|
|
|
|
{
|
|
|
|
op = OpLess;
|
|
|
|
}
|
|
|
|
else if(*argP1 == "VERSION_GREATER")
|
|
|
|
{
|
|
|
|
op = OpGreater;
|
|
|
|
}
|
|
|
|
bool result = HandleVersionCompare(op, def, def2);
|
|
|
|
HandleBinaryOp(result,
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
|
|
|
|
2006-10-23 21:37:24 +04: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 21:01:35 +04:00
|
|
|
HandleBinaryOp(
|
|
|
|
(success==false || fileIsNewer==1 || fileIsNewer==0),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2006-10-23 21:37:24 +04:00
|
|
|
}
|
|
|
|
|
2004-05-01 18:08:14 +04:00
|
|
|
++arg;
|
2002-11-08 23:46:08 +03:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
while (reducible);
|
2008-06-26 21:01:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
2002-11-08 23:46:08 +03:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level 3 handles NOT
|
|
|
|
bool HandleLevel3(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 18:07:05 +04:00
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2004-05-01 18:08:14 +04:00
|
|
|
do
|
2001-08-07 01:01:26 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 0;
|
2004-06-11 23:07:17 +04:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 21:01:35 +04:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 18:08:14 +04:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 19:16:20 +04:00
|
|
|
{
|
2004-06-11 23:07:17 +04:00
|
|
|
argP1 = arg;
|
2005-11-17 17:32:07 +03:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2004-06-11 23:07:17 +04:00
|
|
|
if (argP1 != newArgs.end() && *arg == "NOT")
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2009-06-12 18:07:05 +04:00
|
|
|
bool rhs = GetBooleanValueWithAutoDereference(*argP1, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
|
|
|
++arg;
|
2001-05-01 19:16:20 +04:00
|
|
|
}
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
while (reducible);
|
2008-06-26 21:01:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-04 16:50:37 +04:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level 4 handles AND OR
|
|
|
|
bool HandleLevel4(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2009-06-12 18:07:05 +04:00
|
|
|
std::string &errorString,
|
|
|
|
cmPolicies::PolicyStatus Policy12Status,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2009-06-12 18:07:05 +04:00
|
|
|
bool lhs;
|
|
|
|
bool rhs;
|
2004-05-01 18:08:14 +04:00
|
|
|
do
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
reducible = 0;
|
2004-06-11 23:07:17 +04:00
|
|
|
std::list<std::string>::iterator arg = newArgs.begin();
|
2008-06-26 21:01:35 +04:00
|
|
|
std::list<std::string>::iterator argP1;
|
|
|
|
std::list<std::string>::iterator argP2;
|
2004-05-01 18:08:14 +04:00
|
|
|
while (arg != newArgs.end())
|
2001-05-01 19:16:20 +04:00
|
|
|
{
|
2004-06-11 23:07:17 +04:00
|
|
|
argP1 = arg;
|
2005-11-17 17:32:07 +03:00
|
|
|
IncrementArguments(newArgs,argP1,argP2);
|
2009-06-12 18:07:05 +04:00
|
|
|
if (argP1 != newArgs.end() && *(argP1) == "AND" &&
|
2004-08-04 16:50:37 +04:00
|
|
|
argP2 != newArgs.end())
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2009-06-12 18:07:05 +04:00
|
|
|
lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandleBinaryOp((lhs && rhs),
|
2008-06-26 21:01:35 +04:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2001-08-07 01:01:26 +04:00
|
|
|
|
2009-06-12 18:07:05 +04:00
|
|
|
if (argP1 != newArgs.end() && *(argP1) == "OR" &&
|
2004-08-04 16:50:37 +04:00
|
|
|
argP2 != newArgs.end())
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
2009-06-12 18:07:05 +04:00
|
|
|
lhs = GetBooleanValueWithAutoDereference(*arg, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
rhs = GetBooleanValueWithAutoDereference(*argP2, makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
|
|
|
status);
|
|
|
|
HandleBinaryOp((lhs || rhs),
|
2008-06-26 21:01:35 +04:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
|
|
|
++arg;
|
2002-05-23 18:32:28 +04:00
|
|
|
}
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
while (reducible);
|
2008-06-26 21:01:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// order of operations,
|
2009-06-12 18:07:05 +04: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 21:01:35 +04: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 18:07:05 +04:00
|
|
|
std::string &errorString, cmMakefile *makefile,
|
|
|
|
cmake::MessageType &status)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
2008-06-28 19:16:36 +04:00
|
|
|
errorString = "";
|
2008-06-26 21:01:35 +04: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 18:07:05 +04:00
|
|
|
{
|
2008-06-26 21:01:35 +04: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 18:07:05 +04:00
|
|
|
// parens
|
|
|
|
if (!HandleLevel0(newArgs, makefile, errorString, status))
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
//predicates
|
|
|
|
if (!HandleLevel1(newArgs, makefile, errorString, status))
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
// binary ops
|
|
|
|
if (!HandleLevel2(newArgs, makefile, errorString, status))
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 18:07:05 +04: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 21:01:35 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
// AND OR
|
|
|
|
if (!HandleLevel4(newArgs, makefile, errorString,
|
|
|
|
Policy12Status, status))
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-23 18:32:28 +04:00
|
|
|
|
2004-05-01 18:08:14 +04:00
|
|
|
// now at the end there should only be one argument left
|
2009-06-12 18:07:05 +04:00
|
|
|
if (newArgs.size() != 1)
|
2008-06-28 19:16:36 +04:00
|
|
|
{
|
|
|
|
errorString = "Unknown arguments specified";
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-12 18:07:05 +04:00
|
|
|
|
|
|
|
return GetBooleanValueWithAutoDereference(*(newArgs.begin()),
|
|
|
|
makefile,
|
|
|
|
errorString,
|
|
|
|
Policy12Status,
|
2009-10-28 19:17:18 +03:00
|
|
|
status, true);
|
2001-04-20 01:39:03 +04:00
|
|
|
}
|
2002-10-03 01:22:56 +04:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2002-10-03 01:22:56 +04:00
|
|
|
const char* cmIfCommand::GetVariableOrString(const char* str,
|
|
|
|
const cmMakefile* mf)
|
|
|
|
{
|
|
|
|
const char* def = mf->GetDefinition(str);
|
|
|
|
if(!def)
|
|
|
|
{
|
|
|
|
def = str;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|