1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMathCommand.cxx,v $
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmMathCommand.h"
19 #include "cmExprParserHelper.h"
21 //----------------------------------------------------------------------------
23 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
25 if ( args
.size() < 1 )
27 this->SetError("must be called with at least one argument.");
30 const std::string
&subCommand
= args
[0];
31 if(subCommand
== "EXPR")
33 return this->HandleExprCommand(args
);
35 std::string e
= "does not recognize sub-command "+subCommand
;
36 this->SetError(e
.c_str());
40 //----------------------------------------------------------------------------
41 bool cmMathCommand::HandleExprCommand(std::vector
<std::string
> const& args
)
43 if ( args
.size() != 3 )
45 this->SetError("EXPR called with incorrect arguments.");
49 const std::string
& outputVariable
= args
[1];
50 const std::string
& expression
= args
[2];
52 cmExprParserHelper helper
;
53 if ( !helper
.ParseString(expression
.c_str(), 0) )
55 std::string e
= "cannot parse the expression: \""+expression
+"\": ";
56 e
+= helper
.GetError();
57 this->SetError(e
.c_str());
62 sprintf(buffer
, "%d", helper
.GetResult());
64 this->Makefile
->AddDefinition(outputVariable
.c_str(), buffer
);