MantisBT - CMake
View Issue Details
0008222CMakeCMakepublic2008-12-04 02:012011-04-04 12:00
Philip Lowman 
David Cole 
normalfeatureN/A
closedwon't fix 
CMake-2-6 
CMake 2.8.4 
0008222: [PATCH] Support for >= and <= operators in IF() conditional
The patch includes support for the following operators:

GREATER_OR_EQUAL
LESS_OR_EQUAL
VERSION_GREATER_OR_EQUAL
VERSION_LESS_OR_EQUAL

Basically this is just a nice-to-have for CMake scripters so they can avoid writing ugly code like this:

IF(${CMAKE_MAJOR_VERSION} GREATER 1 AND
   ${CMAKE_MINOR_VERSION} GREATER 5) # CMake >= 2.6

# and start writing code like this:

IF(${CMAKE_MAJOR_VERSION} GREATER_OR_EQUAL 2 AND
   ${CMAKE_MINOR_VERSION} GREATER_OR_EQUAL 6) # CMake >2.6

# or better yet, in the case of a version number, code like this:

SET(ver ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
IF(ver VERSION_GREATER_OR_EQUAL 2.6)
   MESSAGE("HOORAY!")
ENDIF()
No tags attached.
patch or_equal.patch (22,838) 2008-12-04 02:01
https://public.kitware.com/Bug/file/1892/or_equal.patch
Issue History
2008-12-04 02:01Philip LowmanNew Issue
2008-12-04 02:01Philip LowmanFile Added: or_equal.patch
2008-12-04 22:21Philip LowmanNote Added: 0014300
2008-12-15 10:39Bill HoffmanStatusnew => assigned
2008-12-15 10:39Bill HoffmanAssigned To => Ken Martin
2009-08-13 00:28Philip LowmanNote Added: 0017110
2010-03-24 18:45LysiusNote Added: 0020003
2010-12-14 11:09David ColeAssigned ToKen Martin =>
2010-12-15 06:54David ColeAssigned To => David Cole
2010-12-15 07:01David ColeNote Added: 0024129
2010-12-15 07:01David ColeStatusassigned => resolved
2010-12-15 07:01David ColeFixed in Version => CMake 2.8.4
2010-12-15 07:01David ColeResolutionopen => won't fix
2011-04-04 12:00David ColeNote Added: 0026052
2011-04-04 12:00David ColeStatusresolved => closed

Notes
(0014300)
Philip Lowman   
2008-12-04 22:21   
Sorry about the poor example of the uglyness of using GREATER instead of GREATER_OR_EQUAL with:

IF(${CMAKE_MAJOR_VERSION} GREATER 1 AND
   ${CMAKE_MINOR_VERSION} GREATER 5) # CMake >= 2.6

This is false when CMake == 3.0 (woops). The point was to illustrate that code is much more readable with >= and <=. My blunder above is a nice justification for VERSION_GREATER_OR_EQUAL.

IF(${version} VERSION_GREATER 2.6 OR ${version} VERSION_EQUAL 2.6) stinks compared to:
IF(${version} VERSION_GREATER_OR_EQUAL 2.6)
(0017110)
Philip Lowman   
2009-08-13 00:28   
Hi, Just reviewing my open patches.

I see less merit in this patch than I did 8 months ago as the added operators could confuse users into thinking the feature was there since 2.6.

If it is merged in it probably should have a "Since 2.8" added to the documentation. Otherwise just dump it.
(0020003)
Lysius   
2010-03-24 18:45   
I'm also missing this feature.

The more I dig into cmake the more I get the impression that it is not yet ripe for usage. But when I see this bug (including a patch) open for more than a year, I fear that it will never become really usable.
(0024129)
David Cole   
2010-12-15 07:01   
This patch adds needless complexity to the choices available for IF comparisons. And, as you say, people will start using it when introduced, and then wonder why it doesn't work in prior versions...

Additionally,

if("${x}" GREATER_OR_EQUAL "${y}")

  is logically the same as

if(NOT "${x}" LESS "${y}")

and similarly for LESS_OR_EQUAL and NOT GREATER...

I understand that it makes for harder to read logic statements in CMakeLists.txt files when you have to invert logic, but the IF command is already quirky enough without throwing other monkey wrenches into the works at this point.

Please add additional comments, or convince me to change my mind if you disagree.
(0026052)
David Cole   
2011-04-04 12:00   
Closing resolved issues that have not been updated in more than 3 months.