2 # determine the compiler to use for Fortran programs
3 # NOTE, a generator may set CMAKE_Fortran_COMPILER before
4 # loading this file to force a compiler.
5 # use environment variable FC first if defined by user, next use
6 # the cmake variable CMAKE_GENERATOR_FC which can be defined by a generator
7 # as a default compiler
9 IF(NOT CMAKE_Fortran_COMPILER)
10 # prefer the environment variable CC
11 IF($ENV{FC} MATCHES ".+")
12 GET_FILENAME_COMPONENT(CMAKE_Fortran_COMPILER_INIT $ENV{FC} PROGRAM PROGRAM_ARGS CMAKE_Fortran_FLAGS_ENV_INIT)
13 IF(CMAKE_Fortran_FLAGS_ENV_INIT)
14 SET(CMAKE_Fortran_COMPILER_ARG1 "${CMAKE_Fortran_FLAGS_ENV_INIT}" CACHE STRING "First argument to Fortran compiler")
15 ENDIF(CMAKE_Fortran_FLAGS_ENV_INIT)
16 IF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
17 ELSE(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
18 MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FC:\n$ENV{FC}.")
19 ENDIF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
20 ENDIF($ENV{FC} MATCHES ".+")
22 # next try prefer the compiler specified by the generator
23 IF(CMAKE_GENERATOR_FC)
24 IF(NOT CMAKE_Fortran_COMPILER_INIT)
25 SET(CMAKE_Fortran_COMPILER_INIT ${CMAKE_GENERATOR_FC})
26 ENDIF(NOT CMAKE_Fortran_COMPILER_INIT)
27 ENDIF(CMAKE_GENERATOR_FC)
29 # finally list compilers to try
30 IF(CMAKE_Fortran_COMPILER_INIT)
31 SET(CMAKE_Fortran_COMPILER_LIST ${CMAKE_Fortran_COMPILER_INIT})
32 ELSE(CMAKE_Fortran_COMPILER_INIT)
34 # f77/f90/f95: generic compiler names
35 # g77: GNU Fortran 77 compiler
36 # gfortran: putative GNU Fortran 95+ compiler (in progress)
37 # fort77: native F77 compiler under HP-UX (and some older Crays)
38 # frt: Fujitsu F77 compiler
39 # pgf77/pgf90/pgf95: Portland Group F77/F90/F95 compilers
40 # xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
41 # lf95: Lahey-Fujitsu F95 compiler
42 # fl32: Microsoft Fortran 77 "PowerStation" compiler
43 # af77: Apogee F77 compiler for Intergraph hardware running CLIX
44 # epcf90: "Edinburgh Portable Compiler" F90
45 # fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
46 # ifc: Intel Fortran 95 compiler for Linux/x86
47 # efc: Intel Fortran 95 compiler for IA64
49 # The order is 95 or newer compilers first, then 90,
50 # then 77 or older compilers, gnu is always last in the group,
51 # so if you paid for a compiler it is picked by default.
52 # NOTE for testing purposes this list is DUPLICATED in
53 # CMake/Source/CMakeLists.txt, IF YOU CHANGE THIS LIST,
54 # PLEASE UPDATE THAT FILE AS WELL!
55 SET(CMAKE_Fortran_COMPILER_LIST
56 ifort ifc efc f95 pgf95 lf95 xlf95 fort gfortran g95 f90
57 pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77
59 ENDIF(CMAKE_Fortran_COMPILER_INIT)
62 FIND_PROGRAM(CMAKE_Fortran_COMPILER NAMES ${CMAKE_Fortran_COMPILER_LIST} DOC "Fortran compiler")
63 IF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
64 SET(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER_INIT}" CACHE FILEPATH "Fortran compiler" FORCE)
65 ENDIF(CMAKE_Fortran_COMPILER_INIT AND NOT CMAKE_Fortran_COMPILER)
66 ENDIF(NOT CMAKE_Fortran_COMPILER)
68 MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER)
70 # Build a small source file to identify the compiler.
71 IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
72 SET(CMAKE_Fortran_COMPILER_ID_RUN 1)
73 SET(CMAKE_Fortran_PLATFORM_ID "Windows")
75 # TODO: Set the compiler id. It is probably MSVC but
76 # the user may be using an integrated Intel compiler.
77 # SET(CMAKE_Fortran_COMPILER_ID "MSVC")
78 ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
80 IF(NOT CMAKE_Fortran_COMPILER_ID_RUN)
81 SET(CMAKE_Fortran_COMPILER_ID_RUN 1)
83 # Each entry in this list is a set of extra flags to try
84 # adding to the compile line to see if it helps produce
85 # a valid identification executable.
86 SET(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS
87 # Try compiling to an object file only.
90 # Intel on windows does not preprocess by default.
94 # Try to identify the compiler.
95 SET(CMAKE_Fortran_COMPILER_ID)
96 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
97 CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F90)
99 # Fall back to old is-GNU test.
100 IF(NOT CMAKE_Fortran_COMPILER_ID)
101 EXEC_PROGRAM(${CMAKE_Fortran_COMPILER}
102 ARGS ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "\"${CMAKE_ROOT}/Modules/CMakeTestGNU.c\""
103 OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
104 IF(NOT CMAKE_COMPILER_RETURN)
105 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
106 SET(CMAKE_Fortran_COMPILER_ID "GNU")
107 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
108 "Determining if the Fortran compiler is GNU succeeded with "
109 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
110 ELSE("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
111 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
112 "Determining if the Fortran compiler is GNU failed with "
113 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
114 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
115 IF(NOT CMAKE_Fortran_PLATFORM_ID)
116 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
117 SET(CMAKE_Fortran_PLATFORM_ID "MinGW")
118 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
119 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
120 SET(CMAKE_Fortran_PLATFORM_ID "Cygwin")
121 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
122 ENDIF(NOT CMAKE_Fortran_PLATFORM_ID)
123 ENDIF(NOT CMAKE_COMPILER_RETURN)
124 ENDIF(NOT CMAKE_Fortran_COMPILER_ID)
126 # Set old compiler and platform id variables.
127 IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
128 SET(CMAKE_COMPILER_IS_GNUG77 1)
129 ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
130 IF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "MinGW")
131 SET(CMAKE_COMPILER_IS_MINGW 1)
132 ELSEIF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "Cygwin")
133 SET(CMAKE_COMPILER_IS_CYGWIN 1)
134 ENDIF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "MinGW")
135 ENDIF(NOT CMAKE_Fortran_COMPILER_ID_RUN)
137 INCLUDE(CMakeFindBinUtils)
139 # configure variables set in this file for fast reload later on
140 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
141 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeFortranCompiler.cmake
142 @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
144 SET(CMAKE_Fortran_COMPILER_ENV_VAR "FC")