Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Fortran compiler-dependent flags

Tags:

cmake

fortran

I'm using CMake for a moderate-sized Fortran project; sometimes I build it with gfortran, other times with ifort. When I want to do a debug build, the compiler flags are different; I'd like to have CMake automatically check which compiler is being used and set the flags accordingly.

It looks like this answer shows how to do the same thing for different C++ compilers. There's an example of how to check compilers with Fortran, using

if (Fortran_COMPILER_NAME MATCHES "gfortran.*")

However, this fails to invoke the conditional, because CMake has decided to use f95. Of course, f95 happens to alias to gfortran, but CMake doesn't detect that.

What's the right way to do this?

like image 370
Daniel Shapero Avatar asked Aug 27 '14 18:08

Daniel Shapero


1 Answers

You can use also use CMAKE_Fortran_COMPILER_ID:

if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel")
  # something
elseif("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
  # something else
endif

Best way is to read file CMakeDetermineFortranCompiler.cmake and related files referenced from it.

like image 189
Peter Avatar answered Oct 19 '22 10:10

Peter