View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014770CMakeCMakepublic2014-02-24 12:292014-10-06 10:32
ReporterAurélien Gâteau 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product VersionCMake 2.8.12.2 
Target VersionFixed in Version 
Summary0014770: if (4.96.0) evaluates to FALSE
Description`if (4.96)` evaluates to TRUE, but `if (4.96.0)` evaluates to FALSE. This is unexpected.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0035175)
Brad King (manager)
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 (reporter)
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 (manager)
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 (manager)
2014-10-06 10:32

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-02-24 12:29 Aurélien Gâteau New Issue
2014-02-24 12:44 Brad King Note Added: 0035175
2014-02-24 12:44 Brad King Status new => resolved
2014-02-24 12:44 Brad King Resolution open => won't fix
2014-02-24 13:44 Aurélien Gâteau Note Added: 0035176
2014-02-24 13:44 Aurélien Gâteau Status resolved => feedback
2014-02-24 13:44 Aurélien Gâteau Resolution won't fix => reopened
2014-02-24 14:00 Brad King Note Added: 0035177
2014-02-24 14:01 Brad King Status feedback => resolved
2014-02-24 14:01 Brad King Resolution reopened => won't fix
2014-10-06 10:32 Robert Maynard Note Added: 0036913
2014-10-06 10:32 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team