diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-17 15:42:05 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-06-24 18:26:14 +0200 |
commit | 36df81b3bc6d721d5598d5163b0a9659de4a69ee (patch) | |
tree | d9032e08f4d27daa9e4b16a2c2e622ed2fa6951b /src/qml/Qt6QmlMacros.cmake | |
parent | 6de0287d7c3aa4251fe6eb4f970d73ce11cf07fc (diff) |
Discern between "auto" and versioned imports in qmldirs
You can now import the latest version, a specific version, or, "auto"
which is the same version as the parent module.
[ChangeLog][QtQml] You can now procedurally add module imports to
modules, using qmlRegisterModuleImport(). However, actual import
statements in qmldir files should be preferred wherever possible.
Fixes: QTBUG-84899
Change-Id: I3b32dd8b07a19d31b6538b9a6bb436840862f345
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/Qt6QmlMacros.cmake')
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index d04d663656..4405db694a 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -57,7 +57,11 @@ # that can be read by QML tools such as Qt Creator to access information about # the types defined by the module's plugins. (OPTIONAL) # -# IMPORTS: List of other Qml Modules that this module imports. (OPTIONAL) +# IMPORTS: List of other Qml Modules that this module imports. A version can be +# specified by appending it after a slash(/), e.g QtQuick/2.0. The minor +# version may be omitted, e.g. QtQuick/2. Alternatively "auto" may be given +# as version to forward the version the current module is being imported with, +# e.g. QtQuick/auto. (OPTIONAL) # # RESOURCE_EXPORT: In static builds, when Qml files are processed via the Qt # Quick Compiler generate a separate static library that will be linked in @@ -254,7 +258,21 @@ function(qt6_add_qml_module target) string(APPEND qmldir_file_contents "typeinfo plugins.qmltypes\n") endif() foreach(import IN LISTS arg_IMPORTS) - string(APPEND qmldir_file_contents "import ${import}\n") + string(FIND ${import} "/" slash_position REVERSE) + if (slash_position EQUAL -1) + string(APPEND qmldir_file_contents "import ${import}\n") + else() + string(SUBSTRING ${import} 0 ${slash_position} import_module) + math(EXPR slash_position "${slash_position} + 1") + string(SUBSTRING ${import} ${slash_position} -1 import_version) + if (import_version MATCHES "[0-9]+\\.[0-9]+" OR import_version MATCHES "[0-9]+") + string(APPEND qmldir_file_contents "import ${import_module} ${import_version}\n") + elseif (import_version MATCHES "auto") + string(APPEND qmldir_file_contents "import ${import_module} auto\n") + else() + message(FATAL_ERROR "Invalid module import version number. Expected 'VersionMajor', 'VersionMajor.VersionMinor' or 'auto'.") + endif() + endif() endforeach() foreach(dependency IN LISTS arg_DEPENDENCIES) |