Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake : branch on clang version

Tags:

c++

cmake

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,

like image 227
Gurg Hackpof Avatar asked Apr 22 '13 15:04

Gurg Hackpof


3 Answers

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)
     ....
like image 126
Gurg Hackpof Avatar answered Oct 23 '22 18:10

Gurg Hackpof


CMake defines following for clang:

  • CLANG_VERSION_MAJOR,
  • CLANG_VERSION_MINOR,
  • CLANG_VERSION_PATCHLEVEL,
  • and the combination of the above: CLANG_VERSION_STRING
like image 32
piokuc Avatar answered Oct 23 '22 19:10

piokuc


This works for me:

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

Similarly, we have VERSION_LESS and VERSION_EQUAL.

like image 4
vulcan raven Avatar answered Oct 23 '22 17:10

vulcan raven