CheckSymbolExists: Restore support for CMAKE_REQUIRED_FLAGS

Refactoring in commit a72e241200 (Check*: Restore more toleration of
`;-W...` in CMAKE_REQUIRED_FLAGS, 2026-07-21, v4.4.1~12^2) changed the
pattern that `Check*` modules use to forward `CMAKE_REQUIRED_FLAGS` to
`try_compile` calls.  However, it accidentally left out part of the new
pattern in the `CheckSymbolExists` module.  Fix that and add tests.

Fixes: #28001
This commit is contained in:
Josef Šimánek
2026-07-29 11:02:57 -04:00
committed by Brad King
parent d1cffecacd
commit e81906d12e
4 changed files with 20 additions and 0 deletions
+2
View File
@@ -174,6 +174,8 @@ int main(int argc, char** argv)
${_CSE_ADD_LINK_OPTIONS}
${_CSE_ADD_LINK_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}
${_CSE_EXTRA_CMAKE_ARGUMENTS}
-DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}
"${_CSE_INCLUDE_DIRECTORIES}"
"${_CSE_LINK_DIRECTORIES}"
@@ -14,6 +14,13 @@ set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists")
include(CheckCXXSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-DCSE_REQUIRED_FLAG")
check_cxx_symbol_exists(required_flag_symbol "cm_cse.h" CSE_RESULT_REQUIRED_FLAG)
if(NOT CSE_RESULT_REQUIRED_FLAG)
message(SEND_ERROR "CheckCXXSymbolExists did not honor CMAKE_REQUIRED_FLAGS")
endif()
unset(CMAKE_REQUIRED_FLAGS)
foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
unset(CSE_RESULT_${_config_type} CACHE)
@@ -14,6 +14,13 @@ set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}")
include(CheckSymbolExists)
set(CMAKE_REQUIRED_FLAGS "-DCSE_REQUIRED_FLAG")
check_symbol_exists(required_flag_symbol "cm_cse.h" CSE_RESULT_REQUIRED_FLAG)
if(NOT CSE_RESULT_REQUIRED_FLAG)
message(SEND_ERROR "CheckSymbolExists did not honor CMAKE_REQUIRED_FLAGS")
endif()
unset(CMAKE_REQUIRED_FLAGS)
foreach(_config_type Release RelWithDebInfo MinSizeRel Debug)
set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type})
unset(CSE_RESULT_${_config_type} CACHE)
@@ -3,4 +3,8 @@
int non_existent_function_for_symbol_test();
#ifdef CSE_REQUIRED_FLAG
# define required_flag_symbol 1
#endif
#endif