Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
3153 views
1
cmake_minimum_required(VERSION 3.10)
2
3
project(CheckStructHasMember)
4
5
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
6
7
include(CheckStructHasMember)
8
9
foreach(_config_type Release RelWithDebInfo Debug)
10
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
11
unset(CSHM_RESULT_S1_${_config_type} CACHE)
12
unset(CSHM_RESULT_S2_${_config_type} CACHE)
13
unset(CSHM_RESULT_S3_${_config_type} CACHE)
14
message(STATUS "Testing configuration ${_config_type}")
15
16
check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type})
17
check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type})
18
check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type})
19
20
if(CSHM_RESULT_S1_${_config_type} OR CSHM_RESULT_S2_${_config_type})
21
message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
22
endif()
23
24
if(NOT CSHM_RESULT_S3_${_config_type})
25
message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
26
endif()
27
endforeach()
28
29
foreach(_config_type Release RelWithDebInfo Debug)
30
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
31
unset(CSHM_RESULT_S1_${_config_type}_C CACHE)
32
unset(CSHM_RESULT_S2_${_config_type}_C CACHE)
33
unset(CSHM_RESULT_S3_${_config_type}_C CACHE)
34
message(STATUS "Testing configuration ${_config_type}")
35
36
check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_C LANGUAGE C)
37
check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_C LANGUAGE C)
38
check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_C LANGUAGE C)
39
40
if(CSHM_RESULT_S1_${_config_type}_C OR CSHM_RESULT_S2_${_config_type}_C)
41
message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
42
endif()
43
44
if(NOT CSHM_RESULT_S3_${_config_type}_C)
45
message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
46
endif()
47
endforeach()
48
49
foreach(_config_type Release RelWithDebInfo Debug)
50
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
51
unset(CSHM_RESULT_S1_${_config_type}_CXX CACHE)
52
unset(CSHM_RESULT_S2_${_config_type}_CXX CACHE)
53
unset(CSHM_RESULT_S3_${_config_type}_CXX CACHE)
54
unset(CSHM_RESULT_C1_${_config_type}_CXX CACHE)
55
unset(CSHM_RESULT_C2_${_config_type}_CXX CACHE)
56
unset(CSHM_RESULT_C3_${_config_type}_CXX CACHE)
57
58
message(STATUS "Testing configuration ${_config_type}")
59
60
check_struct_has_member("non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_CXX LANGUAGE CXX)
61
check_struct_has_member("struct_with_non_existent_members" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_CXX LANGUAGE CXX)
62
check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_CXX LANGUAGE CXX)
63
check_struct_has_member("ns::non_existent_class" "foo" "cm_cshm.hxx" CSHM_RESULT_C1_${_config_type}_CXX LANGUAGE CXX)
64
check_struct_has_member("ns::class_with_non_existent_members" "foo" "cm_cshm.hxx" CSHM_RESULT_C2_${_config_type}_CXX LANGUAGE CXX)
65
check_struct_has_member("ns::class_with_member" "foo" "cm_cshm.hxx" CSHM_RESULT_C3_${_config_type}_CXX LANGUAGE CXX)
66
67
if(CSHM_RESULT_S1_${_config_type}_CXX OR CSHM_RESULT_S2_${_config_type}_CXX OR CSHM_RESULT_C1_${_config_type}_CXX OR CSHM_RESULT_C2_${_config_type}_CXX)
68
message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")
69
endif()
70
71
if(NOT CSHM_RESULT_S3_${_config_type}_CXX OR NOT CSHM_RESULT_C3_${_config_type}_CXX)
72
message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")
73
endif()
74
endforeach()
75
76
77
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
78
79
if (CMAKE_C_COMPILER_ID MATCHES "^(GNU|LCC)$")
80
string(APPEND CMAKE_C_FLAGS " -O3")
81
unset(CSHM_RESULT_O3 CACHE)
82
unset(CSHM_RESULT_O3_C CACHE)
83
unset(CSHM_RESULT_O3_CXX CACHE)
84
message(STATUS "Testing with optimization -O3")
85
86
check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3)
87
check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_C LANGUAGE C)
88
check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_CXX LANGUAGE CXX)
89
90
if (CSE_RESULT_O3 OR CSHM_RESULT_O3_C OR CSHM_RESULT_O3_CXX)
91
message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")
92
endif ()
93
endif ()
94
95