[CMake] Fwd: CMake and Visual Studio 9 2008: use gfortran instead of ifort

japedo24 japedo24 at gmail.com
Fri Jul 31 07:18:45 EDT 2015


Hi guys,

I am currently working on some CMake build scripts that were designed for
crossplatform use. However they are not working perfectly under windows.

The isolated testcase looks like this: initialize a fortran project. CMake
always tries to use 'ifort' from Visual Studio as compiler but I do not
even have that installed. Instead I want to use gfortran from MingW (which
is set in my %PATH% variable).

The messy (because I tried so much stuff :) CMakeLists.txt looks like this:

cmake_minimum_required( VERSION 2.8.12 )

message( "-- env(fc): $ENV{FC}")
message( "-- cmake generator fc: ${CMAKE_GENERATOR_FC}")

set(FC "gfortran" CACHE PATH "" FORCE)
set(CMAKE_GENERATOR_FC "gfortran" CACHE PATH "" FORCE)
set(CMAKE_Fortran_COMPILER_INIT "gfortran" CACHE PATH "" FORCE)
set(CMAKE_Fortran_COMPILER_LIST "gfortran" CACHE PATH "" FORCE)
set(ENV{FC} "gfortran" CACHE PATH "" FORCE)
set(CMAKE_Fortran_COMPILER "gfortran" CACHE STRING "" FORCE)
SET(CMAKE_Fortran_COMPILER_ENV_VAR "FC")

project( example Fortran )

# why does this always print ifort instead of gfortran?
message("-- fortran compiler ${CMAKE_Fortran_COMPILER} ")

include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
   enable_language(Fortran)
else()
   message(STATUS "No native Fortran support ")
endif()

So for me none of these options to switch from ifort to gfortran works. The
output is always the same:

cmake -G "Visual Studio 9 2008" ..
-- env(fc):
-- cmake generator fc: gfortran
-- Check for working Fortran compiler using: Visual Studio 9 2008 -- broken
-> fails: "The Fortran compiler ifort is not able to compile a simple test
program."

Maybe there is someone around here who can explain this issue to me. The
CMake docs can't help me and neither googling for hours.

Please let me know if you need further system informations.

Thanks in advance!

- japedo24
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150731/7aadb78e/attachment.html>


More information about the CMake mailing list