CMakeDetermineFortranCompiler.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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(CMAKE_Fortran_FLAGS_ENV_INIT)
  12. SET(CMAKE_Fortran_COMPILER_ARG1 ${CMAKE_Fortran_FLAGS_ENV_INIT} CACHE STRING "First argument to Fortran compiler")
  13. ENDIF(CMAKE_Fortran_FLAGS_ENV_INIT)
  14. IF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
  15. ELSE(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
  16. MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable FC:\n$ENV{FC}.")
  17. ENDIF(EXISTS ${CMAKE_Fortran_COMPILER_INIT})
  18. ENDIF($ENV{FC} MATCHES ".+")
  19. # next try prefer the compiler specified by the generator
  20. IF(CMAKE_GENERATOR_FC)
  21. IF(NOT CMAKE_Fortran_COMPILER_INIT)
  22. SET(CMAKE_Fortran_COMPILER_INIT ${CMAKE_GENERATOR_FC})
  23. ENDIF(NOT CMAKE_Fortran_COMPILER_INIT)
  24. 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
  28. # Known compilers:
  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
  43. #
  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)
  58. SET(CMAKE_Fortran_COMPILER ${CMAKE_Fortran_COMPILER_INIT} CACHE STRING "Fortran compiler")
  59. ENDIF(NOT CMAKE_Fortran_COMPILER)
  60. MARK_AS_ADVANCED(CMAKE_Fortran_COMPILER)
  61. FIND_PROGRAM(CMAKE_AR NAMES ar )
  62. FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib)
  63. IF(NOT CMAKE_RANLIB)
  64. SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  65. ENDIF(NOT CMAKE_RANLIB)
  66. MARK_AS_ADVANCED(CMAKE_RANLIB)
  67. # do not test for GNU if the generator is visual studio
  68. IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
  69. SET(CMAKE_COMPILER_IS_GNUG77_RUN 1)
  70. ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
  71. IF(NOT CMAKE_COMPILER_IS_GNUG77_RUN)
  72. # test to see if the Fortran compiler is gnu
  73. IF(CMAKE_Fortran_FLAGS)
  74. SET(CMAKE_BOOT_Fortran_FLAGS ${CMAKE_Fortran_FLAGS})
  75. ELSE(CMAKE_Fortran_FLAGS)
  76. SET(CMAKE_BOOT_Fortran_FLAGS $ENV{FFLAGS})
  77. ENDIF(CMAKE_Fortran_FLAGS)
  78. 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)
  79. SET(CMAKE_COMPILER_IS_GNUG77_RUN 1)
  80. IF(NOT CMAKE_COMPILER_RETURN)
  81. IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
  82. SET(CMAKE_COMPILER_IS_GNUG77 1)
  83. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
  84. "Determining if the Fortran compiler is GNU succeeded with "
  85. "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
  86. ELSE("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
  87. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
  88. "Determining if the Fortran compiler is GNU failed with "
  89. "the following output:\n${CMAKE_COMPILER_OUTPUT}\n\n")
  90. ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_GNU.*" )
  91. IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
  92. SET(CMAKE_COMPILER_IS_MINGW 1)
  93. ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_MINGW.*" )
  94. IF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
  95. SET(CMAKE_COMPILER_IS_CYGWIN 1)
  96. ENDIF("${CMAKE_COMPILER_OUTPUT}" MATCHES ".*THIS_IS_CYGWIN.*" )
  97. ENDIF(NOT CMAKE_COMPILER_RETURN)
  98. ENDIF(NOT CMAKE_COMPILER_IS_GNUG77_RUN)
  99. # configure variables set in this file for fast reload later on
  100. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
  101. ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeFortranCompiler.cmake IMMEDIATE)
  102. MARK_AS_ADVANCED(CMAKE_AR)
  103. SET(CMAKE_Fortran_COMPILER_ENV_VAR "FC")