From c5be4026513dd35b722b1e3ceb35e5140696e1af Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 28 Mar 2024 11:03:25 +0100 Subject: [PATCH] Consider the qt_internal_extend_target calls when adding deps on qpa_default_plugins Applications not necessarly link QtGui module in qt_internal_add_executable. They still may add link it in followoup qt_internal_extend_target calls. We should consider this when adding dependencies on qpa_default_plugins to the internal executables. Pick-to: 6.7 Change-Id: Icc413bd35b631b3a356e4033faab4e6c01b29a60 Reviewed-by: Alexandru Croitor --- cmake/QtExecutableHelpers.cmake | 9 --------- cmake/QtTargetHelpers.cmake | 13 +++++++++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake index 1b9200e3137..7856e4111f1 100644 --- a/cmake/QtExecutableHelpers.cmake +++ b/cmake/QtExecutableHelpers.cmake @@ -207,15 +207,6 @@ function(qt_internal_add_executable name) ADDITIONAL_INSTALL_ARGS ${additional_install_args}) qt_internal_install_pdb_files(${name} "${arg_INSTALL_DIRECTORY}") endif() - - # If linking against Gui, make sure to also build the default QPA plugin. - # This makes the experience of an initial Qt configuration to build and run one single - # test / executable nicer. - get_target_property(linked_libs "${name}" LINK_LIBRARIES) - if(linked_libs MATCHES "(^|;)(${QT_CMAKE_EXPORT_NAMESPACE}::|Qt::)?Gui($|;)" AND - TARGET qpa_default_plugins) - add_dependencies("${name}" qpa_default_plugins) - endif() endfunction() # This function compiles the target at configure time the very first time and creates the custom diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 1208658a4e3..3740e858039 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -277,9 +277,18 @@ function(qt_internal_extend_target target) _qt_extra_linker_script_exports "${arg_EXTRA_LINKER_SCRIPT_EXPORTS}") endif() - # For executables collect static plugins that these targets depend on. if(is_executable) - qt_internal_import_plugins(${target} ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES}) + # If linking against Gui, make sure to also build the default QPA plugin. + # This makes the experience of an initial Qt configuration to build and run one single + # test / executable nicer. + set(linked_libs ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES}) + if(linked_libs MATCHES "(^|;)(${QT_CMAKE_EXPORT_NAMESPACE}::|Qt::)?Gui($|;)" AND + TARGET qpa_default_plugins) + add_dependencies("${target}" qpa_default_plugins) + endif() + + # For executables collect static plugins that these targets depend on. + qt_internal_import_plugins(${target} ${linked_libs}) endif() endfunction()