1 # determine the compiler to use for C programs
2 # NOTE, a generator may set CMAKE_C_COMPILER before
3 # loading this file to force a compiler.
4 # use environment variable CCC first if defined by user, next use
5 # the cmake variable CMAKE_GENERATOR_CC which can be defined by a generator
6 # as a default compiler
7 IF(NOT CMAKE_Fortran_COMPILER)
8 # prefer the environment variable CC
9 IF($ENV{FC} MATCHES ".+")
10 GET_FILENAME_COMPONENT(CMAKE_Fortran_COMPILER_INIT $ENV{FC} PROGRAM PROGRAM_ARGS CMAKE_Fortran_FLAGS_ENV_INIT)
11 IF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
12 ELSE(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
13 MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FC:\n$ENV{FC}.")
14 ENDIF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
15 ENDIF($ENV{FC} MATCHES ".+")
17 # next try prefer the compiler specified by the generator
18 IF(CMAKE_GENERATOR_FC)
19 IF(NOT CMAKE_Fortran_COMPILER_INIT)
20 SET(CMAKE_Fortran_COMPILER_INIT ${CMAKE_GENERATOR_FC})
21 ENDIF(NOT CMAKE_Fortran_COMPILER_INIT)
22 ENDIF(CMAKE_GENERATOR_FC)
25 # if no compiler has been specified yet, then look for one
26 IF(NOT CMAKE_Fortran_COMPILER_INIT)
27 # if not in the envionment then search for the compiler in the path
29 # f77/f90/f95: generic compiler names
30 # g77: GNU Fortran 77 compiler
31 # gfortran: putative GNU Fortran 95+ compiler (in progress)
32 # fort77: native F77 compiler under HP-UX (and some older Crays)
33 # frt: Fujitsu F77 compiler
34 # pgf77/pgf90/pgf95: Portland Group F77/F90/F95 compilers
35 # xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
36 # lf95: Lahey-Fujitsu F95 compiler
37 # fl32: Microsoft Fortran 77 "PowerStation" compiler
38 # af77: Apogee F77 compiler for Intergraph hardware running CLIX
39 # epcf90: "Edinburgh Portable Compiler" F90
40 # fort: Compaq (now HP) Fortran 90/95 compiler for Tru64 and Linux/Alpha
41 # ifc: Intel Fortran 95 compiler for Linux/x86
42 # efc: Intel Fortran 95 compiler for IA64
44 # The order is 95 or newer compilers first, then 90,
45 # then 77 or older compilers, gnu is always last in the group,
46 # so if you paid for a compiler it is picked by default.
47 # NOTE for testing purposes this list is DUPLICATED in
48 # CMake/Source/CMakeLists.txt, IF YOU CHANGE THIS LIST,
49 # PLEASE UPDATE THAT FILE AS WELL!
50 SET(CMAKE_Fortran_COMPILER_LIST ifort ifc efc f95 pgf95
51 lf95 xlf95 fort gfortran f90 pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77 )
52 FIND_PROGRAM(CMAKE_Fortran_COMPILER_FULLPATH NAMES ${CMAKE_Fortran_COMPILER_LIST} )
53 GET_FILENAME_COMPONENT(CMAKE_Fortran_COMPILER_INIT
54 ${CMAKE_Fortran_COMPILER_FULLPATH} NAME)
55 SET(CMAKE_Fortran_COMPILER_FULLPATH "${CMAKE_Fortran_COMPILER_FULLPATH}"
56 CACHE INTERNAL "full path to the compiler cmake found")
57 ENDIF(NOT CMAKE_Fortran_COMPILER_INIT)
59 SET(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER_INIT} CACHE STRING "Fortran compiler")
60 ENDIF(NOT CMAKE_Fortran_COMPILER)
62 MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER)
64 FIND_PROGRAM(CMAKE_AR NAMES ar )
66 FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib)
68 SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
69 ENDIF(NOT CMAKE_RANLIB)
70 MARK_AS_ADVANCED(CMAKE_RANLIB)
72 # do not test for GNU if the generator is visual studio
73 IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
74 SET(CMAKE_COMPILER_IS_GNUG77_RUN 1)
75 ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
77 IF(NOT CMAKE_COMPILER_IS_GNUG77_RUN)
78 # test to see if the Fortran compiler is gnu
80 IF(CMAKE_Fortran_FLAGS)
81 SET(CMAKE_BOOT_Fortran_FLAGS ${CMAKE_Fortran_FLAGS})
82 ELSE(CMAKE_Fortran_FLAGS)
83 SET(CMAKE_BOOT_Fortran_FLAGS $ENV{FFLAGS})
84 ENDIF(CMAKE_Fortran_FLAGS)
85 EXEC_PROGRAM(${CMAKE_Fortran_COMPILER} ARGS ${CMAKE_BOOT_Fortran_FLAGS} -E "\"${CMAKE_ROOT}/Modules/CMakeTestGNU.c\"" OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
86 SET(CMAKE_COMPILER_IS_GNUG77_RUN 1)
87 IF(NOT CMAKE_COMPILER_RETURN)
88 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
89 SET(CMAKE_COMPILER_IS_GNUG77 1)
90 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
91 "Determining if the Fortran compiler is GNU succeeded with "
92 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
93 ELSE("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
94 FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
95 "Determining if the Fortran compiler is GNU failed with "
96 "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
97 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
98 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
99 SET(CMAKE_COMPILER_IS_MINGW 1)
100 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
101 IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
102 SET(CMAKE_COMPILER_IS_CYGWIN 1)
103 ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
104 ENDIF(NOT CMAKE_COMPILER_RETURN)
105 ENDIF(NOT CMAKE_COMPILER_IS_GNUG77_RUN)
108 # configure variables set in this file for fast reload later on
109 CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
110 ${CMAKE_BINARY_DIR}/CMakeFortranCompiler.cmake IMMEDIATE)
111 MARK_AS_ADVANCED(CMAKE_AR)
112 SET(CMAKE_Fortran_COMPILER_ENV_VAR "FC")