Skip to content

Commit

Permalink
CMake: Fix directory scoping issue for qt6_generate_deploy_script
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jobor committed Feb 9, 2023
1 parent 5ae8417 commit 6c28528
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cmake/QtPublicPluginHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,24 @@ function(__qt_internal_collect_plugin_targets_from_dependencies_of_plugins targe
set("${out_var}" "${plugin_targets}" PARENT_SCOPE)
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)
if(NOT marked_for_deployment)
return()
Expand Down Expand Up @@ -447,8 +464,8 @@ function(__qt_internal_apply_plugin_imports_finalizer_mode target)
return()
endif()

__qt_internal_collect_plugin_targets_from_dependencies("${target}" plugin_targets)
__qt_internal_generate_plugin_deployment_info(${target} "${plugin_targets}")
__qt_internal_generate_plugin_deployment_info(${target}
OUT_PLUGIN_TARGETS plugin_targets)

# 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
Expand Down
7 changes: 7 additions & 0 deletions src/corelib/Qt6CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,13 @@ function(qt6_generate_deploy_script)
# Mark the target as "to be deployed".
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
# 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
Expand Down

0 comments on commit 6c28528

Please sign in to comment.