From 51ae235080df7f051e65883a90731685649f2957 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 8 Jul 2021 14:01:59 +0200 Subject: CMake: Use correct MSVC runtime library for Qt object libraries If Qt was configured with -static-runtime which implies MultiThreaded -MT flag, the plugin initializer object libraries were still compiled with the default -MD flag. When an application linked to Qt, that caused linking to fail with mismatched symbol errors between the application symbols and the plugin initializer object library symbols. Make sure to set the MSVC_RUNTIME_LIBRARY property on both plugin initializer and resource object libraries, depending on the value of QT_FEATURE_static_runtime. We did set the property for resources added by qt_internal_add_resource, but not for the resource created by the public qt6_add_resources counterpart. Pick-to: 6.2 Fixes: QTBUG-95043 Change-Id: Ia543cd0241db94a12080be2655ad420fe9ad3f24 Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann --- cmake/QtPublicTargetHelpers.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cmake/QtPublicTargetHelpers.cmake') diff --git a/cmake/QtPublicTargetHelpers.cmake b/cmake/QtPublicTargetHelpers.cmake index d6465b4fb5..8471c45d05 100644 --- a/cmake/QtPublicTargetHelpers.cmake +++ b/cmake/QtPublicTargetHelpers.cmake @@ -299,3 +299,14 @@ function(__qt_internal_defer_promote_targets_in_dir_scope_to_global) endif() endif() endfunction() + +function(_qt_internal_set_up_static_runtime_library target) + if(QT_FEATURE_static_runtime) + if(MSVC) + set_property(TARGET ${target} PROPERTY + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + elseif(MINGW) + target_link_options(${target} INTERFACE "LINKER:-static") + endif() + endif() +endfunction() -- cgit v1.2.3