summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-07-01 14:29:25 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2022-07-05 13:04:09 +0200
commitff4be4cf30ec470ab00290c629bb1bc311b77e22 (patch)
tree34e831f9439a7189fdd218d652ebe9819598f82f /cmake
parenteb8da02d055f8f761880da33b02342ca2d69b1a5 (diff)
CMake: Move plugin package inclusion logic into a common function
Don't duplicate the logic of plugin package inclusion for each Qt module. Instead move it into QtPublicPluginHelpers.cmake. Pick-to: 6.4 Task-number: QTBUG-94066 Change-Id: I5e1f5176a0e754ed56a792c97865752529462617 Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPlugins.cmake.in63
-rw-r--r--cmake/QtPublicPluginHelpers.cmake65
2 files changed, 66 insertions, 62 deletions
diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in
index a96588cc5e..09a2f40414 100644
--- a/cmake/QtPlugins.cmake.in
+++ b/cmake/QtPlugins.cmake.in
@@ -1,67 +1,6 @@
include_guard(DIRECTORY)
@QT_MODULE_PLUGIN_INCLUDES@
-# 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 "")
-
- # Properties can't be set on aliased targets, so make sure to unalias the target. This is needed
- # when Qt examples are built as part of the Qt build itself.
- get_target_property(_aliased_target ${_module_target} ALIASED_TARGET)
- if(_aliased_target)
- set(_module_target ${_aliased_target})
- endif()
-
- # Include all PluginConfig.cmake files and update the _qt_plugins and QT_PLUGINS property of
- # the module. The underscored version is the one we will use going forward to have compatibility
- # with INTERFACE libraries. QT_PLUGINS is now deprecated and only kept so that we don't break
- # existing projects using it (like CMake itself).
- file(GLOB _qt_plugin_config_files "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@*PluginConfig.cmake")
- foreach(_config_file ${_qt_plugin_config_files})
- string(REGEX REPLACE "^.*/@INSTALL_CMAKE_NAMESPACE@(.*Plugin)Config.cmake$" "\\1" _qt_plugin "${_config_file}")
- include("${_config_file}")
- if(TARGET "@INSTALL_CMAKE_NAMESPACE@::${_qt_plugin}")
- list(APPEND _qt_plugins ${_qt_plugin})
- endif()
- endforeach()
- set_property(TARGET ${_module_target} PROPERTY _qt_plugins ${_qt_plugins})
-
- # TODO: Deprecated. Remove in Qt 7.
- set_property(TARGET ${_module_target} PROPERTY QT_PLUGINS ${_qt_plugins})
-
- get_target_property(_have_added_plugins_already ${_module_target} __qt_internal_plugins_added)
- if(_have_added_plugins_already)
- return()
- endif()
-
- foreach(plugin_target ${_qt_plugins})
- __qt_internal_plugin_get_plugin_type("${plugin_target}" __has_plugin_type __plugin_type)
- if(NOT __has_plugin_type)
- continue()
- endif()
-
- __qt_internal_plugin_has_class_name("${plugin_target}" __has_class_name)
- if(NOT __has_class_name)
- continue()
- endif()
-
- list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}")
-
- __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
- __qt_internal_add_static_plugin_import_macro(
- "${plugin_target}" ${_module_target} "@QT_MODULE@")
- endforeach()
-
- set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}"
- "${QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}}"
- PARENT_SCOPE
- )
-
- set_target_properties(${_module_target} PROPERTIES __qt_internal_plugins_added TRUE)
-endfunction()
-
if(NOT @BUILD_SHARED_LIBS@ AND NOT QT_NO_CREATE_TARGETS)
- __qt_internal_add_static_plugins_once()
+ __qt_internal_include_plugin_packages(@QT_MODULE@)
endif()
diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake
index a5b1125e4f..90d784d88e 100644
--- a/cmake/QtPublicPluginHelpers.cmake
+++ b/cmake/QtPublicPluginHelpers.cmake
@@ -408,3 +408,68 @@ function(__qt_internal_apply_plugin_imports_finalizer_mode target)
set_target_properties(${target} PROPERTIES _qt_plugin_finalizer_imports_processed TRUE)
endfunction()
+
+# Include CMake plugin packages that belong to the Qt module ${target} and initialize automatic
+# linkage of the plugins in static builds.
+function(__qt_internal_include_plugin_packages target)
+ set(_module_target "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
+ set(_qt_plugins "")
+
+ # Properties can't be set on aliased targets, so make sure to unalias the target. This is needed
+ # when Qt examples are built as part of the Qt build itself.
+ get_target_property(_aliased_target ${_module_target} ALIASED_TARGET)
+ if(_aliased_target)
+ set(_module_target ${_aliased_target})
+ endif()
+
+ # Include all PluginConfig.cmake files and update the _qt_plugins and QT_PLUGINS property of
+ # the module. The underscored version is the one we will use going forward to have compatibility
+ # with INTERFACE libraries. QT_PLUGINS is now deprecated and only kept so that we don't break
+ # existing projects using it (like CMake itself).
+ file(GLOB _qt_plugin_config_files
+ "${CMAKE_CURRENT_LIST_DIR}/${QT_CMAKE_EXPORT_NAMESPACE}*PluginConfig.cmake")
+ foreach(_config_file ${_qt_plugin_config_files})
+ string(REGEX REPLACE
+ "^.*/${QT_CMAKE_EXPORT_NAMESPACE}(.*Plugin)Config.cmake$"
+ "\\1"
+ _qt_plugin "${_config_file}")
+ include("${_config_file}")
+ if(TARGET "${QT_CMAKE_EXPORT_NAMESPACE}::${_qt_plugin}")
+ list(APPEND _qt_plugins ${_qt_plugin})
+ endif()
+ endforeach()
+ set_property(TARGET ${_module_target} PROPERTY _qt_plugins ${_qt_plugins})
+
+ # TODO: Deprecated. Remove in Qt 7.
+ set_property(TARGET ${_module_target} PROPERTY QT_PLUGINS ${_qt_plugins})
+
+ get_target_property(_have_added_plugins_already ${_module_target} __qt_internal_plugins_added)
+ if(_have_added_plugins_already)
+ return()
+ endif()
+
+ foreach(plugin_target ${_qt_plugins})
+ __qt_internal_plugin_get_plugin_type("${plugin_target}" __has_plugin_type __plugin_type)
+ if(NOT __has_plugin_type)
+ continue()
+ endif()
+
+ __qt_internal_plugin_has_class_name("${plugin_target}" __has_class_name)
+ if(NOT __has_class_name)
+ continue()
+ endif()
+
+ list(APPEND "QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}" "${plugin_target}")
+
+ __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
+ __qt_internal_add_static_plugin_import_macro(
+ "${plugin_target}" ${_module_target} "${target}")
+ endforeach()
+
+ set("QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}"
+ "${QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_${__plugin_type}}"
+ PARENT_SCOPE
+ )
+
+ set_target_properties(${_module_target} PROPERTIES __qt_internal_plugins_added TRUE)
+endfunction()