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 gfortran-4 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 ELSE(NOT CMAKE_Fortran_COMPILER)
67 # we only get here if CMAKE_Fortran_COMPILER was specified using -D or a pre-made CMakeCache.txt
68 # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE
69 # if CMAKE_Fortran_COMPILER is a list of length 2, use the first item as
70 # CMAKE_Fortran_COMPILER and the 2nd one as CMAKE_Fortran_COMPILER_ARG1
72 LIST(LENGTH CMAKE_Fortran_COMPILER _CMAKE_Fortran_COMPILER_LIST_LENGTH)
73 IF("${_CMAKE_Fortran_COMPILER_LIST_LENGTH}" EQUAL 2)
74 LIST(GET CMAKE_Fortran_COMPILER 1 CMAKE_Fortran_COMPILER_ARG1)
75 LIST(GET CMAKE_Fortran_COMPILER 0 CMAKE_Fortran_COMPILER)
76 ENDIF("${_CMAKE_Fortran_COMPILER_LIST_LENGTH}" EQUAL 2)
78 # if a compiler was specified by the user but without path,
79 # now try to find it with the full path
80 # if it is found, force it into the cache,
81 # if not, don't overwrite the setting (which was given by the user) with "NOTFOUND"
82 # if the C compiler already had a path, reuse it for searching the CXX compiler
83 GET_FILENAME_COMPONENT(_CMAKE_USER_Fortran_COMPILER_PATH "${CMAKE_Fortran_COMPILER}" PATH)
84 IF(NOT _CMAKE_USER_Fortran_COMPILER_PATH)
85 FIND_PROGRAM(CMAKE_Fortran_COMPILER_WITH_PATH NAMES ${CMAKE_Fortran_COMPILER})
86 MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER_WITH_PATH)
87 IF(CMAKE_Fortran_COMPILER_WITH_PATH)
88 SET(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER_WITH_PATH}
89 CACHE STRING "Fortran compiler" FORCE)
90 ENDIF(CMAKE_Fortran_COMPILER_WITH_PATH)
91 ENDIF(NOT _CMAKE_USER_Fortran_COMPILER_PATH)
92 ENDIF(NOT CMAKE_Fortran_COMPILER)
94 MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER)
96 # Build a small source file to identify the compiler.
97 IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
98 SET(CMAKE_Fortran_COMPILER_ID_RUN 1)
99 SET(CMAKE_Fortran_PLATFORM_ID "Windows")
101 # TODO: Set the compiler id. It is probably MSVC but
102 # the user may be using an integrated Intel compiler.
103 # SET(CMAKE_Fortran_COMPILER_ID "MSVC")
104 ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
106 IF(NOT CMAKE_Fortran_COMPILER_ID_RUN)
107 SET(CMAKE_Fortran_COMPILER_ID_RUN 1)
109 # Each entry in this list is a set of extra flags to try
110 # adding to the compile line to see if it helps produce
111 # a valid identification executable.
112 SET(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS
113 # Try compiling to an object file only.
116 # Intel on windows does not preprocess by default.
120 # Try to identify the compiler.
121 SET(CMAKE_Fortran_COMPILER_ID)
122 INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
123 CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F)
125 # Fall back to old is-GNU test.
126 IF(NOT CMAKE_Fortran_COMPILER_ID)
127 EXEC_PROGRAM(${CMAKE_Fortran_COMPILER}
128 ARGS ${CMAKE_Fortran_COMPILER_ID_FLAGS_LIST} -E "\"${CMAKE_ROOT}/Modules/CMakeTestGNU.c\""
129 OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
130 IF(NOT CMAKE_COMPILER_RETURN)
131 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
132 SET(CMAKE_Fortran_COMPILER_ID "GNU")
133 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
134 "Determining if the Fortran compiler is GNU succeeded with "
135 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
136 ELSE("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
137 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
138 "Determining if the Fortran compiler is GNU failed with "
139 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
140 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
141 IF(NOT CMAKE_Fortran_PLATFORM_ID)
142 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
143 SET(CMAKE_Fortran_PLATFORM_ID "MinGW")
144 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
145 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
146 SET(CMAKE_Fortran_PLATFORM_ID "Cygwin")
147 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
148 ENDIF(NOT CMAKE_Fortran_PLATFORM_ID)
149 ENDIF(NOT CMAKE_COMPILER_RETURN)
150 ENDIF(NOT CMAKE_Fortran_COMPILER_ID)
152 # Set old compiler and platform id variables.
153 IF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
154 SET(CMAKE_COMPILER_IS_GNUG77 1)
155 ENDIF("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU")
156 IF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "MinGW")
157 SET(CMAKE_COMPILER_IS_MINGW 1)
158 ELSEIF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "Cygwin")
159 SET(CMAKE_COMPILER_IS_CYGWIN 1)
160 ENDIF("${CMAKE_Fortran_PLATFORM_ID}" MATCHES "MinGW")
161 ENDIF(NOT CMAKE_Fortran_COMPILER_ID_RUN)
163 INCLUDE(CMakeFindBinUtils)
165 # configure variables set in this file for fast reload later on
166 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
167 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeFortranCompiler.cmake
168 @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
170 SET(CMAKE_Fortran_COMPILER_ENV_VAR "FC")