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()