2001-04-20 01:39:03 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2001-04-20 01:39:03 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2001-04-20 01:39:03 +04:00
|
|
|
|
2002-01-21 23:30:43 +03:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices 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>
|
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2001-04-20 01:39:03 +04:00
|
|
|
bool cmIfFunctionBlocker::
|
2008-06-26 21:01:35 +04:00
|
|
|
IsFunctionBlocked(const cmListFileFunction& lff,
|
|
|
|
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
|
|
|
// Prevent recusion and don't let this blocker block its own
|
|
|
|
// commands.
|
|
|
|
if (this->Executing)
|
2002-09-23 17:41:01 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
return false;
|
2002-09-23 17:41:01 +04:00
|
|
|
}
|
2006-12-12 18:07:20 +03: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
|
|
|
|
if (!this->ScopeDepth)
|
2006-09-22 19:23:51 +04:00
|
|
|
{
|
2008-01-23 18:28:26 +03:00
|
|
|
// execute the functions for the true parts of the if statement
|
|
|
|
this->Executing = true;
|
|
|
|
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
|
|
|
|
{
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string errorString;
|
2008-01-23 18:28:26 +03:00
|
|
|
|
|
|
|
std::vector<std::string> expandedArguments;
|
|
|
|
mf.ExpandArguments(this->Functions[c].Arguments,
|
|
|
|
expandedArguments);
|
|
|
|
bool isTrue =
|
2008-06-28 19:16:36 +04:00
|
|
|
cmIfCommand::IsTrue(expandedArguments,errorString,&mf);
|
2008-01-23 18:28:26 +03:00
|
|
|
|
2008-06-28 19:16:36 +04:00
|
|
|
if (errorString.size())
|
2008-01-23 18:28:26 +03:00
|
|
|
{
|
|
|
|
std::string err = "had incorrect arguments: ";
|
|
|
|
unsigned int i;
|
|
|
|
for(i =0; i < this->Functions[c].Arguments.size(); ++i)
|
|
|
|
{
|
|
|
|
err += (this->Functions[c].Arguments[i].Quoted?"\"":"");
|
|
|
|
err += this->Functions[c].Arguments[i].Value;
|
|
|
|
err += (this->Functions[c].Arguments[i].Quoted?"\"":"");
|
|
|
|
err += " ";
|
|
|
|
}
|
|
|
|
err += "(";
|
|
|
|
err += errorString;
|
|
|
|
err += ").";
|
|
|
|
cmSystemTools::Error(err.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2006-09-22 19:23:51 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
if (isTrue)
|
|
|
|
{
|
|
|
|
this->IsBlocking = false;
|
|
|
|
this->HasRun = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
mf.RemoveFunctionBlocker(lff);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (status.GetBreakInvoked())
|
|
|
|
{
|
|
|
|
inStatus.SetBreakInvoked(true);
|
|
|
|
mf.RemoveFunctionBlocker(lff);
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-22 19:23:51 +04:00
|
|
|
}
|
2002-08-09 20:00:49 +04:00
|
|
|
}
|
2008-01-23 18:28:26 +03:00
|
|
|
mf.RemoveFunctionBlocker(lff);
|
2006-09-22 19:23:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
// record the command
|
|
|
|
this->Functions.push_back(lff);
|
|
|
|
|
|
|
|
// 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
|
|
|
//=========================================================================
|
|
|
|
void cmIfFunctionBlocker::ScopeEnded(cmMakefile &mf)
|
2001-05-04 16:46:05 +04:00
|
|
|
{
|
2006-05-11 23:50:11 +04:00
|
|
|
std::string errmsg = "The end of a CMakeLists file was reached with an "
|
|
|
|
"IF statement that was not closed properly.\nWithin the directory: ";
|
2001-11-26 19:31:50 +03:00
|
|
|
errmsg += mf.GetCurrentDirectory();
|
|
|
|
errmsg += "\nThe arguments are: ";
|
2006-03-15 19:02:08 +03:00
|
|
|
for(std::vector<cmListFileArgument>::const_iterator j = this->Args.begin();
|
|
|
|
j != this->Args.end(); ++j)
|
2001-11-26 19:31:50 +03:00
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
errmsg += (j->Quoted?"\"":"");
|
|
|
|
errmsg += j->Value;
|
|
|
|
errmsg += (j->Quoted?"\"":"");
|
2001-11-26 19:31:50 +03:00
|
|
|
errmsg += " ";
|
|
|
|
}
|
2002-12-13 17:52:05 +03:00
|
|
|
cmSystemTools::Message(errmsg.c_str(), "Warning");
|
2001-05-04 16:46:05 +04:00
|
|
|
}
|
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2006-05-11 23:50:11 +04:00
|
|
|
bool cmIfCommand
|
2008-01-23 18:28:26 +03:00
|
|
|
::InvokeInitialPass(const std::vector<cmListFileArgument>& args,
|
|
|
|
cmExecutionStatus &)
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string errorString;
|
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);
|
2006-05-11 23:50:11 +04:00
|
|
|
bool isTrue =
|
2008-06-28 19:16:36 +04:00
|
|
|
cmIfCommand::IsTrue(expandedArguments,errorString,this->Makefile);
|
2002-07-01 16:49:36 +04:00
|
|
|
|
2008-06-28 19:16:36 +04:00
|
|
|
if (errorString.size())
|
2001-04-20 01:39:03 +04:00
|
|
|
{
|
2004-08-03 16:13:54 +04:00
|
|
|
std::string err = "had incorrect arguments: ";
|
2002-11-15 20:54:04 +03:00
|
|
|
unsigned int i;
|
|
|
|
for(i =0; i < args.size(); ++i)
|
2002-11-08 23:46:08 +03:00
|
|
|
{
|
2002-12-12 02:13:33 +03:00
|
|
|
err += (args[i].Quoted?"\"":"");
|
|
|
|
err += args[i].Value;
|
|
|
|
err += (args[i].Quoted?"\"":"");
|
2002-11-08 23:46:08 +03:00
|
|
|
err += " ";
|
|
|
|
}
|
2004-08-03 16:13:54 +04:00
|
|
|
err += "(";
|
|
|
|
err += errorString;
|
|
|
|
err += ").";
|
2002-11-08 23:46:08 +03:00
|
|
|
this->SetError(err.c_str());
|
2001-04-20 01:39:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
2002-07-01 16:49:36 +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);
|
2002-07-01 16:49:36 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2001-08-07 01:01:26 +04:00
|
|
|
|
2005-11-17 17:44:32 +03:00
|
|
|
namespace
|
2005-11-17 17:32:07 +03:00
|
|
|
{
|
2008-06-26 21:01:35 +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";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*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";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*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-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
|
|
|
// level 0 processes parenthetical expressions
|
|
|
|
bool HandleLevel0(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &errorString)
|
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";
|
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++)
|
|
|
|
{
|
|
|
|
newArgs2.push_back(*argP1);
|
|
|
|
}
|
|
|
|
newArgs2.pop_back();
|
|
|
|
// now recursively invoke IsTrue to handle the values inside the parenthetical expression
|
|
|
|
bool value =
|
|
|
|
cmIfCommand::IsTrue(newArgs2, errorString, makefile);
|
|
|
|
if(value)
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
*arg = "1";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
|
newArgs.erase(argP1,argClose);
|
|
|
|
}
|
|
|
|
++arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (reducible);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level one handles most predicates except for NOT
|
|
|
|
bool HandleLevel1(std::list<std::string> &newArgs,
|
|
|
|
cmMakefile *makefile,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &)
|
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,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &errorString)
|
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() &&
|
2004-08-04 16:50:37 +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();
|
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
|
|
|
|
2004-06-11 23:07:17 +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() &&
|
2004-08-04 16:50:37 +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);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-26 21:01:35 +04:00
|
|
|
result = (lhs == rhs);
|
2004-05-01 18:08:14 +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() &&
|
2004-08-04 16:50:37 +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
|
|
|
|
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,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
|
|
|
const char *def;
|
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
|
|
|
{
|
2004-06-11 23:07:17 +04:00
|
|
|
def = cmIfCommand::GetVariableOrNumber((argP1)->c_str(), makefile);
|
2008-06-26 21:01:35 +04:00
|
|
|
HandlePredicate(cmSystemTools::IsOff(def),
|
|
|
|
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,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &)
|
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() && *(argP1) == "AND" &&
|
2004-08-04 16:50:37 +04:00
|
|
|
argP2 != newArgs.end())
|
2004-05-01 18:08:14 +04:00
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
|
2004-06-11 23:07:17 +04:00
|
|
|
def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
|
2008-06-26 21:01:35 +04:00
|
|
|
HandleBinaryOp(
|
|
|
|
!(cmSystemTools::IsOff(def) || cmSystemTools::IsOff(def2)),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2004-05-01 18:08:14 +04:00
|
|
|
}
|
2001-08-07 01:01:26 +04:00
|
|
|
|
2004-06-11 23:07:17 +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
|
|
|
{
|
|
|
|
def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
|
2004-06-11 23:07:17 +04:00
|
|
|
def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
|
2008-06-26 21:01:35 +04:00
|
|
|
HandleBinaryOp(
|
|
|
|
!(cmSystemTools::IsOff(def) && cmSystemTools::IsOff(def2)),
|
|
|
|
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,
|
|
|
|
// 1. ( ) -- parenthetical groups
|
|
|
|
// 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
|
|
|
|
// 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
|
|
|
|
// 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,
|
2008-06-28 19:16:36 +04:00
|
|
|
std::string &errorString, cmMakefile *makefile)
|
2008-06-26 21:01:35 +04:00
|
|
|
{
|
|
|
|
const char *def;
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if (!HandleLevel0(newArgs, makefile, errorString)) // parens
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!HandleLevel1(newArgs, makefile, errorString)) //predicates
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!HandleLevel2(newArgs, makefile, errorString)) // binary ops
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!HandleLevel3(newArgs, makefile, errorString)) // NOT
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!HandleLevel4(newArgs, makefile, errorString)) // AND OR
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if (newArgs.size() == 1)
|
2002-05-23 18:32:28 +04:00
|
|
|
{
|
2004-06-11 23:07:17 +04:00
|
|
|
if (*newArgs.begin() == "0")
|
2004-04-28 17:51:06 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
return false;
|
2004-04-28 17:51:06 +04:00
|
|
|
}
|
2004-06-11 23:07:17 +04:00
|
|
|
if (*newArgs.begin() == "1")
|
2002-05-23 18:32:28 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
return true;
|
2002-05-23 18:32:28 +04:00
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
def = makefile->GetDefinition(args[0].c_str());
|
|
|
|
if(cmSystemTools::IsOff(def))
|
2002-05-23 18:32:28 +04:00
|
|
|
{
|
2004-05-01 18:08:14 +04:00
|
|
|
return false;
|
2002-05-23 18:32:28 +04:00
|
|
|
}
|
|
|
|
}
|
2008-06-28 19:16:36 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
errorString = "Unknown arguments specified";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-05-01 18:08:14 +04:00
|
|
|
return 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;
|
|
|
|
}
|
2004-05-01 18:08:14 +04:00
|
|
|
|
2008-06-26 21:01:35 +04:00
|
|
|
//=========================================================================
|
2004-05-01 18:08:14 +04:00
|
|
|
const char* cmIfCommand::GetVariableOrNumber(const char* str,
|
|
|
|
const cmMakefile* mf)
|
|
|
|
{
|
|
|
|
const char* def = mf->GetDefinition(str);
|
|
|
|
if(!def)
|
|
|
|
{
|
|
|
|
if (atoi(str))
|
|
|
|
{
|
|
|
|
def = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|