2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-10-18 00:42:47 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-10-18 00:42:47 +04:00
|
|
|
|
2009-09-28 19:43: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.
|
|
|
|
============================================================================*/
|
2005-10-18 00:42:47 +04:00
|
|
|
#include "cmMathCommand.h"
|
|
|
|
|
|
|
|
#include "cmExprParserHelper.h"
|
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmMathCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
2005-10-18 00:42:47 +04:00
|
|
|
{
|
|
|
|
if ( args.size() < 1 )
|
|
|
|
{
|
|
|
|
this->SetError("must be called with at least one argument.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const std::string &subCommand = args[0];
|
|
|
|
if(subCommand == "EXPR")
|
|
|
|
{
|
|
|
|
return this->HandleExprCommand(args);
|
|
|
|
}
|
|
|
|
std::string e = "does not recognize sub-command "+subCommand;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e);
|
2005-10-18 00:42:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
if ( args.size() != 3 )
|
|
|
|
{
|
|
|
|
this->SetError("EXPR called with incorrect arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& outputVariable = args[1];
|
|
|
|
const std::string& expression = args[2];
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-10-18 00:42:47 +04:00
|
|
|
cmExprParserHelper helper;
|
|
|
|
if ( !helper.ParseString(expression.c_str(), 0) )
|
|
|
|
{
|
|
|
|
std::string e = "cannot parse the expression: \""+expression+"\": ";
|
|
|
|
e += helper.GetError();
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e);
|
2005-10-18 00:42:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buffer[1024];
|
|
|
|
sprintf(buffer, "%d", helper.GetResult());
|
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(outputVariable, buffer);
|
2005-10-18 00:42:47 +04:00
|
|
|
return true;
|
|
|
|
}
|