CheckFortran.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #=============================================================================
  2. # Copyright 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. if(NOT DEFINED CMAKE_Fortran_COMPILER)
  14. set(_desc "Looking for a Fortran compiler")
  15. message(STATUS ${_desc})
  16. file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran)
  17. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/CMakeLists.txt"
  18. "cmake_minimum_required(VERSION 2.4)
  19. project(CheckFortran Fortran)
  20. file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
  21. \"set(CMAKE_Fortran_COMPILER \\\"\${CMAKE_Fortran_COMPILER}\\\")\\n\"
  22. \"set(CMAKE_Fortran_FLAGS \\\"\${CMAKE_Fortran_FLAGS}\\\")\\n\"
  23. )
  24. ")
  25. execute_process(
  26. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran
  27. COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
  28. OUTPUT_VARIABLE output
  29. ERROR_VARIABLE output
  30. RESULT_VARIABLE result
  31. )
  32. include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran/result.cmake OPTIONAL)
  33. if(CMAKE_Fortran_COMPILER AND "${result}" STREQUAL "0")
  34. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  35. "${_desc} passed with the following output:\n"
  36. "${output}\n")
  37. else()
  38. set(CMAKE_Fortran_COMPILER NOTFOUND)
  39. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  40. "${_desc} failed with the following output:\n"
  41. "${output}\n")
  42. endif()
  43. message(STATUS "${_desc} - ${CMAKE_Fortran_COMPILER}")
  44. set(CMAKE_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "Fortran compiler")
  45. mark_as_advanced(CMAKE_Fortran_COMPILER)
  46. set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING "Fortran flags")
  47. mark_as_advanced(CMAKE_Fortran_FLAGS)
  48. endif()