1
0

CMakeTestFortranCompiler.cmake 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This file is used by EnableLanguage in cmGlobalGenerator to
  2. # determine that that selected Fortran compiler can actually compile
  3. # and link the most basic of programs. If not, a fatal error
  4. # is set and cmake stops processing commands and will not generate
  5. # any makefiles or projects.
  6. IF(NOT CMAKE_Fortran_COMPILER_WORKS)
  7. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER}")
  8. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f "
  9. PROGRAM TESTFortran
  10. PRINT *, 'Hello'
  11. END
  12. ")
  13. TRY_COMPILE(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  14. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
  15. OUTPUT_VARIABLE OUTPUT)
  16. SET(FORTRAN_TEST_WAS_RUN 1)
  17. ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
  18. IF(NOT CMAKE_Fortran_COMPILER_WORKS)
  19. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- broken")
  20. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  21. "Determining if the Fortran compiler works failed with "
  22. "the following output:\n${OUTPUT}\n\n")
  23. MESSAGE(FATAL_ERROR "The Fortran compiler \"${CMAKE_Fortran_COMPILER}\" "
  24. "is not able to compile a simple test program.\nIt fails "
  25. "with the following output:\n ${OUTPUT}\n\n"
  26. "CMake will not be able to correctly generate this project.")
  27. ELSE(NOT CMAKE_Fortran_COMPILER_WORKS)
  28. IF(FORTRAN_TEST_WAS_RUN)
  29. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- works")
  30. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  31. "Determining if the Fortran compiler works passed with "
  32. "the following output:\n${OUTPUT}\n\n")
  33. ENDIF(FORTRAN_TEST_WAS_RUN)
  34. SET(CMAKE_Fortran_COMPILER_WORKS 1 CACHE INTERNAL "")
  35. IF(CMAKE_Fortran_COMPILER_FORCED)
  36. # The compiler configuration was forced by the user.
  37. # Assume the user has configured all compiler information.
  38. ELSE(CMAKE_Fortran_COMPILER_FORCED)
  39. # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
  40. INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  41. CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
  42. # Test for Fortran 90 support by using an f90-specific construct.
  43. IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  44. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
  45. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
  46. PROGRAM TESTFortran90
  47. stop = 1 ; do while ( stop .eq. 0 ) ; end do
  48. END PROGRAM TESTFortran90
  49. ")
  50. TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
  51. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
  52. OUTPUT_VARIABLE OUTPUT)
  53. IF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  54. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
  55. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  56. "Determining if the Fortran compiler supports Fortran 90 passed with "
  57. "the following output:\n${OUTPUT}\n\n")
  58. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
  59. ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  60. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
  61. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  62. "Determining if the Fortran compiler supports Fortran 90 failed with "
  63. "the following output:\n${OUTPUT}\n\n")
  64. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
  65. ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  66. UNSET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
  67. ENDIF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  68. CONFIGURE_FILE(
  69. ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
  70. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeFortranCompiler.cmake
  71. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  72. )
  73. ENDIF(CMAKE_Fortran_COMPILER_FORCED)
  74. ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)