From f5c69a5195684bf11a4d55c189435eea35e66125 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Tue, 4 May 2021 17:09:47 +1000 Subject: [PATCH] CMake: Walk link dependencies recursively to work out finalizers When versionless targets are used, they are defined as INTERFACE IMPORTED targets. These will sit between the executable target created by qt6_add_executable() and the underlying Qt6::XXX module library where the finalizers are defined. We need to recurse through the link dependencies to ensure we pick up these finalizers. This will also ensure we pick up finalizers in deeper targets from transitive dependencies. Fixes: QTBUG-93387 Change-Id: If8524ebf0e75c8790858dd7e42aa1cf4ebdfd989 Reviewed-by: Joerg Bornemann Reviewed-by: Qt CI Bot --- src/corelib/Qt6CoreMacros.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 6d477180a0..6ebcf279ba 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -517,7 +517,9 @@ function(qt6_finalize_executable target) # We can't evaluate generator expressions at configure time, so we can't # ask for any transitive properties or even the full library dependency - # chain. We can still look at the immediate dependencies though and query + # chain. + # We can still look at the immediate dependencies + # (and recursively their dependencies) and query # any that are not expressed as generator expressions. For any we can # identify as a CMake target known to the current scope, we can check if # that target has a finalizer to be called. This is expected to cover the @@ -526,12 +528,11 @@ function(qt6_finalize_executable target) # responsible for calling any relevant functions themselves instead of # relying on these automatic finalization calls. set(finalizers) - get_target_property(immediate_deps ${target} LINK_LIBRARIES) - if(immediate_deps) - foreach(dep IN LISTS immediate_deps) - if(NOT TARGET ${dep}) - continue() - endif() + + __qt_internal_collect_all_target_dependencies("${target}" dep_targets) + + if(dep_targets) + foreach(dep IN LISTS dep_targets) get_target_property(dep_finalizers ${dep} INTERFACE_QT_EXECUTABLE_FINALIZERS ) @@ -541,6 +542,7 @@ function(qt6_finalize_executable target) endforeach() list(REMOVE_DUPLICATES finalizers) endif() + if(finalizers) if(CMAKE_VERSION VERSION_LESS 3.18) # cmake_language() not available