2011-01-12 13:58:19 +00:00
|
|
|
# - Check if a symbol exists as a function, variable, or macro
|
|
|
|
# CHECK_SYMBOL_EXISTS(<symbol> <files> <variable>)
|
2005-12-15 15:41:19 +00:00
|
|
|
#
|
2011-01-12 13:58:19 +00:00
|
|
|
# Check that the <symbol> is available after including given header
|
|
|
|
# <files> and store the result in a <variable>. Specify the list
|
|
|
|
# of files in one argument as a semicolon-separated list.
|
|
|
|
#
|
|
|
|
# If the header files define the symbol as a macro it is considered
|
|
|
|
# available and assumed to work. If the header files declare the
|
|
|
|
# symbol as a function or variable then the symbol must also be
|
|
|
|
# available for linking. If the symbol is a type or enum value
|
|
|
|
# it will not be recognized (consider using CheckTypeSize or
|
|
|
|
# CheckCSourceCompiles).
|
2011-07-08 19:09:32 +00:00
|
|
|
# If the check needs to be done in C++, consider using CHECK_CXX_SYMBOL_EXISTS(),
|
|
|
|
# which does the same as CHECK_SYMBOL_EXISTS(), but in C++.
|
2006-02-10 00:23:18 +00:00
|
|
|
#
|
|
|
|
# The following variables may be set before calling this macro to
|
|
|
|
# modify the way the check is run:
|
|
|
|
#
|
|
|
|
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
|
|
|
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
|
|
|
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
|
|
|
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
2003-01-13 03:28:32 +00:00
|
|
|
|
2009-09-28 15:46:51 +00:00
|
|
|
#=============================================================================
|
2011-01-17 19:10:55 +00:00
|
|
|
# Copyright 2003-2011 Kitware, Inc.
|
2009-09-28 15:46:51 +00:00
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 00:48:47 +00:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 15:46:51 +00:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2003-01-13 03:28:32 +00:00
|
|
|
MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
2011-07-08 19:09:32 +00:00
|
|
|
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
|
|
|
ENDMACRO(CHECK_SYMBOL_EXISTS)
|
|
|
|
|
|
|
|
MACRO(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
|
2003-01-13 03:28:32 +00:00
|
|
|
IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
|
2006-02-23 14:58:07 +00:00
|
|
|
SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
|
2003-01-13 03:28:32 +00:00
|
|
|
SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
2003-03-28 18:42:34 +00:00
|
|
|
IF(CMAKE_REQUIRED_LIBRARIES)
|
2011-07-08 19:09:32 +00:00
|
|
|
SET(CHECK_SYMBOL_EXISTS_LIBS
|
2003-03-28 18:42:34 +00:00
|
|
|
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
|
2006-02-09 19:28:01 +00:00
|
|
|
ELSE(CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
SET(CHECK_SYMBOL_EXISTS_LIBS)
|
2003-03-28 18:42:34 +00:00
|
|
|
ENDIF(CMAKE_REQUIRED_LIBRARIES)
|
2006-02-09 19:28:01 +00:00
|
|
|
IF(CMAKE_REQUIRED_INCLUDES)
|
|
|
|
SET(CMAKE_SYMBOL_EXISTS_INCLUDES
|
|
|
|
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
|
|
|
|
ELSE(CMAKE_REQUIRED_INCLUDES)
|
|
|
|
SET(CMAKE_SYMBOL_EXISTS_INCLUDES)
|
|
|
|
ENDIF(CMAKE_REQUIRED_INCLUDES)
|
2003-01-13 03:28:32 +00:00
|
|
|
FOREACH(FILE ${FILES})
|
2006-02-23 14:58:07 +00:00
|
|
|
SET(CMAKE_CONFIGURABLE_FILE_CONTENT
|
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
|
2003-01-13 03:28:32 +00:00
|
|
|
ENDFOREACH(FILE)
|
2006-02-23 14:58:07 +00:00
|
|
|
SET(CMAKE_CONFIGURABLE_FILE_CONTENT
|
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n#ifndef ${SYMBOL}\n cmakeRequireSymbol(0,&${SYMBOL});\n#endif\n return 0;\n}\n")
|
2003-07-11 18:14:03 +00:00
|
|
|
|
2006-02-23 14:58:07 +00:00
|
|
|
CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
|
2011-08-22 19:48:26 +00:00
|
|
|
"${SOURCEFILE}" @ONLY IMMEDIATE)
|
2003-03-28 18:42:34 +00:00
|
|
|
|
|
|
|
MESSAGE(STATUS "Looking for ${SYMBOL}")
|
2003-01-13 03:28:32 +00:00
|
|
|
TRY_COMPILE(${VARIABLE}
|
2003-07-11 18:14:03 +00:00
|
|
|
${CMAKE_BINARY_DIR}
|
2011-07-08 19:09:32 +00:00
|
|
|
"${SOURCEFILE}"
|
2006-02-10 00:23:18 +00:00
|
|
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
2011-07-08 19:09:32 +00:00
|
|
|
CMAKE_FLAGS
|
2003-07-11 18:14:03 +00:00
|
|
|
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
|
|
|
|
"${CHECK_SYMBOL_EXISTS_LIBS}"
|
2006-02-09 19:28:01 +00:00
|
|
|
"${CMAKE_SYMBOL_EXISTS_INCLUDES}"
|
2003-07-11 18:14:03 +00:00
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
2003-01-13 03:28:32 +00:00
|
|
|
IF(${VARIABLE})
|
2003-03-28 18:42:34 +00:00
|
|
|
MESSAGE(STATUS "Looking for ${SYMBOL} - found")
|
2003-01-13 03:28:32 +00:00
|
|
|
SET(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL}")
|
2011-07-08 19:09:32 +00:00
|
|
|
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
2003-03-28 18:42:34 +00:00
|
|
|
"Determining if the ${SYMBOL} "
|
|
|
|
"exist passed with the following output:\n"
|
2011-07-08 19:09:32 +00:00
|
|
|
"${OUTPUT}\nFile ${SOURCEFILE}:\n"
|
2006-02-23 14:58:07 +00:00
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
|
2003-01-13 03:28:32 +00:00
|
|
|
ELSE(${VARIABLE})
|
2003-03-28 18:42:34 +00:00
|
|
|
MESSAGE(STATUS "Looking for ${SYMBOL} - not found.")
|
2003-01-13 03:28:32 +00:00
|
|
|
SET(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL}")
|
2011-07-08 19:09:32 +00:00
|
|
|
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
2003-01-13 03:28:32 +00:00
|
|
|
"Determining if the ${SYMBOL} "
|
|
|
|
"exist failed with the following output:\n"
|
2011-07-08 19:09:32 +00:00
|
|
|
"${OUTPUT}\nFile ${SOURCEFILE}:\n"
|
2006-02-23 14:58:07 +00:00
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
|
2003-01-13 03:28:32 +00:00
|
|
|
ENDIF(${VARIABLE})
|
|
|
|
ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
|
2011-07-08 19:09:32 +00:00
|
|
|
ENDMACRO(_CHECK_SYMBOL_EXISTS)
|