summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-06-11 17:02:45 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-17 19:13:07 +0000
commit9dd2541bebdbbc4bcbac983d79700fb77aa89e8c (patch)
tree28b92acbd0bed694d948a6d08a380eb62eadb4e6 /cmake
parentf2c3e1a3fc986c5e78565a5fed6b519342499029 (diff)
CMake: Set the plugin class name for qml plugins
This is needed for a change in qtdeclarative to allow building the Q_IMPORT_PLUGIN-containing object library initializer of a qml plugin. Show an error if the qml plugin has no class name, it's needed for plugin initialization so it's mandatory to have a class name. Show an error if a class name is not found when computing the import macro for a plugin (both for a regular qt plugin and a qml plugin). When querying for the class name of a target, query both a Qt6:: prefixed target as well as a non-prefixed one, with the Qt one taking precedence. This is to allow querying the class name of user project created qml plugins. Currently regular qt user plugins don't use the object library initializer approach. This will likely be revisited in the future. Task-number: QTBUG-92933 Change-Id: I46417471a7d8b49651e6821f7b28e7a9d44c2557 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit 602d26c38f3767be9bec25302c93fc155c4dce59) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPublicPluginHelpers.cmake26
1 files changed, 24 insertions, 2 deletions
diff --git a/cmake/QtPublicPluginHelpers.cmake b/cmake/QtPublicPluginHelpers.cmake
index 0c4eebec0b..8c98852c49 100644
--- a/cmake/QtPublicPluginHelpers.cmake
+++ b/cmake/QtPublicPluginHelpers.cmake
@@ -150,8 +150,30 @@ endfunction()
# Generates C++ import macro source code for given plugin
function(__qt_internal_get_plugin_import_macro plugin_target out_var)
- set(plugin_target_versioned "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
- get_target_property(class_name "${plugin_target_versioned}" QT_PLUGIN_CLASS_NAME)
+ set(plugin_target_prefixed "${QT_CMAKE_EXPORT_NAMESPACE}::${plugin_target}")
+
+ # Query the class name of plugin targets prefixed with a Qt namespace and without, this is
+ # needed to support plugin object initializers created by user projects.
+ set(class_name"")
+ set(class_name_prefixed "")
+
+ if(TARGET ${plugin_target})
+ get_target_property(class_name "${plugin_target}" QT_PLUGIN_CLASS_NAME)
+ endif()
+
+ if(TARGET ${plugin_target_prefixed})
+ get_target_property(class_name_prefixed "${plugin_target_prefixed}" QT_PLUGIN_CLASS_NAME)
+ endif()
+
+ if(NOT class_name AND NOT class_name_prefixed)
+ message(FATAL_ERROR "No QT_PLUGIN_CLASS_NAME value on target: '${plugin_target}'")
+ endif()
+
+ # Qt prefixed target takes priority.
+ if(class_name_prefixed)
+ set(class_name "${class_name_prefixed}")
+ endif()
+
set(${out_var} "Q_IMPORT_PLUGIN(${class_name})" PARENT_SCOPE)
endfunction()