From d5be7c7f31dc406a37e1cfe34a76819f331d2131 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 13 Mar 2025 16:14:15 +0100 Subject: [PATCH] Linker: Detect GNU push-state/pop-state flags more robustly Try actually passing them to the linker to see whether it complains. Fixes: #26766 --- Modules/Platform/Linker/GNU.cmake | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Modules/Platform/Linker/GNU.cmake b/Modules/Platform/Linker/GNU.cmake index a1e8bd7c0e..3d6632976d 100644 --- a/Modules/Platform/Linker/GNU.cmake +++ b/Modules/Platform/Linker/GNU.cmake @@ -21,10 +21,11 @@ function(__cmake_set_whole_archive_feature __linker) endif() if(NOT DEFINED CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED) - execute_process(COMMAND "${__linker}" --help - OUTPUT_VARIABLE __linker_help - ERROR_VARIABLE __linker_help) - if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state") + # launch linker to check if push_state/pop_state options are supported + execute_process(COMMAND "${__linker}" --push-state --pop-state + OUTPUT_VARIABLE __linker_log + ERROR_VARIABLE __linker_log) + if(__linker_log MATCHES "--push-state" OR __linker_log MATCHES "--pop-state") set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED FALSE) else() set(CMAKE_${__lang}LINKER_PUSHPOP_STATE_SUPPORTED TRUE)