Path: blob/master/Tests/CMakeOnly/CheckStructHasMember/CMakeLists.txt
3153 views
cmake_minimum_required(VERSION 3.10)12project(CheckStructHasMember)34set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")56include(CheckStructHasMember)78foreach(_config_type Release RelWithDebInfo Debug)9set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})10unset(CSHM_RESULT_S1_${_config_type} CACHE)11unset(CSHM_RESULT_S2_${_config_type} CACHE)12unset(CSHM_RESULT_S3_${_config_type} CACHE)13message(STATUS "Testing configuration ${_config_type}")1415check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type})16check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type})17check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type})1819if(CSHM_RESULT_S1_${_config_type} OR CSHM_RESULT_S2_${_config_type})20message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")21endif()2223if(NOT CSHM_RESULT_S3_${_config_type})24message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")25endif()26endforeach()2728foreach(_config_type Release RelWithDebInfo Debug)29set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})30unset(CSHM_RESULT_S1_${_config_type}_C CACHE)31unset(CSHM_RESULT_S2_${_config_type}_C CACHE)32unset(CSHM_RESULT_S3_${_config_type}_C CACHE)33message(STATUS "Testing configuration ${_config_type}")3435check_struct_has_member("struct non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_C LANGUAGE C)36check_struct_has_member("struct struct_with_member" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_C LANGUAGE C)37check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_C LANGUAGE C)3839if(CSHM_RESULT_S1_${_config_type}_C OR CSHM_RESULT_S2_${_config_type}_C)40message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")41endif()4243if(NOT CSHM_RESULT_S3_${_config_type}_C)44message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")45endif()46endforeach()4748foreach(_config_type Release RelWithDebInfo Debug)49set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})50unset(CSHM_RESULT_S1_${_config_type}_CXX CACHE)51unset(CSHM_RESULT_S2_${_config_type}_CXX CACHE)52unset(CSHM_RESULT_S3_${_config_type}_CXX CACHE)53unset(CSHM_RESULT_C1_${_config_type}_CXX CACHE)54unset(CSHM_RESULT_C2_${_config_type}_CXX CACHE)55unset(CSHM_RESULT_C3_${_config_type}_CXX CACHE)5657message(STATUS "Testing configuration ${_config_type}")5859check_struct_has_member("non_existent_struct" "foo" "cm_cshm.h" CSHM_RESULT_S1_${_config_type}_CXX LANGUAGE CXX)60check_struct_has_member("struct_with_non_existent_members" "non_existent_member" "cm_cshm.h" CSHM_RESULT_S2_${_config_type}_CXX LANGUAGE CXX)61check_struct_has_member("struct struct_with_member" "member" "cm_cshm.h" CSHM_RESULT_S3_${_config_type}_CXX LANGUAGE CXX)62check_struct_has_member("ns::non_existent_class" "foo" "cm_cshm.hxx" CSHM_RESULT_C1_${_config_type}_CXX LANGUAGE CXX)63check_struct_has_member("ns::class_with_non_existent_members" "foo" "cm_cshm.hxx" CSHM_RESULT_C2_${_config_type}_CXX LANGUAGE CXX)64check_struct_has_member("ns::class_with_member" "foo" "cm_cshm.hxx" CSHM_RESULT_C3_${_config_type}_CXX LANGUAGE CXX)6566if(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)67message(SEND_ERROR "CheckStructHasMember reported a nonexistent member as existing in configuration ${_config_type}")68endif()6970if(NOT CSHM_RESULT_S3_${_config_type}_CXX OR NOT CSHM_RESULT_C3_${_config_type}_CXX)71message(SEND_ERROR "CheckStructHasMember did not report an existent member as existing in configuration ${_config_type}")72endif()73endforeach()747576set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})7778if (CMAKE_C_COMPILER_ID MATCHES "^(GNU|LCC)$")79string(APPEND CMAKE_C_FLAGS " -O3")80unset(CSHM_RESULT_O3 CACHE)81unset(CSHM_RESULT_O3_C CACHE)82unset(CSHM_RESULT_O3_CXX CACHE)83message(STATUS "Testing with optimization -O3")8485check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3)86check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_C LANGUAGE C)87check_struct_has_member("class_with_non_existent_members" foo "cm_cshm.h" CSHM_RESULT_O3_CXX LANGUAGE CXX)8889if (CSE_RESULT_O3 OR CSHM_RESULT_O3_C OR CSHM_RESULT_O3_CXX)90message(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3")91endif ()92endif ()939495