CMakeTestFortranCompiler.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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()
  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()
  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()
  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()
  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()
  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()
  79. unset(CMAKE_Fortran_COMPILER_SUPPORTS_F90 CACHE)
  80. endif()
  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()
  88. if(CMAKE_Fortran_SIZEOF_DATA_PTR)
  89. foreach(f ${CMAKE_Fortran_ABI_FILES})
  90. include(${f})
  91. endforeach()
  92. unset(CMAKE_Fortran_ABI_FILES)
  93. endif()
  94. endif()