summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-10-19 19:34:53 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-10-22 23:32:23 +0000
commitdf9c7456d11dfcf74c7399ba0981a3ba3d3f5117 (patch)
tree6b0ef5c7a5e267e804b55ab45ff09cc42ce5c840 /cmake
parent4fed50f4ab8fa6331e2f4d1d0567dcc961e7bb01 (diff)
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 <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake10
-rw-r--r--cmake/QtExecutableHelpers.cmake8
-rw-r--r--cmake/QtPluginHelpers.cmake8
3 files changed, 26 insertions, 0 deletions
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")