From df9c7456d11dfcf74c7399ba0981a3ba3d3f5117 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 19 Oct 2020 19:34:53 +0200 Subject: [PATCH] CMake: Add convenience custom targets to build Qt plugins Add 3 new convenience custom targets: 'qt_plugins', 'qpa_plugins' and 'qpa_default_plugins'. Additionally, if we detect that an internal executable / test links against Gui, add a dependency on the 'qpa_default_plugins' custom target, so that if a developer configures Qt for the first time and then calls ninja 'tst_foo_check', we ensure the test will launch successfully because the default QPA plugin will also be built. Change-Id: If6dd70844b5effdf8a293f65f8785855cc85b132 Reviewed-by: Alexandru Croitor --- cmake/QtBuildInternals/QtBuildInternalsConfig.cmake | 10 ++++++++++ cmake/QtExecutableHelpers.cmake | 8 ++++++++ cmake/QtPluginHelpers.cmake | 8 ++++++++ 3 files changed, 26 insertions(+) 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")