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