CheckFortranFunctionExists.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # - Check if the Fortran function exists.
  2. # CHECK_FORTRAN_FUNCTION_EXISTS(FUNCTION VARIABLE)
  3. # - macro which checks if the Fortran function exists
  4. # FUNCTION - the name of the Fortran function
  5. # VARIABLE - variable to store the result
  6. #
  7. # The following variables may be set before calling this macro to
  8. # modify the way the check is run:
  9. #
  10. # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
  11. #=============================================================================
  12. # Copyright 2007-2009 Kitware, Inc.
  13. #
  14. # Distributed under the OSI-approved BSD License (the "License");
  15. # see accompanying file Copyright.txt for details.
  16. #
  17. # This software is distributed WITHOUT ANY WARRANTY; without even the
  18. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. # See the License for more information.
  20. #=============================================================================
  21. # (To distribute this file outside of CMake, substitute the full
  22. # License text for the above reference.)
  23. macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
  24. if(NOT DEFINED ${VARIABLE})
  25. message(STATUS "Looking for Fortran ${FUNCTION}")
  26. if(CMAKE_REQUIRED_LIBRARIES)
  27. set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
  28. "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
  29. else(CMAKE_REQUIRED_LIBRARIES)
  30. set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
  31. endif(CMAKE_REQUIRED_LIBRARIES)
  32. FILE(WRITE
  33. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
  34. "
  35. program TESTFortran
  36. external ${FUNCTION}
  37. call ${FUNCTION}()
  38. end program TESTFortran
  39. "
  40. )
  41. try_compile(${VARIABLE}
  42. ${CMAKE_BINARY_DIR}
  43. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
  44. CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
  45. OUTPUT_VARIABLE OUTPUT
  46. )
  47. # message(STATUS "${OUTPUT}")
  48. if(${VARIABLE})
  49. set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
  50. message(STATUS "Looking for Fortran ${FUNCTION} - found")
  51. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  52. "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
  53. "${OUTPUT}\n\n")
  54. else(${VARIABLE})
  55. message(STATUS "Looking for Fortran ${FUNCTION} - not found")
  56. set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
  57. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  58. "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
  59. "${OUTPUT}\n\n")
  60. endif(${VARIABLE})
  61. endif(NOT DEFINED ${VARIABLE})
  62. endmacro(CHECK_FORTRAN_FUNCTION_EXISTS)