CMake: Fix directory scoping issue for qt6_generate_deploy_script

Consider a Qt target created in a subdirectory and a call to
qt6_generate_deploy_app_script(target) in the parent directory.

Once qt6_generate_deploy_script (called by
qt6_generate_deploy_app_script) is run, the target has already been
finalized. However, qt6_generate_deploy_script needs to run before
finalization, because:
- qt6_generate_deploy_script marks the target as to be deployed
- the finalizer generates plugins information only if the target was
  marked to be deployed

Fix this in qt6_generate_deploy_script by checking whether the target
was already finalized. In that case, generate the plugin deployment
information right away.

Pick-to: 6.5
Fixes: QTBUG-109741
Change-Id: Idf60f9e21f038c1a33843177d9299230857ee70b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2023-01-27 15:36:31 +01:00
parent 5ae8417c4f
commit 6c28528e40
2 changed files with 27 additions and 3 deletions

View File

@ -416,7 +416,24 @@ function(__qt_internal_collect_plugin_targets_from_dependencies_of_plugins targe
set("${out_var}" "${plugin_targets}" PARENT_SCOPE) set("${out_var}" "${plugin_targets}" PARENT_SCOPE)
endfunction() endfunction()
function(__qt_internal_generate_plugin_deployment_info target plugin_targets) # Generate plugin information files for deployment
#
# Arguments:
# OUT_PLUGIN_TARGETS - Variable name to store the plugin targets that were collected with
# __qt_internal_collect_plugin_targets_from_dependencies.
function(__qt_internal_generate_plugin_deployment_info target)
set(no_value_options "")
set(single_value_options "OUT_PLUGIN_TARGETS")
set(multi_value_options "")
cmake_parse_arguments(PARSE_ARGV 0 arg
"${no_value_options}" "${single_value_options}" "${multi_value_options}"
)
__qt_internal_collect_plugin_targets_from_dependencies("${target}" plugin_targets)
if(NOT "${arg_OUT_PLUGIN_TARGETS}" STREQUAL "")
set("${arg_OUT_PLUGIN_TARGETS}" "${plugin_targets}" PARENT_SCOPE)
endif()
get_target_property(marked_for_deployment ${target} _qt_marked_for_deployment) get_target_property(marked_for_deployment ${target} _qt_marked_for_deployment)
if(NOT marked_for_deployment) if(NOT marked_for_deployment)
return() return()
@ -447,8 +464,8 @@ function(__qt_internal_apply_plugin_imports_finalizer_mode target)
return() return()
endif() endif()
__qt_internal_collect_plugin_targets_from_dependencies("${target}" plugin_targets) __qt_internal_generate_plugin_deployment_info(${target}
__qt_internal_generate_plugin_deployment_info(${target} "${plugin_targets}") OUT_PLUGIN_TARGETS plugin_targets)
# By default if the project hasn't explicitly opted in or out, use finalizer mode. # By default if the project hasn't explicitly opted in or out, use finalizer mode.
# The precondition for this is that qt_finalize_target was called (either explicitly by the user # The precondition for this is that qt_finalize_target was called (either explicitly by the user

View File

@ -2910,6 +2910,13 @@ function(qt6_generate_deploy_script)
# Mark the target as "to be deployed". # Mark the target as "to be deployed".
set_property(TARGET ${arg_TARGET} PROPERTY _qt_marked_for_deployment ON) set_property(TARGET ${arg_TARGET} PROPERTY _qt_marked_for_deployment ON)
# If the target already was finalized, maybe because it was defined in a subdirectory, generate
# the plugin deployment information here.
get_target_property(is_finalized "${arg_TARGET}" _qt_is_finalized)
if(is_finalized)
__qt_internal_generate_plugin_deployment_info(${arg_TARGET})
endif()
# Create a file name that will be unique for this target and the combination # Create a file name that will be unique for this target and the combination
# of arguments passed to this command. This allows the project to call us # of arguments passed to this command. This allows the project to call us
# multiple times with different arguments for the same target (e.g. to # multiple times with different arguments for the same target (e.g. to