[CMake] How do you determine what compiler is being used?

Bill Hoffman bill.hoffman at kitware.com
Wed Dec 3 21:48:31 EST 2008


Bartlett, Roscoe A wrote:
> Here is some CMake code that I wrote to determine this:
> 
> 
> 
> # Determine compiler version
> 
> INCLUDE(CheckCXXSourceCompiles)
> 
> CHECK_CXX_SOURCE_COMPILES(
> "
> int main() {
> #ifdef __sun
>   // This is the SUN!
> #else
>   THIS IS NOT THE SUN
> #endif
>   return 0;
> }
> "
> Trilinos_USING_SUN_COMPILER
> )
> 
> 
This is already done in CMake 2.6.  See Modules/CMakeCCompilerId.c.in, 
it is even better than the above because it works when cross compiling. 
It does not use a try-run, but rather a try-compile, and then it looks 
for strings in the executable that was created.

Anyway, it is already done, and it sets the following variables:

CMAKE_C_COMPILER_ID
CMAKE_CXX_COMPILER_ID
CMAKE_Fortran_COMPILER_ID

-Bill


More information about the CMake mailing list