aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/CMakeLists.txt
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-11-08 14:20:17 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-11-24 04:26:56 +0100
commita021bd427328c495cf9969be820a3cfbd41996c6 (patch)
tree89c7a0a3c5121f62dce1dd661fa8196eb0f545a1 /src/qml/CMakeLists.txt
parentb54f42c41eee9edc4e4b734822a882f5e703c215 (diff)
Make builtins an actual module
This way we can eventually use the metatypes generated by the builtins to validate other module using qmltyperegistrar, and throw informed warnings if types are missing. qmltyperegistrar automatically picks up the metatypes of any library linked into a target. This means it always picks up the builtins metatypes now when QtQml is linked in. We now have to check more closely whether an object binding is actually a group property. QVariant now has a value type metaobject and does not pass as "unknown thing" anymore. We also have to move the QML_FOREIGN macros to QQmlIntegration since we want QML_FOREIGN to declare the builtins but we don't want to depend on QtQml. Task-number: QTBUG-101143 Change-Id: I9f1a2713797291b6624aef0ade599d19e0766907 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Diffstat (limited to 'src/qml/CMakeLists.txt')
-rw-r--r--src/qml/CMakeLists.txt91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt
index 531fb95701..54aa328fb1 100644
--- a/src/qml/CMakeLists.txt
+++ b/src/qml/CMakeLists.txt
@@ -31,6 +31,49 @@ if(ANDROID)
"${INSTALL_CMAKE_NAMESPACE}AndroidQmlMacros.cmake")
endif()
+set_source_files_properties(
+ qml/qqmlcomponent.h qml/qqmlcomponent.cpp qml/qqmlcomponent_p.h
+ qml/qqmlcomponentattached_p.h
+ PROPERTIES
+ SKIP_AUTOMOC TRUE
+)
+
+# We want QQmlComponent and QQmlComponentAttached to be available as metatypes in the builtins,
+# but without depending on QtQml and without duplicating the metaobjects.
+qt_manual_moc(qqmlcomponent_moc_files
+ OUTPUT_MOC_JSON_FILES qqmlcomponent_json_list
+ qml/qqmlcomponent.h
+ qml/qqmlcomponentattached_p.h
+ INCLUDE_DIRECTORY_TARGETS Qt::Qml
+)
+
+# The moc files are included directly by qqmlcomponent.cpp
+set_source_files_properties(${qqmlcomponent_moc_files} PROPERTIES HEADER_FILE_ONLY ON)
+
+qt_internal_add_module(QmlBuiltins
+ STATIC
+ NO_GENERATE_METATYPES # we do that manually below
+ SOURCES
+ qqmlbuiltins_p.h
+)
+
+add_custom_target(QQmlComponentJson DEPENDS ${qqmlcomponent_json_list})
+add_custom_target(QQmlComponentMocs DEPENDS ${qqmlcomponent_moc_files})
+
+target_link_libraries(QmlBuiltins PRIVATE Qt::Core Qt::QmlIntegration)
+
+# We generally need to copy the files into the build directory,
+# so that they are located together with the QML modules
+qt_path_join(qml_build_dir "${QT_BUILD_DIR}" "${INSTALL_QMLDIR}")
+
+# Simulate conditions that qt6_add_qml_module() would normally set up for us
+set_target_properties(QmlBuiltins PROPERTIES
+ QT_QML_MODULE_VERSION 1.0
+ QT_QML_MODULE_URI QML
+ QT_QML_MODULE_TYPEINFO builtins.qmltypes
+ QT_QML_MODULE_OUTPUT_DIRECTORY ${qml_build_dir}
+)
+
qt_internal_add_qml_module(Qml
URI "QtQml.Base"
VERSION "${PROJECT_VERSION}"
@@ -412,6 +455,7 @@ qt_internal_add_qml_module(Qml
${CMAKE_CURRENT_BINARY_DIR}/compiler
${CMAKE_CURRENT_BINARY_DIR}/jsruntime
${CMAKE_CURRENT_BINARY_DIR}/memory
+ ${CMAKE_CURRENT_BINARY_DIR}/qml
${CMAKE_CURRENT_BINARY_DIR}/qmldirparser
../3rdparty/masm
../3rdparty/masm/assembler
@@ -427,6 +471,7 @@ qt_internal_add_qml_module(Qml
debugger
jsruntime
memory
+ qml
qmldirparser
LIBRARIES
Qt::CorePrivate
@@ -434,8 +479,10 @@ qt_internal_add_qml_module(Qml
PUBLIC_LIBRARIES
Qt::Core
Qt::QmlIntegration
+ Qt::QmlBuiltins
PRIVATE_MODULE_INTERFACE
Qt::CorePrivate
+ Qt::QmlBuiltinsPrivate
EXTRA_CMAKE_FILES
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}qmldirTemplate.cmake.in"
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlPluginTemplate.cpp.in"
@@ -453,12 +500,52 @@ qt_internal_add_qml_module(Qml
QTP0001
)
+target_include_directories(QmlBuiltins PRIVATE
+ $<TARGET_PROPERTY:${QT_CMAKE_EXPORT_NAMESPACE}::QmlPrivate,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+set(builtins_typeregistration_args
+ MANUAL_MOC_JSON_FILES ${qqmlcomponent_json_list}
+ REGISTRATIONS_TARGET Qml
+)
+
+get_target_property(qt_namespace ${QT_CMAKE_EXPORT_NAMESPACE}::Core _qt_namespace)
+if(qt_namespace)
+ list(APPEND builtins_typeregistration_args NAMESPACE ${qt_namespace})
+endif()
+
+_qt_internal_qml_type_registration(QmlBuiltins ${builtins_typeregistration_args})
+add_dependencies(QmlBuiltins QQmlComponentJson)
+
+add_custom_command(
+ OUTPUT "${qml_build_dir}/jsroot.qmltypes"
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/jsroot.qmltypes"
+ COMMAND
+ "${CMAKE_COMMAND}" -E copy_if_different
+ "${CMAKE_CURRENT_SOURCE_DIR}/jsroot.qmltypes" "${qml_build_dir}"
+)
+
+set(builtins_output_files "")
+list(APPEND builtins_output_files "${qml_build_dir}/builtins.qmltypes")
+list(APPEND builtins_output_files "${qml_build_dir}/jsroot.qmltypes")
+
+add_custom_target(BuiltinsOutput DEPENDS ${builtins_output_files})
+
+qt_install(
+ FILES ${builtins_output_files}
+ DESTINATION "${INSTALL_QMLDIR}"
+)
+
+add_dependencies(Qml QQmlComponentMocs)
+add_dependencies(Qml BuiltinsOutput)
+
qt_update_ignore_pch_source(Qml "compat/removed_api.cpp")
set_source_files_properties(compat/removed_api.cpp
jsruntime/qv4mathobject.cpp # math.h issues on Windows
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
+
qt_internal_add_qml_module(QmlMeta
URI "QtQml"
VERSION "${PROJECT_VERSION}"
@@ -755,8 +842,10 @@ endif()
# "unknown IID" issue when moc processes plugin sources, because of missing header aliases.
# Qml_sync_headers target is created later by the finalizer in the directory scope so we add this
# dependency manually instead of relying on qt_internal_add_qml_module logic. Same is applicable
-# for QmlMeta target.
+# for the QmlMeta and the QmlBuiltins target.
set_property(TARGET qmlplugin APPEND PROPERTY AUTOGEN_TARGET_DEPENDS
Qml_sync_headers)
set_property(TARGET QmlMeta APPEND PROPERTY AUTOGEN_TARGET_DEPENDS
Qml_sync_headers)
+set_property(TARGET QmlBuiltins APPEND PROPERTY AUTOGEN_TARGET_DEPENDS
+ Qml_sync_headers)