2016-09-27 19:01:08 +00:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
|
|
|
|
2013-10-15 15:17:36 +00:00
|
|
|
#.rst:
|
|
|
|
# CheckFortranFunctionExists
|
|
|
|
# --------------------------
|
|
|
|
#
|
|
|
|
# macro which checks if the Fortran function exists
|
|
|
|
#
|
2007-10-10 21:47:37 +00:00
|
|
|
# CHECK_FORTRAN_FUNCTION_EXISTS(FUNCTION VARIABLE)
|
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
|
|
|
#
|
|
|
|
# FUNCTION - the name of the Fortran function
|
|
|
|
# VARIABLE - variable to store the result
|
2014-09-10 06:35:49 +00:00
|
|
|
# Will be created as an internal cache variable.
|
2013-10-15 15:17:36 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# The following variables may be set before calling this macro to modify
|
|
|
|
# the way the check is run:
|
|
|
|
#
|
|
|
|
# ::
|
2007-10-10 21:47:37 +00:00
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
2007-10-10 21:47:37 +00:00
|
|
|
|
|
|
|
macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
|
|
|
|
if(NOT DEFINED ${VARIABLE})
|
|
|
|
message(STATUS "Looking for Fortran ${FUNCTION}")
|
|
|
|
if(CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
|
2013-02-09 09:34:37 +00:00
|
|
|
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
|
2012-08-13 17:50:14 +00:00
|
|
|
else()
|
2007-10-10 21:47:37 +00:00
|
|
|
set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
|
2012-08-13 17:50:14 +00:00
|
|
|
endif()
|
2012-08-13 17:47:32 +00:00
|
|
|
file(WRITE
|
2007-10-10 21:47:37 +00:00
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
|
|
|
|
"
|
|
|
|
program TESTFortran
|
|
|
|
external ${FUNCTION}
|
2008-07-21 08:56:26 +00:00
|
|
|
call ${FUNCTION}()
|
2008-07-22 11:15:31 +00:00
|
|
|
end program TESTFortran
|
2007-10-10 21:47:37 +00:00
|
|
|
"
|
|
|
|
)
|
|
|
|
try_compile(${VARIABLE}
|
|
|
|
${CMAKE_BINARY_DIR}
|
|
|
|
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
|
2013-02-09 09:34:37 +00:00
|
|
|
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
|
2007-10-10 21:47:37 +00:00
|
|
|
OUTPUT_VARIABLE OUTPUT
|
|
|
|
)
|
2008-07-22 11:15:31 +00:00
|
|
|
# message(STATUS "${OUTPUT}")
|
2007-10-10 21:47:37 +00:00
|
|
|
if(${VARIABLE})
|
|
|
|
set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}")
|
|
|
|
message(STATUS "Looking for Fortran ${FUNCTION} - found")
|
2012-01-18 20:55:52 +00:00
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
2007-10-10 21:47:37 +00:00
|
|
|
"Determining if the Fortran ${FUNCTION} exists passed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n")
|
2012-08-13 17:50:14 +00:00
|
|
|
else()
|
2007-10-10 21:47:37 +00:00
|
|
|
message(STATUS "Looking for Fortran ${FUNCTION} - not found")
|
|
|
|
set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}")
|
2012-01-18 20:55:52 +00:00
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
2007-10-10 21:47:37 +00:00
|
|
|
"Determining if the Fortran ${FUNCTION} exists failed with the following output:\n"
|
|
|
|
"${OUTPUT}\n\n")
|
2012-08-13 17:50:14 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro()
|