Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / CheckFortranFunctionExists.cmake
blob49858812f6432bde55154797ef100517f9cd4c31
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
12 macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
13   if(NOT DEFINED ${VARIABLE})
14     message(STATUS "Looking for Fortran ${FUNCTION}")
15     if(CMAKE_REQUIRED_LIBRARIES)
16       set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
17         "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
18     else(CMAKE_REQUIRED_LIBRARIES)
19       set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
20     endif(CMAKE_REQUIRED_LIBRARIES)
21     FILE(WRITE
22     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
23     "
24       program TESTFortran
25       external ${FUNCTION}
26       call ${FUNCTION}()
27       end program TESTFortran
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 #    message(STATUS "${OUTPUT}")
37     if(${VARIABLE})
38       set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
39       message(STATUS "Looking for Fortran ${FUNCTION} - found")
40       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
41         "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
42         "${OUTPUT}\n\n")
43     else(${VARIABLE})
44       message(STATUS "Looking for Fortran ${FUNCTION} - not found")
45       set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
46       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
47         "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
48         "${OUTPUT}\n\n")
49     endif(${VARIABLE})
50   endif(NOT DEFINED ${VARIABLE})
51 endmacro(CHECK_FORTRAN_FUNCTION_EXISTS)