From bc569d65b15526951d71e659fc5aadbe8a9e7a5c Mon Sep 17 00:00:00 2001 From: Li Xinwei <1326710505@qq.com> Date: Sat, 19 Aug 2023 16:27:58 +0800 Subject: [PATCH] CMake: use correct link flag for MinGW(GCC) static-runtime build When using MinGW compiler and Qt is configured with "-static-runtime", we should pass "-static" to g++ while linking, like Qt 5, instead of "-Wl,-Bstatic", to get rid of dependencies on libgcc_s_seh-1.dll, libwinpthread-1.dll and libstdc++-6.dll. Because syncqt doesn't link to any Qt library, "target_link_options(${target} INTERFACE -static)" has no effect on it. So we should use "PRIVATE" instead of "INTERFACE" for executables. Change-Id: Icf551783f92ef3615b3840c9af16d163eee09fdb Reviewed-by: Alexey Edelev (cherry picked from commit 9256d9e7b6ab4bfeaeb733c88719e1019d7bd92b) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPublicTargetHelpers.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/QtPublicTargetHelpers.cmake b/cmake/QtPublicTargetHelpers.cmake index 6f0d3bb2c97..df9e87db117 100644 --- a/cmake/QtPublicTargetHelpers.cmake +++ b/cmake/QtPublicTargetHelpers.cmake @@ -307,7 +307,17 @@ function(_qt_internal_set_up_static_runtime_library target) set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") elseif(MINGW) - target_link_options(${target} INTERFACE "LINKER:-Bstatic") + get_target_property(target_type ${target} TYPE) + if(target_type STREQUAL "EXECUTABLE") + set(link_option PRIVATE) + else() + set(link_option INTERFACE) + endif() + if(CLANG) + target_link_options(${target} ${link_option} "LINKER:-Bstatic") + else() + target_link_options(${target} ${link_option} "-static") + endif() endif() endif() endfunction()