From e81906d12e204b04f67f9942541319ad5cabf71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= Date: Wed, 29 Jul 2026 16:41:53 +0200 Subject: [PATCH] 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 --- Modules/CheckSymbolExists.cmake | 2 ++ Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt | 7 +++++++ Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt | 7 +++++++ Tests/CMakeOnly/CheckSymbolExists/cm_cse.h | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index ab5a73b669..3f49dfc295 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -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}" diff --git a/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt index c0ca2c74bf..0d44e216b8 100644 --- a/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt @@ -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) diff --git a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt index 0a8be7ab0e..218364ab9a 100644 --- a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt @@ -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) diff --git a/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h index 4f41c76963..7c2d1c4ff3 100644 --- a/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h +++ b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h @@ -3,4 +3,8 @@ int non_existent_function_for_symbol_test(); +#ifdef CSE_REQUIRED_FLAG +# define required_flag_symbol 1 +#endif + #endif