From f0ccdbb439ecce01e63b6c6947da7f56e50ecf9f Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 20 Jan 2021 18:05:25 +1100 Subject: [PATCH] Only generate and add static plugin imports once per module target Projects may call find_package(Qt6 ...) multiple times. When enabling examples and tests, this happens a lot. For a statically built Qt, for modules that have plugins (e.g. Gui), every time the module's config file was loaded, it was generating and adding another copy of the import plugin sources to the module target. These accumulated and created many duplicates, which in turn blew out generation time and made the build very inefficient. This change checks whether the import plugin sources have already been processed for the module target and ensures they are only added once. It records its status on the target itself so that both local and global targets are supported. Fixes: QTBUG-90465 Change-Id: I1f45b1ee771a933ee755d44f1e983d6d9113dad0 Reviewed-by: Joerg Bornemann --- cmake/QtPlugins.cmake.in | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in index 54bfc41251..ce077a9ebc 100644 --- a/cmake/QtPlugins.cmake.in +++ b/cmake/QtPlugins.cmake.in @@ -1,7 +1,9 @@ include_guard(DIRECTORY) @QT_MODULE_PLUGIN_INCLUDES@ -if(NOT @BUILD_SHARED_LIBS@) +# Use a function to hide all the temporary variables we use so they don't leak +# out into the consuming scope +function(__qt_internal_add_static_plugins_once) set(_module_target "@INSTALL_CMAKE_NAMESPACE@::@QT_MODULE@") set(_qt_plugins "") @@ -20,7 +22,11 @@ if(NOT @BUILD_SHARED_LIBS@) if(_aliased_target) set(_module_target ${_aliased_target}) endif() - unset(_aliased_target) + + get_target_property(_have_added_plugins_already ${_module_target} __qt_internal_plugins_added) + if(_have_added_plugins_already) + return() + endif() set(_default_plugins_are_enabled "$>,0>>") # Make sure to boolify the result of the expression, in case if the returned property value @@ -61,6 +67,10 @@ if(NOT @BUILD_SHARED_LIBS@) endif() list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${_plugin_type}" "${target}") + set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${_plugin_type}" + "${QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${_plugin_type}}" + PARENT_SCOPE + ) set(_plugin_is_default "$") @@ -142,4 +152,10 @@ if(NOT @BUILD_SHARED_LIBS@) target_sources(${_module_target} INTERFACE "$<${_plugin_condition}:${_generated_qt_plugin_file_name}>") endforeach() + + set_target_properties(${_module_target} PROPERTIES __qt_internal_plugins_added TRUE) +endfunction() + +if(NOT @BUILD_SHARED_LIBS@) + __qt_internal_add_static_plugins_once() endif()