CMake: Fix resource object file paths in prl files for prefix builds

Before this change, the prl files always assumed that resource object
files are installed into $qt_prefix/lib when doing a prefix build.
That was true for qt_internal_add_resource calls, but not for
qt6_add_qml_module and qt6_target_qml_files.

Change qt_internal_record_rcc_object_files to take a new required
INSTALL_LOCATION argument. The argument takes a path relative
to CMAKE_INSTALL_PREFIX.

Modify __qt_propagate_generated_resource to save the relative path of
the generated resource source file, which will be used in the
computation of the final resource object file location.
This is needed because the Qml resource functions place the source
files in a different directory layout, e.g. .rcc vs .qmlcache

Modify qt_generate_prl_file to prepend $$[QT_INSTALL_PREFIX]/
instead of $$[QT_INSTALL_LIBS]/ for the resource install paths.

A follow up patch is done in qtdeclarative to pass the new
INSTALL_LOCATION argument from the Qml CMake functions.

Amends f9dcade5e795a631b9a2d93c855aa8198d58e24e

Task-number: QTBUG-87702
Task-number: QTBUG-88425
Change-Id: Id17bb517b4cb5d00911bfd10a728ba4e0d44871b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit 54d0ca93bca78f8fd31b6761f078e7a96283f183)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2020-11-25 17:54:53 +01:00 committed by Qt Cherry-pick Bot
parent 1f443c36f2
commit 62ee1c8504
3 changed files with 57 additions and 8 deletions

View File

@ -283,7 +283,7 @@ function(qt_generate_prl_file target install_dir)
endif() endif()
if(rcc_objects AND QT_WILL_INSTALL) if(rcc_objects AND QT_WILL_INSTALL)
list(TRANSFORM rcc_objects PREPEND "$$[QT_INSTALL_LIBS]/") list(TRANSFORM rcc_objects PREPEND "$$[QT_INSTALL_PREFIX]/")
endif() endif()
# Generate a preliminary .prl file that contains absolute paths to all libraries # Generate a preliminary .prl file that contains absolute paths to all libraries

View File

@ -19,26 +19,64 @@ function(qt_internal_add_resource target resourceName)
if (out_targets) if (out_targets)
qt_install(TARGETS ${out_targets} qt_install(TARGETS ${out_targets}
EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets" EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
DESTINATION ${INSTALL_LIBDIR} DESTINATION "${INSTALL_LIBDIR}"
) )
qt_internal_record_rcc_object_files("${target}" "${out_targets}") qt_internal_record_rcc_object_files("${target}" "${out_targets}"
INSTALL_LOCATION "${INSTALL_LIBDIR}")
endif() endif()
endfunction() endfunction()
function(qt_internal_record_rcc_object_files target resource_targets) function(qt_internal_record_rcc_object_files target resource_targets)
set(args_optional "")
set(args_single INSTALL_LOCATION)
set(args_multi "")
cmake_parse_arguments(arg
"${args_optional}"
"${args_single}"
"${args_multi}"
${ARGN}
)
foreach(out_target ${resource_targets}) foreach(out_target ${resource_targets})
get_target_property(resource_name ${out_target} _qt_resource_name) get_target_property(resource_name ${out_target} _qt_resource_name)
if(NOT resource_name) if(NOT resource_name)
continue() continue()
endif() endif()
if(QT_WILL_INSTALL) if(QT_WILL_INSTALL)
# Compute the install location of the rcc object file. # Compute the install location of a resource object file in a prefix build.
# This is the relative path below the install destination (install_prefix/lib). # It's comprised of thee following path parts:
# See CMake's computeInstallObjectDir function. #
set(object_file_name "qrc_${resource_name}.cpp${CMAKE_CXX_OUTPUT_EXTENSION}") # part (1) INSTALL_LOCATION.
# A usual value is '${INSTALL_LIBDIR}/' for libraries
# and '${INSTALL_QMLDIR}/foo/bar/' for qml plugin resources.
#
# part (2) the value computed by CMake's computeInstallObjectDir comprised of an
# objects-<CONFIG> dir and the target name of the object library.
# Example: objects-$<CONFIG>/Gui_resources_qpdf
#
# part (3) path to the object file, relative to it's build directory.
# Example: .rcc/qrc_qpdf.cpp.o
#
# The final path is relative to CMAKE_INSTALL_PREFIX aka $qt_install_prefix.
#
# The relative path will be transformed into an absolute path when generating .prl
# files, by prepending $$[QT_INSTALL_PREFIX]/.
get_target_property(generated_cpp_file_relative_path
${out_target}
_qt_resource_generated_cpp_relative_path)
set(object_file_name "${generated_cpp_file_relative_path}${CMAKE_CXX_OUTPUT_EXTENSION}")
qt_path_join(rcc_object_file_path qt_path_join(rcc_object_file_path
"objects-$<CONFIG>" ${out_target} .rcc "${object_file_name}") "objects-$<CONFIG>" ${out_target} "${object_file_name}")
if(arg_INSTALL_LOCATION)
qt_path_join(rcc_object_file_path
"${arg_INSTALL_LOCATION}" "${rcc_object_file_path}")
else()
message(FATAL_ERROR "No install location given for object files to be installed"
" for the following resource target: '${out_target}'")
endif()
else() else()
# In a non-prefix build we use the object file paths right away. # In a non-prefix build we use the object file paths right away.
set(rcc_object_file_path $<TARGET_OBJECTS:$<TARGET_NAME:${out_target}>>) set(rcc_object_file_path $<TARGET_OBJECTS:$<TARGET_NAME:${out_target}>>)

View File

@ -1063,6 +1063,17 @@ function(__qt_propagate_generated_resource target resource_name generated_source
add_library("${resource_target}" OBJECT "${generated_source_code}") add_library("${resource_target}" OBJECT "${generated_source_code}")
set_property(TARGET ${resource_target} APPEND PROPERTY _qt_resource_name ${resource_name}) set_property(TARGET ${resource_target} APPEND PROPERTY _qt_resource_name ${resource_name})
# Save the path to the generated source file, relative to the the current build dir.
# The path will be used in static library prl file generation to ensure qmake links
# against the installed resource object files.
# Example saved path:
# .rcc/qrc_qprintdialog.cpp
file(RELATIVE_PATH generated_cpp_file_relative_path
"${CMAKE_CURRENT_BINARY_DIR}"
"${generated_source_code}")
set_property(TARGET ${resource_target} APPEND PROPERTY
_qt_resource_generated_cpp_relative_path "${generated_cpp_file_relative_path}")
# Use TARGET_NAME genex to map to the correct prefixed target name when it is exported # 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 # via qt_install(EXPORT), so that the consumers of the target can find the object library
# as well. # as well.