CMakeTestFortranCompiler.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(CMAKE_Fortran_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_Fortran_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. # Remove any cached result from an older CMake version.
  11. # We now store this in CMakeFortranCompiler.cmake.
  12. unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
  13. # This file is used by EnableLanguage in cmGlobalGenerator to
  14. # determine that the selected Fortran compiler can actually compile
  15. # and link the most basic of programs. If not, a fatal error
  16. # is set and cmake stops processing commands and will not generate
  17. # any makefiles or projects.
  18. if(NOT CMAKE_Fortran_COMPILER_WORKS)
  19. PrintTestCompilerStatus("Fortran" "")
  20. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f "
  21. PROGRAM TESTFortran
  22. PRINT *, 'Hello'
  23. END
  24. ")
  25. try_compile(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  26. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
  27. OUTPUT_VARIABLE OUTPUT)
  28. # Move result from cache to normal variable.
  29. set(CMAKE_Fortran_COMPILER_WORKS ${CMAKE_Fortran_COMPILER_WORKS})
  30. unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
  31. set(FORTRAN_TEST_WAS_RUN 1)
  32. endif()
  33. if(NOT CMAKE_Fortran_COMPILER_WORKS)
  34. PrintTestCompilerStatus("Fortran" " -- broken")
  35. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  36. "Determining if the Fortran compiler works failed with "
  37. "the following output:\n${OUTPUT}\n\n")
  38. string(REPLACE "\n" "\n " _output "${OUTPUT}")
  39. message(FATAL_ERROR "The Fortran compiler\n \"${CMAKE_Fortran_COMPILER}\"\n"
  40. "is not able to compile a simple test program.\nIt fails "
  41. "with the following output:\n ${_output}\n\n"
  42. "CMake will not be able to correctly generate this project.")
  43. else()
  44. if(FORTRAN_TEST_WAS_RUN)
  45. PrintTestCompilerStatus("Fortran" " -- works")
  46. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  47. "Determining if the Fortran compiler works passed with "
  48. "the following output:\n${OUTPUT}\n\n")
  49. endif()
  50. # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
  51. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  52. CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
  53. # Test for Fortran 90 support by using an f90-specific construct.
  54. if(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  55. message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
  56. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
  57. PROGRAM TESTFortran90
  58. integer stop ; stop = 1 ; do while ( stop .eq. 0 ) ; end do
  59. END PROGRAM TESTFortran90
  60. ")
  61. try_compile(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
  62. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
  63. OUTPUT_VARIABLE OUTPUT)
  64. if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  65. message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
  66. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  67. "Determining if the Fortran compiler supports Fortran 90 passed with "
  68. "the following output:\n${OUTPUT}\n\n")
  69. set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
  70. else()
  71. message(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
  72. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  73. "Determining if the Fortran compiler supports Fortran 90 failed with "
  74. "the following output:\n${OUTPUT}\n\n")
  75. set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
  76. endif()
  77. unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
  78. endif()
  79. # Re-configure to save learned information.
  80. configure_file(
  81. ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
  82. ${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake
  83. @ONLY
  84. )
  85. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeFortranCompiler.cmake)
  86. if(CMAKE_Fortran_SIZEOF_DATA_PTR)
  87. foreach(f ${CMAKE_Fortran_ABI_FILES})
  88. include(${f})
  89. endforeach()
  90. unset(CMAKE_Fortran_ABI_FILES)
  91. endif()
  92. endif()