Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake express the "greater or equal" statement

Tags:

cmake

I know that in CMake I can check for the compiler version like this

if(MSVC_VERSION LESS 1700)
... // MSVC is lower than MSVC2012

but how do I express this in CMake syntax?

if(MSVC_VERSION GREATER_OR_EQUAL_TO 1700)
... // MSVC greater or equal to MSVC2012
like image 569
Marco A. Avatar asked May 21 '13 09:05

Marco A.


2 Answers

Update for CMake 3.7 and later:

CMake 3.7 introduced a couple of new comparisons for if, among them GREATER_EQUAL:

if(MSVC_VERSION GREATER_EQUAL 1700)
    [...]

Original answer for older CMake versions:

if((MSVC_VERSION GREATER 1700) OR (MSVC_VERSION EQUAL 1700))
  [...]

Or probably better, as it avoids repeating the condition:

if(NOT (MSVC_VERSION LESS 1700))
  [...]
like image 158
ComicSansMS Avatar answered Nov 15 '22 05:11

ComicSansMS


Maybe use VERSION_GREATER_EQUAL? (This was also introduced in CMake 3.7.)

I.e.:

if (MSVC_VERSION VERSION_GREATER_EQUAL 1700)
# [...]

VERSION_GREATER_EQUAL and VERSION_LESS_EQUAL also support multipart version identifiers, such as 14.1.0, comparing these correctly as well.

like image 31
Stephen G Tuggy Avatar answered Nov 15 '22 05:11

Stephen G Tuggy