CheckFortran.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(NOT DEFINED CMAKE_Fortran_COMPILER)
  4. set(_desc "Looking for a Fortran compiler")
  5. message(STATUS ${_desc})
  6. file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran)
  7. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/CMakeLists.txt"
  8. "cmake_minimum_required(VERSION 2.8.12)
  9. project(CheckFortran Fortran)
  10. file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
  11. \"set(CMAKE_Fortran_COMPILER \\\"\${CMAKE_Fortran_COMPILER}\\\")\\n\"
  12. \"set(CMAKE_Fortran_COMPILER_ID \\\"\${CMAKE_Fortran_COMPILER_ID}\\\")\\n\"
  13. \"set(CMAKE_Fortran_FLAGS \\\"\${CMAKE_Fortran_FLAGS}\\\")\\n\"
  14. \"set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 \\\"\${CMAKE_Fortran_COMPILER_SUPPORTS_F90}\\\")\\n\"
  15. )
  16. ")
  17. if(CMAKE_GENERATOR_INSTANCE)
  18. set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
  19. else()
  20. set(_D_CMAKE_GENERATOR_INSTANCE "")
  21. endif()
  22. execute_process(
  23. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran
  24. COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
  25. -A "${CMAKE_GENERATOR_PLATFORM}"
  26. -T "${CMAKE_GENERATOR_TOOLSET}"
  27. ${_D_CMAKE_GENERATOR_INSTANCE}
  28. TIMEOUT 60
  29. OUTPUT_VARIABLE output
  30. ERROR_VARIABLE output
  31. RESULT_VARIABLE result
  32. )
  33. include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/result.cmake OPTIONAL)
  34. if(CMAKE_Fortran_COMPILER AND "${result}" STREQUAL "0")
  35. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  36. "${_desc} passed with the following output:\n"
  37. "${output}\n")
  38. else()
  39. set(CMAKE_Fortran_COMPILER NOTFOUND)
  40. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  41. "${_desc} failed with the following output:\n"
  42. "${output}\n")
  43. endif()
  44. message(STATUS "${_desc} - ${CMAKE_Fortran_COMPILER}")
  45. set(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "Fortran compiler")
  46. mark_as_advanced(CMAKE_Fortran_COMPILER)
  47. set(CMAKE_Fortran_COMPILER_ID "${CMAKE_Fortran_COMPILER_ID}" CACHE STRING "Fortran compiler Id")
  48. mark_as_advanced(CMAKE_Fortran_COMPILER_ID)
  49. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING "Fortran flags")
  50. mark_as_advanced(CMAKE_Fortran_FLAGS)
  51. set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 "${CMAKE_Fortran_COMPILER_SUPPORTS_F90}" CACHE BOOL "Fortran compiler supports F90")
  52. mark_as_advanced(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
  53. endif()