From 8a00f0e175d79c62217809d28d6c103ccbeae7cc Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 15 Dec 2023 22:03:34 +0100 Subject: [PATCH] CMake: Add deployment hooks for the generic deploy tool Add a way to run code after qt_deploy_runtime_dependencies has finished its job. Motivation: To deploy QtWebEngine-specific assets we must call a QtWebEngine-specific deployment function that is defined in the QtWebEngineCore module. Qt modules (and other code) can now register a deployment hook with _qt_internal_add_deployment_hook(my_hook). The function my_hook will be called at the end of _qt_internal_generic_deployqt. The function my_hook will be called with all arguments that were passed to _qt_internal_generic_deployqt plus a list of resolved dependencies. The hook can use this list of dependencies to decide whether to deploy files. Pick-to: 6.5 Task-number: QTBUG-119077 Change-Id: I07ab2f6b3a0ea399b43409b4a0498dbf2f52664f Reviewed-by: Alexey Edelev (cherry picked from commit 21bf313ce65e248793f36363a510539f6e658771) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 5065fb780f4ef15fe0a2a41fd40359f6ac0287c2) --- src/corelib/Qt6CoreDeploySupport.cmake | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/corelib/Qt6CoreDeploySupport.cmake b/src/corelib/Qt6CoreDeploySupport.cmake index 1034368a631..388ab5fd042 100644 --- a/src/corelib/Qt6CoreDeploySupport.cmake +++ b/src/corelib/Qt6CoreDeploySupport.cmake @@ -153,6 +153,34 @@ function(_qt_internal_get_rpath_origin out_var) set(${out_var} ${rpath_origin} PARENT_SCOPE) endfunction() +# Add a function to the list of deployment hooks. +# The hooks are run at the end of _qt_internal_generic_deployqt. +# +# Every hook is passed the parameters of _qt_internal_generic_deployqt plus the following: +# RESOLVED_DEPENDENCIES: list of resolved dependencies that were installed. +function(_qt_internal_add_deployment_hook function_name) + set_property(GLOBAL APPEND PROPERTY QT_INTERNAL_DEPLOYMENT_HOOKS "${function_name}") +endfunction() + +# Run all registered deployment hooks. +function(_qt_internal_run_deployment_hooks) + get_property(hooks GLOBAL PROPERTY QT_INTERNAL_DEPLOYMENT_HOOKS) + foreach(hook IN LISTS hooks) + if(NOT COMMAND "${hook}") + message(AUTHOR_WARNING "'${hook}' is not a command but was added as deployment hook.") + continue() + endif() + if(CMAKE_VERSION GREATER_EQUAL "3.19") + cmake_language(CALL "${hook}" ${ARGV}) + else() + set(temp_file ".qt-run-deploy-hook.cmake") + file(WRITE "${temp_file}" "${hook}(${ARGV})") + include(${temp_file}) + file(REMOVE "${temp_file}") + endif() + endforeach() +endfunction() + function(_qt_internal_generic_deployqt) set(no_value_options NO_TRANSLATIONS @@ -273,6 +301,8 @@ function(_qt_internal_generic_deployqt) if(NOT arg_NO_TRANSLATIONS) qt6_deploy_translations() endif() + + _qt_internal_run_deployment_hooks(${ARGV} RESOLVED_DEPENDENCIES ${resolved}) endfunction() function(qt6_deploy_runtime_dependencies)