From 96fdbf597e581fe5e09e02758a4a2b0fe12add53 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 16 Aug 2021 15:10:38 +1000 Subject: Allow QML plugin's CMake target name to be specified for qmldir file The current code assumes that the basename of the QML plugin is the same as the CMake target it corresponds to. This won't be the case for installed Qt packages due to the installed name including a namespace. It also won't match when a Qt library infix is used. The current code works around the former by trying to heuristically work out whether a namespaced Qt target exists for the plugin. The Qt library infix is more problematic because the plugin target name won't include the infix whereas the plugin library basename will. Address both of those issues by adding an internal option INSTALLED_PLUGIN_TARGET to qt6_add_qml_module() which allows the installed target name to be provided. When included in a qmldir file, qt6_import_qml_plugin() will use that name, otherwise it will fall back to using the plugin library's basename, as per the current behavior. The option may become public in the future, but for now it is only for Qt's internal use for the 6.2 release. Conflicts: src/qml/qmldirparser/qqmldirparser_p.h Fixes: QTBUG-95140 Change-Id: I5a057c80b70ee802c0f0840e9eea2e579193d126 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale Reviewed-by: Alexandru Croitor (cherry picked from commit a25f650c317e4886007a8beb0e9f2f7e973e6e7c) Reviewed-by: Craig Scott --- tools/qmlimportscanner/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tools') diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp index d59dc4a2e1..ab26abae46 100644 --- a/tools/qmlimportscanner/main.cpp +++ b/tools/qmlimportscanner/main.cpp @@ -69,6 +69,10 @@ inline QString dependenciesLiteral() { return QStringLiteral("dependencies"); } inline QString moduleLiteral() { return QStringLiteral("module"); } inline QString javascriptLiteral() { return QStringLiteral("javascript"); } inline QString directoryLiteral() { return QStringLiteral("directory"); } +inline QString linkTargetLiteral() +{ + return QStringLiteral("linkTarget"); +} void printUsage(const QString &appNameIn) { @@ -193,6 +197,10 @@ QVariantMap pluginsForModulePath(const QString &modulePath, const QString &versi pluginInfo[pluginIsOptionalLiteral()] = true; } + if (!parser.linkTarget().isEmpty()) { + pluginInfo[linkTargetLiteral()] = parser.linkTarget(); + } + pluginInfo[classnamesLiteral()] = parser.classNames().join(QLatin1Char(' ')); QStringList importsAndDependencies; @@ -310,9 +318,12 @@ QVariantList findPathsForModuleImports(const QVariantList &imports) import.insert(relativePathLiteral(), paths.second); plugininfo = pluginsForModulePath(paths.first, version); } + QString linkTarget = plugininfo.value(linkTargetLiteral()).toString(); QString plugins = plugininfo.value(pluginsLiteral()).toString(); bool isOptional = plugininfo.value(pluginIsOptionalLiteral(), QVariant(false)).toBool(); QString classnames = plugininfo.value(classnamesLiteral()).toString(); + if (!linkTarget.isEmpty()) + import.insert(linkTargetLiteral(), linkTarget); if (!plugins.isEmpty()) import.insert(QStringLiteral("plugin"), plugins); if (isOptional) -- cgit v1.2.3