1
0

CMakeTestFortranCompiler.cmake 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #=============================================================================
  2. # Copyright 2004-2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distributed this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # This file is used by EnableLanguage in cmGlobalGenerator to
  14. # determine that that 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. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER}")
  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. SET(FORTRAN_TEST_WAS_RUN 1)
  29. ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)
  30. IF(NOT CMAKE_Fortran_COMPILER_WORKS)
  31. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- broken")
  32. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  33. "Determining if the Fortran compiler works failed with "
  34. "the following output:\n${OUTPUT}\n\n")
  35. MESSAGE(FATAL_ERROR "The Fortran compiler \"${CMAKE_Fortran_COMPILER}\" "
  36. "is not able to compile a simple test program.\nIt fails "
  37. "with the following output:\n ${OUTPUT}\n\n"
  38. "CMake will not be able to correctly generate this project.")
  39. ELSE(NOT CMAKE_Fortran_COMPILER_WORKS)
  40. IF(FORTRAN_TEST_WAS_RUN)
  41. MESSAGE(STATUS "Check for working Fortran compiler: ${CMAKE_Fortran_COMPILER} -- works")
  42. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  43. "Determining if the Fortran compiler works passed with "
  44. "the following output:\n${OUTPUT}\n\n")
  45. ENDIF(FORTRAN_TEST_WAS_RUN)
  46. SET(CMAKE_Fortran_COMPILER_WORKS 1 CACHE INTERNAL "")
  47. IF(CMAKE_Fortran_COMPILER_FORCED)
  48. # The compiler configuration was forced by the user.
  49. # Assume the user has configured all compiler information.
  50. ELSE(CMAKE_Fortran_COMPILER_FORCED)
  51. # Try to identify the ABI and configure it into CMakeFortranCompiler.cmake
  52. INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
  53. CMAKE_DETERMINE_COMPILER_ABI(Fortran ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F)
  54. # Test for Fortran 90 support by using an f90-specific construct.
  55. IF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  56. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90")
  57. FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90 "
  58. PROGRAM TESTFortran90
  59. stop = 1 ; do while ( stop .eq. 0 ) ; end do
  60. END PROGRAM TESTFortran90
  61. ")
  62. TRY_COMPILE(CMAKE_Fortran_COMPILER_SUPPORTS_F90 ${CMAKE_BINARY_DIR}
  63. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompilerF90.f90
  64. OUTPUT_VARIABLE OUTPUT)
  65. IF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  66. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- yes")
  67. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  68. "Determining if the Fortran compiler supports Fortran 90 passed with "
  69. "the following output:\n${OUTPUT}\n\n")
  70. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 1)
  71. ELSE(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  72. MESSAGE(STATUS "Checking whether ${CMAKE_Fortran_COMPILER} supports Fortran 90 -- no")
  73. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  74. "Determining if the Fortran compiler supports Fortran 90 failed with "
  75. "the following output:\n${OUTPUT}\n\n")
  76. SET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 0)
  77. ENDIF(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  78. UNSET(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
  79. ENDIF(NOT DEFINED CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  80. CONFIGURE_FILE(
  81. ${CMAKE_ROOT}/Modules/CMakeFortranCompiler.cmake.in
  82. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeFortranCompiler.cmake
  83. @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
  84. )
  85. ENDIF(CMAKE_Fortran_COMPILER_FORCED)
  86. ENDIF(NOT CMAKE_Fortran_COMPILER_WORKS)