diff options
author | Craig Scott <craig.scott@qt.io> | 2021-01-20 18:05:25 +1100 |
---|---|---|
committer | Craig Scott <craig.scott@qt.io> | 2021-01-21 11:54:14 +1100 |
commit | f0ccdbb439ecce01e63b6c6947da7f56e50ecf9f (patch) | |
tree | 7770e40a0f0e6d20937746f7e872a8762b5381f1 /cmake | |
parent | af0fa5cffe55b3ce9364fa2e6f4b76bc581c08c9 (diff) |
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 <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtPlugins.cmake.in | 20 |
1 files 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 "$<NOT:$<STREQUAL:$<GENEX_EVAL:$<TARGET_PROPERTY:QT_DEFAULT_PLUGINS>>,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 "$<TARGET_PROPERTY:${_plugin_target},QT_DEFAULT_PLUGIN>") @@ -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() |