CMakeTestFortranCompiler.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
  36. IF(CMAKE_Fortran_COMPILER_WORKS)
  37. # Test for Fortran 90 support by using an f90-specific construct.
  38. IF(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  39. ELSE(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  40. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
  41. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
  42. PROGRAM TESTFortran90
  43. stop = 1 ; do while ( stop .eq. 0 ) ; end do
  44. END PROGRAM TESTFortran90
  45. ")
  46. TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
  47. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
  48. OUTPUT_VARIABLE OUTPUT)
  49. IF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  50. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
  51. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  52. "Determining if the Fortran compiler supports Fortran 90 passed with "
  53. "the following output:\n${OUTPUT}\n\n")
  54. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1 CACHE INTERNAL "")
  55. ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  56. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
  57. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  58. "Determining if the Fortran compiler supports Fortran 90 failed with "
  59. "the following output:\n${OUTPUT}\n\n")
  60. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0 CACHE INTERNAL "")
  61. ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  62. ENDIF(DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  63. ENDIF(CMAKE_Fortran_COMPILER_WORKS)