summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-07-19 18:47:52 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2022-07-25 19:52:54 +0200
commit4720735103f0a1076873de1d77089747bc2192ad (patch)
tree3823a88acd17654641484445edc0a2d756ed2954
parent63db26a47ec49699026a4b8f0e128ecdad2570e4 (diff)
CMake: Change __qt_internal_include_plugin_packages to be a macro
The __qt_internal_include_plugin_packages function includes PluginConfig.cmake files which in turn might look for dependencies with find_dependency. The dependencies that were found not have their _FOUND variables set in the calling scope, which could cause multiple lookups of the same dependency packages. Change the function to be macro, so that all relevant _FOUND variables are set and no unnecessary package lookups are done. As a result, no need to set the QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE variable using set(PARENT_SCOPE) Pick-to: 6.4 Task-number: QTBUG-104998 Change-Id: Iba0fc83d9e58651f095e7b70d1ed19f064c4e577 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
-rw-r--r--cmake/QtPublicPluginHelpers.cmake53
1 files changed, 28 insertions, 25 deletions
diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake
index e0f1277762..7bec5fd627 100644
--- a/cmake/QtPublicPluginHelpers.cmake
+++ b/cmake/QtPublicPluginHelpers.cmake
@@ -416,44 +416,50 @@ 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 "")
+# The variables inside the macro have to be named unique to the module because an included Plugin
+# file might look up another module dependency that calls the same macro before the first one
+# has finished processing, which can silently override the values if the variables are not unique.
+macro(__qt_internal_include_plugin_packages target)
+ set(__qt_${target}_plugin_module_target "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
+ set(__qt_${target}_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)
+ get_target_property(_aliased_target ${__qt_${target}_plugin_module_target} ALIASED_TARGET)
if(_aliased_target)
- set(_module_target ${_aliased_target})
+ set(__qt_${target}_plugin_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
+ file(GLOB __qt_${target}_plugin_config_files
"${CMAKE_CURRENT_LIST_DIR}/${QT_CMAKE_EXPORT_NAMESPACE}*PluginConfig.cmake")
- foreach(_config_file ${_qt_plugin_config_files})
+ foreach(__qt_${target}_plugin_config_file ${__qt_${target}_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})
+ __qt_${target}_qt_plugin "${__qt_${target}_plugin_config_file}")
+ include("${__qt_${target}_plugin_config_file}")
+ if(TARGET "${QT_CMAKE_EXPORT_NAMESPACE}::${__qt_${target}_qt_plugin}")
+ list(APPEND __qt_${target}_plugins ${__qt_${target}_qt_plugin})
endif()
endforeach()
- set_property(TARGET ${_module_target} PROPERTY _qt_plugins ${_qt_plugins})
+ set_property(TARGET ${__qt_${target}_plugin_module_target}
+ PROPERTY _qt_plugins ${__qt_${target}_plugins})
# TODO: Deprecated. Remove in Qt 7.
- set_property(TARGET ${_module_target} PROPERTY QT_PLUGINS ${_qt_plugins})
+ set_property(TARGET ${__qt_${target}_plugin_module_target}
+ PROPERTY QT_PLUGINS ${__qt_${target}_plugins})
- get_target_property(_have_added_plugins_already ${_module_target} __qt_internal_plugins_added)
- if(_have_added_plugins_already)
+ get_target_property(__qt_${target}_have_added_plugins_already
+ ${__qt_${target}_plugin_module_target} __qt_internal_plugins_added)
+ if(__qt_${target}_have_added_plugins_already)
return()
endif()
- foreach(plugin_target ${_qt_plugins})
+ foreach(plugin_target ${__qt_${target}_plugins})
__qt_internal_plugin_get_plugin_type("${plugin_target}" __has_plugin_type __plugin_type)
if(NOT __has_plugin_type)
continue()
@@ -470,16 +476,13 @@ function(__qt_internal_include_plugin_packages target)
set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
get_target_property(type "${plugin_target_versioned}" TYPE)
if(type STREQUAL STATIC_LIBRARY)
- __qt_internal_add_static_plugin_linkage("${plugin_target}" "${_module_target}")
+ __qt_internal_add_static_plugin_linkage(
+ "${plugin_target}" "${__qt_${target}_plugin_module_target}")
__qt_internal_add_static_plugin_import_macro(
- "${plugin_target}" ${_module_target} "${target}")
+ "${plugin_target}" ${__qt_${target}_plugin_module_target} "${target}")
endif()
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()
+ set_target_properties(
+ ${__qt_${target}_plugin_module_target} PROPERTIES __qt_internal_plugins_added TRUE)
+endmacro()