Gurg Hackpof
Gurg Hackpof

Reputation: 1334

CMake : branch on clang version

How does one achieve the equivalent of the cmake branch below for clang++?

if (GXX_VERSION VERSION_GREATER 4.5 OR GXX_VERSION VERSION_EQUAL 4.5)
    ...

Thanks,

Upvotes: 9

Views: 5009

Answers (4)

vulcan raven
vulcan raven

Reputation: 33582

This works for me:

if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.2)
    ...
    ...
endif ()

Similarly, we have VERSION_LESS and VERSION_EQUAL.

Upvotes: 5

Steven Hartland
Steven Hartland

Reputation: 11

Under cmake v3.1.3 I had to check CMAKE_CXX_COMPILER_VERSION as there was no CLANG_VERSION_STRING so looks like a version is now defined for each compiler type giving more control.

Upvotes: 1

Gurg Hackpof
Gurg Hackpof

Reputation: 1334

For some reason piokuc's solution doesn't work for me, so I did the following:

EXECUTE_PROCESS( COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE clang_full_version_string )
string (REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
if (CLANG_VERSION_STRING VERSION_GREATER 3.1)
     ....

Upvotes: 10

piokuc
piokuc

Reputation: 26204

CMake defines following for clang:

  • CLANG_VERSION_MAJOR,
  • CLANG_VERSION_MINOR,
  • CLANG_VERSION_PATCHLEVEL,
  • and the combination of the above: CLANG_VERSION_STRING

Upvotes: 4

Related Questions