From 74f549b4026710b484f17cd99dbafb074854bd11 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 2 Feb 2021 17:18:26 +0100 Subject: [PATCH] Fix static build with tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A static build of Qt with QT_BUILD_TESTS=ON would fail with errors like this: FAILED: tests/auto/corelib/io/qprocess/testProcessEcho2/testProcessEcho2 undefined reference to `qRegisterResourceData(...)' We create object libraries for resources. In this case, for the mimetypes of QtCore. For static builds we added the object files to INTERFACE_LINK_LIBRARIES of the Qt module the resource belongs to: target_link_libraries(Core INTERFACE "$>") That is, however, a problem for projects that link only against QtCore, like testProcessEcho2 above. On the linker command line Qt6Core.a is before qrc_mimetypes.cpp.o and that doesn't work, because the latter needs symbols of the former. To have the resource object files before any other libraries on the linker's command line, we now treat them as source files. Pick-to: 6.0 Fixes: QTBUG-90582 Change-Id: Ia2786beb5f7c2eba194e8f00ae8785572df1cf6e Reviewed-by: Tor Arne Vestbø --- src/corelib/Qt6CoreMacros.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 2a178de16c..c65203a969 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1123,8 +1123,9 @@ function(__qt_propagate_generated_resource target resource_name generated_source # Use TARGET_NAME genex to map to the correct prefixed target name when it is exported # via qt_install(EXPORT), so that the consumers of the target can find the object library # as well. - target_link_libraries(${target} INTERFACE - "$>") + target_sources(${target} INTERFACE + "$>") + set(${output_generated_target} "${resource_target}" PARENT_SCOPE) # No need to compile Q_IMPORT_PLUGIN-containing files for non-executables.