Path: blob/master/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt
3153 views
# This test will verify if CheckCXXSymbolExists only report symbols available1# for linking that really are. You can find some documentation on this in2# bug 11333 where we found out that gcc would optimize out the actual3# reference to the symbol, so symbols that are in fact _not_ available in the4# given libraries (but seen in header) were reported as present.5#6# If you change this test do not forget to change the CheckSymbolExists7# test, too.89cmake_minimum_required(VERSION 3.10)10project(CheckCXXSymbolExists CXX)1112set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")1314include(CheckCXXSymbolExists)1516foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)17set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})18unset(CSE_RESULT_${_config_type} CACHE)19message(STATUS "Testing configuration ${_config_type}")20check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})2122if (CSE_RESULT_${_config_type})23message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")24endif ()25endforeach()2627set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})28unset(CSE_RESULT_ERRNO_CERRNO CACHE)2930message(STATUS "Checking <cerrno>")3132check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO)3334if (NOT CSE_RESULT_ERRNO_CERRNO)35unset(CSE_RESULT_ERRNO_ERRNOH CACHE)3637message(STATUS "Checking <errno.h>")3839check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH)4041if (NOT CSE_RESULT_ERRNO_ERRNOH)42message(SEND_ERROR "CheckCXXSymbolExists did not find errno in <cerrno> and <errno.h>")43else ()44message(STATUS "errno found in <errno.h>")45endif ()46else ()47message(STATUS "errno found in <cerrno>")48endif ()4950check_cxx_symbol_exists("std::fopen" "cstdio" CSE_RESULT_FOPEN)51if (NOT CSE_RESULT_FOPEN)52if(NOT ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10))53message(SEND_ERROR "CheckCXXSymbolExists did not find std::fopen in <cstdio>")54endif()55else()56message(STATUS "std::fopen found in <cstdio>")57endif()5859if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|LCC)$")60string(APPEND CMAKE_CXX_FLAGS " -O3")61unset(CSE_RESULT_O3 CACHE)62message(STATUS "Testing with optimization -O3")6364check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)6566if (CSE_RESULT_O3)67message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3")68endif ()69endif ()7071check_cxx_symbol_exists("std::non_existent_function_for_symbol_test<int*>" "algorithm" CSE_RESULT_NON_SYMBOL)72if (CSE_RESULT_NON_SYMBOL)73message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol.")74endif()757677