Fix static builds after revamp of add_qt_resource

The first issue is that instead of arg_OUTPUT_TARGET we should use
rcc_OUTPUT_TARGET (there was also a typo in the OUTPUT word).

The second issue came with the fact that the object library targets
that were created for resources had a "Qt6::" namespace prefix in the
exported Targets files, and yet the link generator expression did not
contain the prefix. This failed when building qtsvg in a static build,
because the exported object library could not be found.

The solution is to use the TARGET_NAME generator expression which
takes care of adjusting the name of the target when exported, thus
making the linking work both when building qtbase and when building
qtsvg.

This had the fallout, that all resource object libraries need
to be associated with an export set and installed. This wasn't the case
for plugins, because plugins have an export name of the form
"FooTargets", whereas the export name for the resource object library
is "Qt6FooTargets".

Adjust the export names of plugins to be the same as for modules and
resource library objects (aka contain the "Qt6 prefix").

Change-Id: I1ca28d20c51e4447e5783cc20571a68ec77f6513
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2019-08-29 17:57:04 +02:00
parent fda455d34d
commit d436023b6a
3 changed files with 12 additions and 6 deletions

View File

@ -1808,7 +1808,9 @@ function(add_qt_plugin target)
COMPONENT Devel
)
set(export_name "${target}Targets")
# Make the export name of plugins be consistent with modules, so that
# add_qt_resource adds its additional targets to the same export set in a static Qt build.
set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}Targets")
qt_install(TARGETS "${target}"
EXPORT ${export_name}
RUNTIME DESTINATION "${install_directory}"
@ -2004,7 +2006,6 @@ function(add_qt_resource target resourceName)
)
if (out_target)
qt_internal_add_target_aliases("${out_target}")
qt_install(TARGETS "${out_target}"
EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
DESTINATION ${INSTALL_LIBDIR}

View File

@ -11,5 +11,5 @@ if (NOT QT_NO_CREATE_TARGETS)
include("${CMAKE_CURRENT_LIST_DIR}/@target@Dependencies.cmake")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/@target@Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@target@Targets.cmake")
endif()

View File

@ -15,7 +15,12 @@ function(__qt_propagate_generated_resource target resource_name generated_source
if(type STREQUAL STATIC_LIBRARY)
set(resource_target "${target}_resources_${resourceName}")
add_library("${resource_target}" OBJECT "${generated_source_code}")
target_link_libraries(${target} INTERFACE "$<TARGET_OBJECTS:${resource_target}>")
# 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}>>")
set(${output_generated_target} "${resource_target}" PARENT_SCOPE)
else()
set(${output_generated_target} "" PARENT_SCOPE)
@ -265,7 +270,7 @@ function(QT@PROJECT_VERSION_MAJOR@_PROCESS_RESOURCE target resourceName)
else()
target_sources(${target} PRIVATE "${generatedSourceCode}")
endif()
if (arg_OUTPUT_TARGET)
set(${arg_OUPUT_TARGET} "${output_target}" PARENT_SCOPE)
if (rcc_OUTPUT_TARGET)
set(${rcc_OUTPUT_TARGET} "${output_target}" PARENT_SCOPE)
endif()
endfunction()