mod: Update gh-pages
[platform/upstream/gflags.git] / cmake / CheckCXXLibraryExists.cmake
1 #.rst:
2 # CheckLibraryExists
3 # ------------------
4 #
5 # Check if the function exists.
6 #
7 # CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE)
8 #
9 # ::
10 #
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
15 #
16 #
17 #
18 # The following variables may be set before calling this macro to modify
19 # the way the check is run:
20 #
21 # ::
22 #
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
26
27 #=============================================================================
28 # Copyright 2002-2009 Kitware, Inc.
29 #
30 # Distributed under the OSI-approved BSD License (the "License");
31 # see accompanying file Copyright.txt for details.
32 #
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.)
39
40
41
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})
51     endif()
52     configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c
53                    ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx COPYONLY)
54     try_compile(${VARIABLE}
55       ${CMAKE_BINARY_DIR}
56       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx
57       COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
58       LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
59       CMAKE_FLAGS
60       -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
61       -DLINK_DIRECTORIES:STRING=${LOCATION}
62       OUTPUT_VARIABLE OUTPUT)
63
64     if(${VARIABLE})
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"
70         "${OUTPUT}\n\n")
71     else()
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"
77         "${OUTPUT}\n\n")
78     endif()
79   endif()
80 endmacro()