Path: blob/master/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt
3153 views
# This test will verify if CheckSymbolExists 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 CheckCXXSymbolExists7# test, too.89cmake_minimum_required(VERSION 3.10)10project(CheckSymbolExists C)1112set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")1314include(CheckSymbolExists)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}")2021check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})2223if (CSE_RESULT_${_config_type})24message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")25endif ()26endforeach()2728set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})29unset(CSE_RESULT_ERRNO CACHE)3031check_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO)3233if (NOT CSE_RESULT_ERRNO)34message(SEND_ERROR "CheckSymbolExists did not find errno in <errno.h>")35else ()36message(STATUS "errno found as expected")37endif ()3839if (CMAKE_C_COMPILER_ID MATCHES "^(GNU|LCC)$")40string(APPEND CMAKE_C_FLAGS " -O3")41unset(CSE_RESULT_O3 CACHE)42message(STATUS "Testing with optimization -O3")4344check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)4546if (CSE_RESULT_O3)47message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")48endif ()4950string(APPEND CMAKE_C_FLAGS " -pedantic-errors")51unset(CS_RESULT_PEDANTIC_ERRORS CACHE)52message(STATUS "Testing with -pedantic-errors")5354check_symbol_exists(fopen "stdio.h" CSE_RESULT_PEDANTIC_ERRORS)5556if(NOT CSE_RESULT_PEDANTIC_ERRORS)57message(SEND_ERROR "CheckSymbolExists reported an existing symbol as nonexisting with -pedantic-errors")58endif()5960endif ()616263