summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2019-12-04 11:09:33 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 12:29:30 +0000
commitcce8ada8141d786c1deda78fdba485b4c67f9687 (patch)
treee5366b6b43480f11c03c00b75b95f04b2faf1644
parent48c82e90af12da74c713665ddfd7f8d825ae5bdb (diff)
Support for QML Type Registrar
Change-Id: Ifc1f44cf40b22c20ab768333ba9d5ce58a5f7250 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--cmake/QtBuild.cmake78
-rwxr-xr-xutil/cmake/pro2cmake.py37
2 files changed, 43 insertions, 72 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake
index f79352d725..0b434045b6 100644
--- a/cmake/QtBuild.cmake
+++ b/cmake/QtBuild.cmake
@@ -2349,75 +2349,6 @@ function(qt_add_plugin target)
qt_internal_add_linker_version_script(${target})
endfunction()
-# Generate custom ${target}_qmltypes target for Qml Plugins
-function(qt_add_qmltypes_target target)
-
- # Do nothing when cross compiling
- if (CMAKE_CROSSCOMPILING)
- return()
- endif()
-
- # Do nothing during a Qt static build (because the tool isn't built in that case).
- if (NOT QT_BUILD_SHARED_LIBS)
- return()
- endif()
-
- qt_parse_all_arguments(arg "qt_generate_qmltypes"
- ""
- "TARGET_PATH;IMPORT_VERSION;IMPORT_NAME;QML_PLUGINDUMP_DEPENDENCIES"
- ""
- ${ARGN})
-
- # scan repos for qml repositories
- foreach(repo IN LISTS QT_REPOS)
- if (IS_DIRECTORY "${repo}/qml")
- list(APPEND import_paths "${repo}/qml")
- endif()
- endforeach()
- list(REMOVE_DUPLICATES import_paths)
- if (UNIX)
- list(JOIN import_paths ":" import_paths_env)
- else()
- list(JOIN import_paths "\;" import_paths_env)
- endif()
-
- if(NOT arg_IMPORT_NAME)
- string(REGEX REPLACE "\\.\\d+$" "" import_name ${arg_TARGET_PATH})
- else()
- set(import_name ${arg_IMPORT_NAME})
- endif()
-
- if(NOT arg_IMPORT_VERSION)
- message(FATAL_ERROR "Import version parameter was not specified. Specify the import version using the IMPORT_VERSION.")
- endif()
-
- get_target_property(source_dir ${target} SOURCE_DIR)
-
- # qml1_target check is no longer required
- set(qmltypes_command_args "-nonrelocatable")
- if (NOT arg_QML_PLUGINDUMP_DEPENDENCIES AND EXISTS "${source_dir}/dependencies.json")
- list(APPEND qmltypes_command_args "-dependencies" "${source_dir}/dependencies.json")
- elseif(arg_QML_PLUGINDUMP_DEPENDENCIES)
- list(APPEND qmltypes_command_args "-dependencies" "${arg_QML_PLUGINDUMP_DEPENDENCIES}")
- endif()
-
- string(REPLACE "/" "." import_name_arg ${import_name})
-
- list(APPEND qmltypes_command_args "${import_name_arg}" "${arg_IMPORT_VERSION}")
-
- set(qml_plugindump_target ${QT_CMAKE_EXPORT_NAMESPACE}::qmlplugindump)
-
- # Manually set dependency on plugindump target since CMake will not add
- # this rule because it's not the main executable argument to the COMMAND
- # parameter.
- add_custom_target(
- "${target}_qmltypes"
- DEPENDS ${qml_plugindump_target}
- COMMAND ${CMAKE_COMMAND} -E env "QML2_IMPORTPATH=${import_paths_env}"
- $<TARGET_FILE:${qml_plugindump_target}> ${qmltypes_command_args} > "${source_dir}/plugins.qmltypes"
- )
-endfunction()
-
function(qt_install_qml_files target)
qt_parse_all_arguments(arg "qt_install_qml_files"
@@ -2488,6 +2419,7 @@ endfunction()
function(qt_add_qml_module target)
set(qml_module_optional_args
+ GENERATE_QMLTYPES
DESIGNER_SUPPORTED
DO_NOT_INSTALL
SKIP_TYPE_REGISTRATION
@@ -2570,11 +2502,16 @@ function(qt_add_qml_module target)
set(skip_registration_arg SKIP_TYPE_REGISTRATION)
endif()
+ if (arg_GENERATE_QMLTYPES)
+ set(generate_qmltypes_arg GENERATE_QMLTYPES)
+ endif()
+
qt6_add_qml_module(${target}
${designer_supported_arg}
${no_create_option}
${skip_registration_arg}
${classname_arg}
+ ${generate_qmltypes_arg}
RESOURCE_PREFIX "/qt-project.org/imports"
TARGET_PATH ${arg_TARGET_PATH}
URI ${arg_URI}
@@ -2590,8 +2527,8 @@ function(qt_add_qml_module target)
)
get_target_property(qmldir_file ${target} QT_QML_MODULE_QMLDIR_FILE)
+ get_target_property(plugin_types ${target} QT_QML_MODULE_PLUGIN_TYPES_FILE)
qt_path_join(qml_module_install_dir ${QT_INSTALL_DIR} "${INSTALL_QMLDIR}/${arg_TARGET_PATH}")
- set(plugin_types "${CMAKE_CURRENT_SOURCE_DIR}/plugins.qmltypes")
if (EXISTS ${plugin_types})
qt_copy_or_install(FILES ${plugin_types}
DESTINATION "${qml_module_install_dir}"
@@ -2606,7 +2543,6 @@ function(qt_add_qml_module target)
endif()
endif()
-
qt_copy_or_install(
FILES
"${qmldir_file}"
diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py
index 3ad427f609..fe2a08b71f 100755
--- a/util/cmake/pro2cmake.py
+++ b/util/cmake/pro2cmake.py
@@ -2839,7 +2839,7 @@ def write_module(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
extra.append("NO_PRIVATE_MODULE")
if "header_module" in scope.get("CONFIG"):
extra.append("HEADER_MODULE")
- if "metatypes" in scope.get("CONFIG"):
+ if "metatypes" in scope.get("CONFIG") or "qmltypes" in scope.get("CONFIG"):
extra.append("GENERATE_METATYPES")
module_config = scope.get("MODULE_CONFIG")
@@ -3280,6 +3280,8 @@ def write_plugin(cm_fh, scope, *, indent: int = 0) -> str:
extra.append(f'INSTALL_DIRECTORY "{target_path}"')
else:
extra.append("SKIP_INSTALL")
+ if "qmltypes" in scope.get("CONFIG"):
+ extra.append("GENERATE_QMLTYPES")
plugin_class_name = scope.get_string("PLUGIN_CLASS_NAME")
if plugin_class_name:
@@ -3498,6 +3500,39 @@ def handle_app_or_lib(
footer=")\n",
)
+ # Generate qmltypes instruction for anything that may have CONFIG += qmltypes
+ # that is not a qml plugin
+ if "qmltypes" in scope.get("CONFIG") and not "qml_plugin" in scope.get("_LOADED"):
+ cm_fh.write(f"\n{spaces(indent)}set_target_properties({target} PROPERTIES\n")
+ cm_fh.write(f"{spaces(indent+1)}QT_QML_MODULE_INSTALL_QMLTYPES TRUE\n")
+
+ import_version = scope.get_string("IMPORT_VERSION")
+ if not import_version:
+ import_version = scope.get_string("QML_IMPORT_VERSION")
+ if import_version:
+ import_version = import_version.replace(
+ "$$QT_MINOR_VERSION", "${CMAKE_PROJECT_VERSION_MINOR}"
+ )
+ cm_fh.write(f"{spaces(indent+1)}QT_QML_MODULE_VERSION {import_version}\n")
+
+ import_name = scope.expandString("QML_IMPORT_NAME")
+ if import_name:
+ cm_fh.write(f"{spaces(indent+1)}QT_QML_MODULE_URI {import_name}\n")
+
+ target_path = scope.get("TARGETPATH")
+ if target_path:
+ cm_fh.write(f"{spaces(indent+1)}QT_QML_MODULE_TARGET_PATH {target_path}\n")
+
+ install_dir = scope.expandString("QMLTYPES_INSTALL_DIR")
+ if install_dir:
+ install_dir = install_dir.replace(
+ "$$[QT_INSTALL_QML]","${Qt6_DIR}/../../../qml"
+ )
+ cm_fh.write(f"{spaces(indent+1)}QT_QML_MODULE_INSTALL_DIR \"{install_dir}\"\n")
+
+ cm_fh.write(f"{spaces(indent)})\n\n")
+ cm_fh.write(f"qt6_qml_type_registration({target})\n")
+
def handle_top_level_repo_project(scope: Scope, cm_fh: IO[str]):
# qtdeclarative