diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index 84273b5e9e..246ee3b17b 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -235,6 +235,16 @@ macro(qt_build_repo_begin) add_custom_target(install_docs_docs) endif() + # Add global qt_plugins, qpa_plugins and qpa_default_plugins convenience custom targets. + # Internal executables will add a dependency on the qpa_default_plugins target, + # so that building and running a test ensures it won't fail at runtime due to a missing qpa + # plugin. + if(NOT TARGET qt_plugins) + add_custom_target(qt_plugins) + add_custom_target(qpa_plugins) + add_custom_target(qpa_default_plugins) + endif() + string(TOLOWER ${PROJECT_NAME} project_name_lower) set(qt_docs_target_name docs_${project_name_lower}) diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake index 27aeaf62b2..7bcad2ad7a 100644 --- a/cmake/QtExecutableHelpers.cmake +++ b/cmake/QtExecutableHelpers.cmake @@ -147,4 +147,12 @@ function(qt_internal_add_executable name) ${install_targets_default_args}) endforeach() 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("Qt::Gui" IN_LIST linked_libs AND TARGET qpa_default_plugins) + add_dependencies("${name}" qpa_default_plugins) + endif() endfunction() diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index 691735afe4..2591705a9e 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -140,6 +140,14 @@ function(qt_internal_add_plugin target) endif() endif() + add_dependencies(qt_plugins "${target}") + if(arg_TYPE STREQUAL "platforms") + add_dependencies(qpa_plugins "${target}") + endif() + if(_default_plugin) + add_dependencies(qpa_default_plugins "${target}") + endif() + set_property(TARGET "${target}" PROPERTY QT_DEFAULT_PLUGIN "${_default_plugin}") set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "QT_PLUGIN_CLASS_NAME;QT_PLUGIN_TYPE;QT_MODULE;QT_DEFAULT_PLUGIN")