view cmake/CheckSharedFunctionExists.cmake @ 19:22ac5a0367cd

finally, a first pass at ear.org
author Robert McIntyre <rlm@mit.edu>
date Thu, 03 Nov 2011 14:54:45 -0700
parents f9476ff7637e
children
line wrap: on
line source
1 # - Check if a symbol exists as a function, variable, or macro
2 # CHECK_SYMBOL_EXISTS(<symbol> <files> <variable>)
3 #
4 # Check that the <symbol> is available after including given header
5 # <files> and store the result in a <variable>. Specify the list
6 # of files in one argument as a semicolon-separated list.
7 #
8 # If the header files define the symbol as a macro it is considered
9 # available and assumed to work. If the header files declare the
10 # symbol as a function or variable then the symbol must also be
11 # available for linking. If the symbol is a type or enum value
12 # it will not be recognized (consider using CheckTypeSize or
13 # CheckCSourceCompiles).
14 #
15 # The following variables may be set before calling this macro to
16 # modify the way the check is run:
17 #
18 # CMAKE_REQUIRED_FLAGS = string of compile command line flags
19 # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
20 # CMAKE_REQUIRED_INCLUDES = list of include directories
21 # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
23 #=============================================================================
24 # Copyright 2003-2011 Kitware, Inc.
25 #
26 # Distributed under the OSI-approved BSD License (the "License");
27 # see accompanying file Copyright.txt for details.
28 #
29 # This software is distributed WITHOUT ANY WARRANTY; without even the
30 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
31 # See the License for more information.
32 #=============================================================================
33 # (To distribute this file outside of CMake, substitute the full
34 # License text for the above reference.)
36 MACRO(CHECK_SHARED_FUNCTION_EXISTS SYMBOL FILES LIBRARY LOCATION VARIABLE)
37 IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
38 SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
39 SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
40 IF(CMAKE_REQUIRED_LIBRARIES)
41 SET(CHECK_SYMBOL_EXISTS_LIBS
42 "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES};${LIBRARY}")
43 ELSE(CMAKE_REQUIRED_LIBRARIES)
44 SET(CHECK_SYMBOL_EXISTS_LIBS
45 "-DLINK_LIBRARIES:STRING=${LIBRARY}")
46 ENDIF(CMAKE_REQUIRED_LIBRARIES)
47 IF(CMAKE_REQUIRED_INCLUDES)
48 SET(CMAKE_SYMBOL_EXISTS_INCLUDES
49 "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
50 ELSE(CMAKE_REQUIRED_INCLUDES)
51 SET(CMAKE_SYMBOL_EXISTS_INCLUDES)
52 ENDIF(CMAKE_REQUIRED_INCLUDES)
53 FOREACH(FILE ${FILES})
54 SET(CMAKE_CONFIGURABLE_FILE_CONTENT
55 "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
56 ENDFOREACH(FILE)
57 SET(CMAKE_CONFIGURABLE_FILE_CONTENT
58 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n cmakeRequireSymbol(0,&${SYMBOL});\n return 0;\n}\n")
60 CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
61 "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" @ONLY)
63 MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY}")
64 TRY_COMPILE(${VARIABLE}
65 ${CMAKE_BINARY_DIR}
66 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c
67 COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
68 CMAKE_FLAGS
69 -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
70 -DLINK_DIRECTORIES:STRING=${LOCATION}
71 "${CHECK_SYMBOL_EXISTS_LIBS}"
72 "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
73 OUTPUT_VARIABLE OUTPUT)
74 IF(${VARIABLE})
75 MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - found")
76 SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}")
77 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
78 "Determining if the ${SYMBOL} "
79 "exist in ${LIBRARY} passed with the following output:\n"
80 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
81 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
82 ELSE(${VARIABLE})
83 MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - not found.")
84 SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}")
85 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
86 "Determining if the ${SYMBOL} "
87 "exist in ${LIBRARY} failed with the following output:\n"
88 "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
89 "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
90 ENDIF(${VARIABLE})
91 ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
92 ENDMACRO(CHECK_SHARED_FUNCTION_EXISTS)