MantisBT - CMake
View Issue Details
0008996CMakeCMakepublic2009-05-11 09:352016-06-10 14:30
Denis Scherbakov 
Bill Hoffman 
normalminoralways
closedmoved 
CMake-2-6 
CMake 2.8.12 
0008996: Bug in MATH EXPR
MATH(EXPR varOutput "-1 + 1")

gives an error:

CMake Error at CMakeLists.txt:1 (MATH):
  math cannot parse the expression: "-1 + 1": syntax error, unexpected
  exp_MINUS, expecting exp_OPENPARENT or exp_NUMBER (1)

I think "+1 + 1" also does not work.
CMake 2.6.4 on Linux
No tags attached.
has duplicate 0015181closed Robert Maynard math can't handle negative numbers. 
has duplicate 0015707closed Robert Maynard Error at: math(EXPR value "-1 + 1") 
Issue History
2009-05-11 09:35Denis ScherbakovNew Issue
2009-09-14 12:47Bill HoffmanNote Added: 0017440
2009-09-14 12:48Bill HoffmanStatusnew => assigned
2009-09-14 12:48Bill HoffmanAssigned To => Bill Hoffman
2009-10-17 10:35Greg SharpNote Added: 0018093
2012-05-01 22:12GiliNote Added: 0029384
2012-11-14 10:28David ColeTarget Version => CMake 2.8.11
2013-05-17 09:33Robert MaynardTarget VersionCMake 2.8.11 => CMake 2.8.12
2014-09-30 13:52David ColeRelationship addedhas duplicate 0015181
2015-08-22 05:42David ColeRelationship addedhas duplicate 0015707
2016-01-16 19:16Nicholas BradenNote Added: 0040249
2016-01-16 19:28Nicholas BradenNote Edited: 0040249bug_revision_view_page.php?bugnote_id=40249#r2000
2016-06-10 14:27Kitware RobotNote Added: 0041556
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0017440)
Bill Hoffman   
2009-09-14 12:47   
MATH(EXPR varOutput "0 -1 + 1")
message("${varOutput}")
(0018093)
Greg Sharp   
2009-10-17 10:35   
No floating point?

MATH (EXPR OUTPUT_VAR "1.1 + 1.1")

CMake Error at /home/gcs6/projects/plastimatch/test.cmake:1 (MATH):
  math cannot parse the expression: "1.1 + 1.1": syntax error, unexpected
  exp_NUMBER, expecting $end (4)

2.6.3 on linux
(0029384)
Gili   
2012-05-01 22:12   
Bill,

How are we supposed to increment a number?

  MATH (EXPR index "0 + ${index} + 1")

does not work because:

  math cannot parse the expression: "0 + -1 + 1"

Is there a workaround for this?
(0040249)
Nicholas Braden   
2016-01-16 19:16   
(edited on: 2016-01-16 19:28)
This still affects CMake 3.4.1

@Gili This will always work whether the number is negative or positive:

math(EXPR index "0${index} + 1")

Hopefully they never add support for C-style octal numbers...

(0041556)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.