aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-11-04 15:19:03 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2020-11-10 18:14:48 +0100
commita4d956048b4679bf5b448340d1f3428793699990 (patch)
treefd382c2b6cadb813ac1939bf8a6149beecb60b2e /src
parentd01ec7ebe3853faabc8843d169d288b4998bb209 (diff)
qmltyperegistrar: Add past-major-version option
Adds the option to specify past major versions of modules to be registered. This is necessary for modules that don't export any types themselves to work when built statically. Change-Id: I4b4a379f92707ec64cbb32f91db9d010440b95a2 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/Qt6QmlBuildInternals.cmake2
-rw-r--r--src/qml/Qt6QmlMacros.cmake20
-rw-r--r--src/qmltyperegistrar/qmltyperegistrar.cpp12
-rw-r--r--src/qmltyperegistrar/qmltypes.prf4
4 files changed, 38 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlBuildInternals.cmake b/src/qml/Qt6QmlBuildInternals.cmake
index a9b20235ad..d25c987fc9 100644
--- a/src/qml/Qt6QmlBuildInternals.cmake
+++ b/src/qml/Qt6QmlBuildInternals.cmake
@@ -42,6 +42,7 @@ function(qt_internal_add_qml_module target)
OPTIONAL_IMPORTS
TYPEINFO
DEPENDENCIES
+ PAST_MAJOR_VERSIONS
)
qt_parse_all_arguments(arg "qt_add_qml_module"
@@ -143,6 +144,7 @@ function(qt_internal_add_qml_module target)
TARGET_PATH ${arg_TARGET_PATH}
URI ${arg_URI}
VERSION ${arg_VERSION}
+ PAST_MAJOR_VERSIONS ${arg_PAST_MAJOR_VERSIONS}
QML_FILES ${arg_QML_FILES}
IMPORTS "${arg_IMPORTS}"
OPTIONAL_IMPORTS "${arg_OPTIONAL_IMPORTS}"
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index c6b11d5ba1..51fe4cac14 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -41,6 +41,9 @@
# DEPENDENCIES: List of QML Module dependencies and their versions. The module
# and its version must be separated via a slash(/). E.g. QtQuick/2.0
#
+# PAST_MAJOR_VERSIONS: List of past major versions this QML module was available
+# in. Ensures that the module can be imported when using these major versions.
+#
# QML_FILES: List of Qml files. See qt6_target_qml_files for more information
# on how to specify additional properties on qml files. (OPTIONAL)
#
@@ -117,6 +120,7 @@ function(qt6_add_qml_module target)
IMPORTS
OPTIONAL_IMPORTS
DEPENDENCIES
+ PAST_MAJOR_VERSIONS
)
cmake_parse_arguments(arg
@@ -439,6 +443,10 @@ function(qt6_add_qml_module target)
endif()
endif()
+ if (arg_PAST_MAJOR_VERSIONS)
+ set_target_properties(${target} PROPERTIES QT_QML_PAST_MAJOR_VERSIONS "${arg_PAST_MAJOR_VERSIONS}")
+ endif()
+
# Generate meta types data
if (arg_GENERATE_QMLTYPES)
qt6_qml_type_registration(${target})
@@ -664,6 +672,18 @@ function(qt6_qml_type_registration target)
--minor-version=${minor_version}
)
+ # Add past minor versions
+ get_target_property(past_major_versions ${target} QT_QML_PAST_MAJOR_VERSIONS)
+
+ if (past_major_versions OR past_major_versions STREQUAL "0")
+ foreach (past_major_version ${past_major_versions})
+ list(APPEND cmd_args
+ --past-major-version ${past_major_version}
+ )
+ endforeach()
+ endif()
+
+
# Run a script to recursively evaluate all the metatypes.json files in order
# to collect all foreign types.
string(TOLOWER "${target}_qmltyperegistrations.cpp" type_registration_cpp_file_name)
diff --git a/src/qmltyperegistrar/qmltyperegistrar.cpp b/src/qmltyperegistrar/qmltyperegistrar.cpp
index bf3c4c94d4..07d7955727 100644
--- a/src/qmltyperegistrar/qmltyperegistrar.cpp
+++ b/src/qmltyperegistrar/qmltyperegistrar.cpp
@@ -106,6 +106,12 @@ int main(int argc, char **argv)
importNameOption.setValueName(QStringLiteral("module name"));
parser.addOption(importNameOption);
+ QCommandLineOption pastMajorVersionOption(QStringLiteral("past-major-version"));
+ pastMajorVersionOption.setDescription(QStringLiteral("Past major version to use for type and module "
+ "registrations."));
+ pastMajorVersionOption.setValueName(QStringLiteral("past major version"));
+ parser.addOption(pastMajorVersionOption);
+
QCommandLineOption majorVersionOption(QStringLiteral("major-version"));
majorVersionOption.setDescription(QStringLiteral("Major version to use for type and module "
"registrations."));
@@ -188,8 +194,14 @@ int main(int argc, char **argv)
fprintf(output, "void %s()\n{", qPrintable(functionName));
const auto majorVersion = parser.value(majorVersionOption);
+ const auto pastMajorVersions = parser.values(pastMajorVersionOption);
const auto minorVersion = parser.value(minorVersionOption);
+ for (const auto &version : pastMajorVersions) {
+ fprintf(output, "\n qmlRegisterModule(\"%s\", %s, 0);\n qmlRegisterModule(\"%s\", %s, 254);",
+ qPrintable(module), qPrintable(version), qPrintable(module), qPrintable(version));
+ }
+
if (minorVersion.toInt() != 0) {
fprintf(output, "\n qmlRegisterModule(\"%s\", %s, 0);",
qPrintable(module), qPrintable(majorVersion));
diff --git a/src/qmltyperegistrar/qmltypes.prf b/src/qmltyperegistrar/qmltypes.prf
index e02d425f2a..0b857ad099 100644
--- a/src/qmltyperegistrar/qmltypes.prf
+++ b/src/qmltyperegistrar/qmltypes.prf
@@ -63,6 +63,10 @@ QML_TYPEREGISTRAR_FLAGS = \
--minor-version=$$QML_IMPORT_MINOR_VERSION \
--foreign-types=$$join(QML_FOREIGN_METATYPES, ',')
+!isEmpty(QML_PAST_MAJOR_VERSIONS) {
+ for(past_major_version,QML_PAST_MAJOR_VERSIONS): QML_TYPEREGISTRAR_FLAGS += --past-major-version $$past_major_version
+}
+
!isEmpty(MODULE_PRIVATE_INCLUDES): QML_TYPEREGISTRAR_FLAGS += --private-includes
METATYPES_JSON = $${TARGET_BASENAME}_metatypes.json