2013-10-15 19:17:36 +04:00
|
|
|
#.rst:
|
|
|
|
# CheckSymbolExists
|
|
|
|
# -----------------
|
|
|
|
#
|
|
|
|
# Check if a symbol exists as a function, variable, or macro
|
|
|
|
#
|
2011-01-12 16:58:19 +03:00
|
|
|
# CHECK_SYMBOL_EXISTS(<symbol> <files> <variable>)
|
2005-12-15 18:41:19 +03:00
|
|
|
#
|
2011-01-12 16:58:19 +03:00
|
|
|
# Check that the <symbol> is available after including given header
|
2013-10-15 19:17:36 +04:00
|
|
|
# <files> and store the result in a <variable>. Specify the list of
|
|
|
|
# files in one argument as a semicolon-separated list.
|
2014-09-10 10:35:49 +04:00
|
|
|
# <variable> will be created as an internal cache variable.
|
2011-01-12 16:58:19 +03:00
|
|
|
#
|
|
|
|
# If the header files define the symbol as a macro it is considered
|
2013-10-15 19:17:36 +04:00
|
|
|
# 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). 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++.
|
|
|
|
#
|
|
|
|
# The following variables may be set before calling this macro to modify
|
|
|
|
# the way the check is run:
|
2006-02-10 03:23:18 +03:00
|
|
|
#
|
2013-10-15 19:17:36 +04:00
|
|
|
# ::
|
2006-02-10 03:23:18 +03:00
|
|
|
#
|
2013-10-15 19:17:36 +04:00
|
|
|
# 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
|
2014-03-30 06:12:27 +04:00
|
|
|
# CMAKE_REQUIRED_QUIET = execute quietly without messages
|
2003-01-13 06:28:32 +03:00
|
|
|
|
2009-09-28 19:46:51 +04:00
|
|
|
#=============================================================================
|
2011-01-17 22:10:55 +03:00
|
|
|
# Copyright 2003-2011 Kitware, Inc.
|
2009-09-28 19:46:51 +04: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 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:46:51 +04:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
2015-09-22 07:11:50 +03:00
|
|
|
if(CMAKE_C_COMPILER_LOADED)
|
|
|
|
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
|
|
|
elseif(CMAKE_CXX_COMPILER_LOADED)
|
|
|
|
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled")
|
|
|
|
endif()
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2011-07-08 23:09:32 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
|
2014-08-18 18:49:30 +04:00
|
|
|
if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
|
|
|
|
set(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
|
|
if(CMAKE_REQUIRED_LIBRARIES)
|
|
|
|
set(CHECK_SYMBOL_EXISTS_LIBS
|
2013-02-09 13:34:37 +04:00
|
|
|
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CHECK_SYMBOL_EXISTS_LIBS)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(CMAKE_REQUIRED_INCLUDES)
|
|
|
|
set(CMAKE_SYMBOL_EXISTS_INCLUDES
|
2006-02-09 22:28:01 +03:00
|
|
|
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_SYMBOL_EXISTS_INCLUDES)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
foreach(FILE ${FILES})
|
2016-07-28 01:41:13 +03:00
|
|
|
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
|
|
|
|
"#include <${FILE}>\n")
|
2012-08-13 21:50:14 +04:00
|
|
|
endforeach()
|
2016-07-28 01:41:13 +03:00
|
|
|
string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT
|
|
|
|
"\nint main(int argc, char** argv)\n{\n (void)argv;\n#ifndef ${SYMBOL}\n return ((int*)(&${SYMBOL}))[argc];\n#else\n (void)argc;\n return 0;\n#endif\n}\n")
|
2003-07-11 22:14:03 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
|
2013-11-13 12:50:56 +04:00
|
|
|
"${SOURCEFILE}" @ONLY)
|
2003-03-28 21:42:34 +03:00
|
|
|
|
2014-03-30 06:12:27 +04:00
|
|
|
if(NOT CMAKE_REQUIRED_QUIET)
|
|
|
|
message(STATUS "Looking for ${SYMBOL}")
|
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
try_compile(${VARIABLE}
|
2003-07-11 22:14:03 +04:00
|
|
|
${CMAKE_BINARY_DIR}
|
2011-07-08 23:09:32 +04:00
|
|
|
"${SOURCEFILE}"
|
2006-02-10 03:23:18 +03:00
|
|
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
2013-02-09 13:34:37 +04:00
|
|
|
${CHECK_SYMBOL_EXISTS_LIBS}
|
2011-07-08 23:09:32 +04:00
|
|
|
CMAKE_FLAGS
|
2003-07-11 22:14:03 +04:00
|
|
|
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
|
2006-02-09 22:28:01 +03:00
|
|
|
"${CMAKE_SYMBOL_EXISTS_INCLUDES}"
|
2003-07-11 22:14:03 +04:00
|
|
|
OUTPUT_VARIABLE OUTPUT)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(${VARIABLE})
|
2014-03-30 06:12:27 +04:00
|
|
|
if(NOT CMAKE_REQUIRED_QUIET)
|
|
|
|
message(STATUS "Looking for ${SYMBOL} - found")
|
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(${VARIABLE} 1 CACHE INTERNAL "Have symbol ${SYMBOL}")
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
2003-03-28 21:42:34 +03:00
|
|
|
"Determining if the ${SYMBOL} "
|
|
|
|
"exist passed with the following output:\n"
|
2011-07-08 23:09:32 +04:00
|
|
|
"${OUTPUT}\nFile ${SOURCEFILE}:\n"
|
2006-02-23 17:58:07 +03:00
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2014-03-30 06:12:27 +04:00
|
|
|
if(NOT CMAKE_REQUIRED_QUIET)
|
|
|
|
message(STATUS "Looking for ${SYMBOL} - not found")
|
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(${VARIABLE} "" CACHE INTERNAL "Have symbol ${SYMBOL}")
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
2003-01-13 06:28:32 +03:00
|
|
|
"Determining if the ${SYMBOL} "
|
|
|
|
"exist failed with the following output:\n"
|
2011-07-08 23:09:32 +04:00
|
|
|
"${OUTPUT}\nFile ${SOURCEFILE}:\n"
|
2006-02-23 17:58:07 +03:00
|
|
|
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endmacro()
|