Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt
3153 views
1
# This test will verify if CheckSymbolExists only report symbols available
2
# for linking that really are. You can find some documentation on this in
3
# bug 11333 where we found out that gcc would optimize out the actual
4
# reference to the symbol, so symbols that are in fact _not_ available in the
5
# given libraries (but seen in header) were reported as present.
6
#
7
# If you change this test do not forget to change the CheckCXXSymbolExists
8
# test, too.
9
10
cmake_minimum_required(VERSION 3.10)
11
project(CheckSymbolExists C)
12
13
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
14
15
include(CheckSymbolExists)
16
17
foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
18
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
19
unset(CSE_RESULT_${_config_type} CACHE)
20
message(STATUS "Testing configuration ${_config_type}")
21
22
check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})
23
24
if (CSE_RESULT_${_config_type})
25
message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
26
endif ()
27
endforeach()
28
29
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
30
unset(CSE_RESULT_ERRNO CACHE)
31
32
check_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO)
33
34
if (NOT CSE_RESULT_ERRNO)
35
message(SEND_ERROR "CheckSymbolExists did not find errno in <errno.h>")
36
else ()
37
message(STATUS "errno found as expected")
38
endif ()
39
40
if (CMAKE_C_COMPILER_ID MATCHES "^(GNU|LCC)$")
41
string(APPEND CMAKE_C_FLAGS " -O3")
42
unset(CSE_RESULT_O3 CACHE)
43
message(STATUS "Testing with optimization -O3")
44
45
check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
46
47
if (CSE_RESULT_O3)
48
message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
49
endif ()
50
51
string(APPEND CMAKE_C_FLAGS " -pedantic-errors")
52
unset(CS_RESULT_PEDANTIC_ERRORS CACHE)
53
message(STATUS "Testing with -pedantic-errors")
54
55
check_symbol_exists(fopen "stdio.h" CSE_RESULT_PEDANTIC_ERRORS)
56
57
if(NOT CSE_RESULT_PEDANTIC_ERRORS)
58
message(SEND_ERROR "CheckSymbolExists reported an existing symbol as nonexisting with -pedantic-errors")
59
endif()
60
61
endif ()
62
63