Cmake - How to set different variables for Intel compiler

I have a simple cmake project (on linux) that loads some libraries from user places. Now I would like to use the Intel compiler instead of the gnu compiler and add some if statement to my CMakeLists.txt, which loads different libraries depending on the type of compiler used.

So, I would like to indicate the use of the Intel compiler through the CXX environment variable (is that right?) At the time of cmake configuration. Then I need an if-statement in the line

IF ( INTEL_IS_USED )
  BLA BLA
ELSE
  BLA BLA

What would be the easiest way to do this? In particular, is there some kind of variable that I can query for the compiler type and what is its value for the Intel compiler?

Cheers, Oliver

+3
source share
1 answer

You can check the variables CMAKE_C_COMPILERand CMAKE_CXX_COMPILER.

Something like that:

if (${CMAKE_C_COMPILER} MATCHES "icc.*$") 
  set(USING_INTEL TRUE)
endif ()
+6
source

Source: https://habr.com/ru/post/1764901/


All Articles