123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- include_guard(GLOBAL)
- macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
- if(NOT DEFINED "${VARIABLE}")
- set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
- "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
- if(NOT CMAKE_REQUIRED_QUIET)
- message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
- endif()
- set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
- if(CMAKE_REQUIRED_LIBRARIES)
- set(CHECK_LIBRARY_EXISTS_LIBRARIES
- ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
- endif()
- if(CMAKE_C_COMPILER_LOADED)
- set(_cle_source ${CMAKE_ROOT}/Modules/CheckFunctionExists.c)
- elseif(CMAKE_CXX_COMPILER_LOADED)
- set(_cle_source ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckLibraryExists/CheckFunctionExists.cxx)
- configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c "${_cle_source}" COPYONLY)
- else()
- message(FATAL_ERROR "CHECK_FUNCTION_EXISTS needs either C or CXX language enabled")
- endif()
- try_compile(${VARIABLE}
- ${CMAKE_BINARY_DIR}
- ${_cle_source}
- COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
- LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
- CMAKE_FLAGS
- -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
- -DLINK_DIRECTORIES:STRING=${LOCATION}
- OUTPUT_VARIABLE OUTPUT)
- unset(_cle_source)
- if(${VARIABLE})
- if(NOT CMAKE_REQUIRED_QUIET)
- message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
- endif()
- set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
- "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
- "passed with the following output:\n"
- "${OUTPUT}\n\n")
- else()
- if(NOT CMAKE_REQUIRED_QUIET)
- message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
- endif()
- set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
- file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
- "failed with the following output:\n"
- "${OUTPUT}\n\n")
- endif()
- endif()
- endmacro()
|