1
0

CMakeTestFortranCompiler.cmake 4.6 KB

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