Search code examples
cmakefortrangfortran

cmake fortran compiler: CMAKE_FC_COMPILER or CMAKE_FORTRAN_COMPILER


I need to set a path to fortan compiler in cmake, like

set(CMAKE_FC_COMPILER         /bin/aarch64-none-linux-gnu-gfortran)
set(CMAKE_Fortran_COMPILER    /bin/aarch64-none-linux-gnu-gfortran)

cmake documentation is saying CMAKE_Fortran_COMPILER: https://cmake.org/cmake/help/latest/envvar/FC.html

but I see people CMAKE_FC_COMPILER: https://mixable.blog/how-to-set-c-c-or-fortran-compiler-for-cmake/

which one is correct and what is the difference?


Solution

  • CMAKE_FC_COMPILER isn't something I've ever come across. CMake's own documentation is trustworthy here, I don't see why it wouldn't be. I've used CMAKE_Fortran_FLAGS and build a ton of HPC software for the clusters I manage.

    The only references I find of real projects using CMAKE_FC_COMPILER is to convert it to the proper CMAKE_Fortran_COMPILER.

    I need to set a path to fortan compiler in cmake

    Or set the things during the configuration step, like FC, or cmake .. -DCMAKE_Fortran_COMPILER=/bin/your_fort Hardcoding guesses like this typically always just unnecessarily break things for everyone else (like anyone on a different OS, anyone in an HPC environment etc.).