Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt
3153 views
1
# This test will verify if CheckCXXSymbolExists 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 CheckSymbolExists
8
# test, too.
9
10
cmake_minimum_required(VERSION 3.10)
11
project(CheckCXXSymbolExists CXX)
12
13
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")
14
15
include(CheckCXXSymbolExists)
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
check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type})
22
23
if (CSE_RESULT_${_config_type})
24
message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}")
25
endif ()
26
endforeach()
27
28
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
29
unset(CSE_RESULT_ERRNO_CERRNO CACHE)
30
31
message(STATUS "Checking <cerrno>")
32
33
check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO)
34
35
if (NOT CSE_RESULT_ERRNO_CERRNO)
36
unset(CSE_RESULT_ERRNO_ERRNOH CACHE)
37
38
message(STATUS "Checking <errno.h>")
39
40
check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH)
41
42
if (NOT CSE_RESULT_ERRNO_ERRNOH)
43
message(SEND_ERROR "CheckCXXSymbolExists did not find errno in <cerrno> and <errno.h>")
44
else ()
45
message(STATUS "errno found in <errno.h>")
46
endif ()
47
else ()
48
message(STATUS "errno found in <cerrno>")
49
endif ()
50
51
check_cxx_symbol_exists("std::fopen" "cstdio" CSE_RESULT_FOPEN)
52
if (NOT CSE_RESULT_FOPEN)
53
if(NOT ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10))
54
message(SEND_ERROR "CheckCXXSymbolExists did not find std::fopen in <cstdio>")
55
endif()
56
else()
57
message(STATUS "std::fopen found in <cstdio>")
58
endif()
59
60
if (CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|LCC)$")
61
string(APPEND CMAKE_CXX_FLAGS " -O3")
62
unset(CSE_RESULT_O3 CACHE)
63
message(STATUS "Testing with optimization -O3")
64
65
check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3)
66
67
if (CSE_RESULT_O3)
68
message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3")
69
endif ()
70
endif ()
71
72
check_cxx_symbol_exists("std::non_existent_function_for_symbol_test<int*>" "algorithm" CSE_RESULT_NON_SYMBOL)
73
if (CSE_RESULT_NON_SYMBOL)
74
message(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol.")
75
endif()
76
77