ENH: update for Tcl/Tk 8.5
[cmake.git] / Modules / CheckFortranFunctionExists.cmake
blob4106a069327663254229c8ad6316599c5d74a74b
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
7 # The following variables may be set before calling this macro to
8 # modify the way the check is run:
10 #  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
13 macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
14   if(NOT DEFINED ${VARIABLE})
15     message(STATUS "Looking for Fortran ${FUNCTION}")
16     if(CMAKE_REQUIRED_LIBRARIES)
17       set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
18         "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
19     else(CMAKE_REQUIRED_LIBRARIES)
20       set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
21     endif(CMAKE_REQUIRED_LIBRARIES)
22     FILE(WRITE
23     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
24     "
25       program TESTFortran
26       external ${FUNCTION}
27       end
28     "
29     )
30     try_compile(${VARIABLE}
31     ${CMAKE_BINARY_DIR}
32     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
33     CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
34     OUTPUT_VARIABLE OUTPUT
35     )
36     if(${VARIABLE})
37       set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
38       message(STATUS "Looking for Fortran ${FUNCTION} - found")
39       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
40         "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
41         "${OUTPUT}\n\n")
42     else(${VARIABLE})
43       message(STATUS "Looking for Fortran ${FUNCTION} - not found")
44       set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
45       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
46         "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
47         "${OUTPUT}\n\n")
48     endif(${VARIABLE})
49   endif(NOT DEFINED ${VARIABLE})
50 endmacro(CHECK_FORTRAN_FUNCTION_EXISTS)