rlm@0: # - Check if a symbol exists as a function, variable, or macro rlm@0: # CHECK_SYMBOL_EXISTS( ) rlm@0: # rlm@0: # Check that the is available after including given header rlm@0: # and store the result in a . Specify the list rlm@0: # of files in one argument as a semicolon-separated list. rlm@0: # rlm@0: # If the header files define the symbol as a macro it is considered rlm@0: # available and assumed to work. If the header files declare the rlm@0: # symbol as a function or variable then the symbol must also be rlm@0: # available for linking. If the symbol is a type or enum value rlm@0: # it will not be recognized (consider using CheckTypeSize or rlm@0: # CheckCSourceCompiles). rlm@0: # rlm@0: # The following variables may be set before calling this macro to rlm@0: # modify the way the check is run: rlm@0: # rlm@0: # CMAKE_REQUIRED_FLAGS = string of compile command line flags rlm@0: # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) rlm@0: # CMAKE_REQUIRED_INCLUDES = list of include directories rlm@0: # CMAKE_REQUIRED_LIBRARIES = list of libraries to link rlm@0: rlm@0: #============================================================================= rlm@0: # Copyright 2003-2011 Kitware, Inc. rlm@0: # rlm@0: # Distributed under the OSI-approved BSD License (the "License"); rlm@0: # see accompanying file Copyright.txt for details. rlm@0: # rlm@0: # This software is distributed WITHOUT ANY WARRANTY; without even the rlm@0: # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. rlm@0: # See the License for more information. rlm@0: #============================================================================= rlm@0: # (To distribute this file outside of CMake, substitute the full rlm@0: # License text for the above reference.) rlm@0: rlm@0: MACRO(CHECK_SHARED_FUNCTION_EXISTS SYMBOL FILES LIBRARY LOCATION VARIABLE) rlm@0: IF("${VARIABLE}" MATCHES "^${VARIABLE}$") rlm@0: SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") rlm@0: SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS}) rlm@0: IF(CMAKE_REQUIRED_LIBRARIES) rlm@0: SET(CHECK_SYMBOL_EXISTS_LIBS rlm@0: "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES};${LIBRARY}") rlm@0: ELSE(CMAKE_REQUIRED_LIBRARIES) rlm@0: SET(CHECK_SYMBOL_EXISTS_LIBS rlm@0: "-DLINK_LIBRARIES:STRING=${LIBRARY}") rlm@0: ENDIF(CMAKE_REQUIRED_LIBRARIES) rlm@0: IF(CMAKE_REQUIRED_INCLUDES) rlm@0: SET(CMAKE_SYMBOL_EXISTS_INCLUDES rlm@0: "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") rlm@0: ELSE(CMAKE_REQUIRED_INCLUDES) rlm@0: SET(CMAKE_SYMBOL_EXISTS_INCLUDES) rlm@0: ENDIF(CMAKE_REQUIRED_INCLUDES) rlm@0: FOREACH(FILE ${FILES}) rlm@0: SET(CMAKE_CONFIGURABLE_FILE_CONTENT rlm@0: "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n") rlm@0: ENDFOREACH(FILE) rlm@0: SET(CMAKE_CONFIGURABLE_FILE_CONTENT rlm@0: "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n cmakeRequireSymbol(0,&${SYMBOL});\n return 0;\n}\n") rlm@0: rlm@0: CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" rlm@0: "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" @ONLY) rlm@0: rlm@0: MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY}") rlm@0: TRY_COMPILE(${VARIABLE} rlm@0: ${CMAKE_BINARY_DIR} rlm@0: ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c rlm@0: COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} rlm@0: CMAKE_FLAGS rlm@0: -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS} rlm@0: -DLINK_DIRECTORIES:STRING=${LOCATION} rlm@0: "${CHECK_SYMBOL_EXISTS_LIBS}" rlm@0: "${CMAKE_SYMBOL_EXISTS_INCLUDES}" rlm@0: OUTPUT_VARIABLE OUTPUT) rlm@0: IF(${VARIABLE}) rlm@0: MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - found") rlm@0: SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}") rlm@0: FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log rlm@0: "Determining if the ${SYMBOL} " rlm@0: "exist in ${LIBRARY} passed with the following output:\n" rlm@0: "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n" rlm@0: "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n") rlm@0: ELSE(${VARIABLE}) rlm@0: MESSAGE(STATUS "Looking for ${SYMBOL} in ${LIBRARY} - not found.") rlm@0: SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL} in ${LIBRARY}") rlm@0: FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log rlm@0: "Determining if the ${SYMBOL} " rlm@0: "exist in ${LIBRARY} failed with the following output:\n" rlm@0: "${OUTPUT}\nFile ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n" rlm@0: "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n") rlm@0: ENDIF(${VARIABLE}) rlm@0: ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$") rlm@0: ENDMACRO(CHECK_SHARED_FUNCTION_EXISTS)