5 # Check if the function exists.
7 # CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
11 # LIBRARY - the name of the library you are looking for
12 # FUNCTION - the name of the function
13 # LOCATION - location where the library should be found
14 # VARIABLE - variable to store the result
18 # The following variables may be set before calling this macro to modify
19 # the way the check is run:
23 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
24 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
25 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
27 #=============================================================================
28 # Copyright 2002-2009 Kitware, Inc.
30 # Distributed under the OSI-approved BSD License (the "License");
31 # see accompanying file Copyright.txt for details.
33 # This software is distributed WITHOUT ANY WARRANTY; without even the
34 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35 # See the License for more information.
36 #=============================================================================
37 # (To distribute this file outside of CMake, substitute the full
38 # License text for the above reference.)
42 macro(CHECK_CXX_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
43 if("${VARIABLE}" MATCHES "^${VARIABLE}$")
44 set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION
45 "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}")
46 message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
47 set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
48 if(CMAKE_REQUIRED_LIBRARIES)
49 set(CHECK_LIBRARY_EXISTS_LIBRARIES
50 ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
52 configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c
53 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx COPYONLY)
54 try_compile(${VARIABLE}
56 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx
57 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
58 LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
60 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
61 -DLINK_DIRECTORIES:STRING=${LOCATION}
62 OUTPUT_VARIABLE OUTPUT)
65 message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found")
66 set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}")
67 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
68 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
69 "passed with the following output:\n"
72 message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found")
73 set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}")
74 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
75 "Determining if the function ${FUNCTION} exists in the ${LIBRARY} "
76 "failed with the following output:\n"