Fix static build with tests

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
        "$<TARGET_OBJECTS:$<TARGET_NAME:${resource_target}>>")

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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
Joerg Bornemann 2021-02-02 17:18:26 +01:00
parent 936d499ed4
commit 74f549b402

View File

@ -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_OBJECTS:$<TARGET_NAME:${resource_target}>>")
target_sources(${target} INTERFACE
"$<TARGET_OBJECTS:$<TARGET_NAME:${resource_target}>>")
set(${output_generated_target} "${resource_target}" PARENT_SCOPE)
# No need to compile Q_IMPORT_PLUGIN-containing files for non-executables.