MantisBT - CMake
View Issue Details
0014770CMakeCMakepublic2014-02-24 12:292014-10-06 10:32
Aurélien Gâteau 
 
normalmajoralways
closedwon't fix 
CMake 2.8.12.2 
 
0014770: if (4.96.0) evaluates to FALSE
`if (4.96)` evaluates to TRUE, but `if (4.96.0)` evaluates to FALSE. This is unexpected.
No tags attached.
Issue History
2014-02-24 12:29Aurélien GâteauNew Issue
2014-02-24 12:44Brad KingNote Added: 0035175
2014-02-24 12:44Brad KingStatusnew => resolved
2014-02-24 12:44Brad KingResolutionopen => won't fix
2014-02-24 13:44Aurélien GâteauNote Added: 0035176
2014-02-24 13:44Aurélien GâteauStatusresolved => feedback
2014-02-24 13:44Aurélien GâteauResolutionwon't fix => reopened
2014-02-24 14:00Brad KingNote Added: 0035177
2014-02-24 14:01Brad KingStatusfeedback => resolved
2014-02-24 14:01Brad KingResolutionreopened => won't fix
2014-10-06 10:32Robert MaynardNote Added: 0036913
2014-10-06 10:32Robert MaynardStatusresolved => closed

Notes
(0035175)
Brad King   
2014-02-24 12:44   
This is as documented:

 http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:if [^]

The 4.96 value is a non-zero number so it is true under the if(<constant>) case. The 4.96.0 value is not a number so it falls through to the if(<variable>) case and no variable named "4.96.0" is defined.

One can do

 set(version 4.96.0)
 if(version)
   ...
 endif()

or use the VERSION_LESS, VERSION_EQUAL, or VERSION_GREATER comparison operator.
(0035176)
Aurélien Gâteau   
2014-02-24 13:44   
Actually the issue is a bit more complex. It appeared in a macro. The following code:

"""
cmake_minimum_required(VERSION 2.8)

macro(foo dep)
    if (${ARGV1})
        message("ARGV1(${ARGV1}) is TRUE")
    else()
        message("ARGV1(${ARGV1}) is FALSE")
    endif()
endmacro()

foo(me)
foo(me 4.96)
foo(me 4.96.0)
"""

Yields:

"""
ARGV1() is FALSE
ARGV1(4.96) is TRUE
ARGV1(4.96.0) is FALSE
"""

I expected the last line to be TRUE.
(0035177)
Brad King   
2014-02-24 14:00   
Macro replacements are performed before the code is executed so my explanation stands as it does for literal code.

You can do:

macro(foo dep)
    set(argv1 "${ARGV1}")
    if (argv1)
        message("ARGV1(${argv1}) is TRUE")
    else()
        message("ARGV1(${argv1}) is FALSE")
    endif()
endmacro()

Please post on the mailing list:

 http://www.cmake.org/cgi-bin/mailman/listinfo/cmake [^]

if you need further help. That has a much broader audience.
(0036913)
Robert Maynard   
2014-10-06 10:32   
Closing resolved issues that have not been updated in more than 4 months.