[CMake] Testing with multiple Fortran compilers

Alberto Luaces aluaces at udc.es
Fri Apr 13 02:59:35 EDT 2018


William Clodius writes:

> I have been using CMake with gfortran for a number of years, and now
> want test my code with ifort. I want to switch easily switch between
> compilers. My CMakeLists.txt file is based on the fortran example from
> make.org an appears to have most of the infrastructure needed, but I
> don’t understand how the line
>
> get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME)
>
> determines the Fortran compiler to be used. Does it examine the FC
> system variable?

The easiest way is to export the FC variable with the name of the
compiler before any call to cmake.  It just has to be in the path, so
you do not have to worry about specifying the absolute filename.

> Does it require the full pathname to the compiler executable? Do I
> have to delete the CMakeCache.txt, Makefile, and cmake_install.cmake
> each time I change compilers?

Absolutely.  Those need to be separate build directories, one for each
different compiler/settings.  Remember that you can have as many of
these as you want.

-- 
Alberto



More information about the CMake mailing list