Skip to content

behavior of "IF(my_version VERSION_EQUAL something)" should be documented and/or fixed

The documentation of the IF statment with VERSION_EQUAL is currently documented as:

if(<variable|string> VERSION_EQUAL <variable|string>)
    Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]]).

This does not really clarify how the comparison works if e.g. only the major version is given, as in

if (CMAKE_Fortran_COMPILER_VERSION VERSION_EQUAL 7)

What I actually want to know is whether the major version of my Fortran compiler (here: gfortran) is 7, and I don't care if it's 7.0 7.2 or 7.3 or 7.3.5.

The current behavior seems to be such that the version that I have ("7.3.0") evaluates equal to "7.3" and "7.3.0", but not "7".

My first and minimal request is that this behavior should be documented. Second, I'd like to know how a check for just the major version should be implemented under these circumstances (disregarding any minor versions or patch levels). And finally I wonder if it would make sense to change the behavior of VERSION_EQUAL, in order to make such checks easier (they seem to be the main application to this feature to me).

I assume most people want to check for a specific major (and possibly minor) version number, and are rarely interested in some obscure patch or tweak level. Therefore a simple "VERSION_EQUAL 7" would be more useful if it checked for 7.x, instead of 7.0.0.0. If one really wants to know that the version is 7.0.1.1024, then such a check would still be possible by specifying more than just the major version.

Edited by Janus Weil
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information