aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-06-27 14:51:08 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-06-29 09:31:50 +0000
commit6043b1944b5ad84b50b1bbee7f868b8b77df4f92 (patch)
tree7f4fe2c2423630ef8378f99ff4bfe3483dfba1f5
parent01ed8d8cdfc8150c3fcfbdb2a23aaebf309696a7 (diff)
Create a qrc mapping between build and source dir QML files
QML tooling needs it in various places already As of now, support the mapping only for QML modules (created via qt6_add_qml_module) and enable it only if someone enables qmltc Task-number: QTBUG-95151 Task-number: QTBUG-104094 Change-Id: I86d2351456b5b5b5fa88e16b35d51de493de58fd Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> (cherry picked from commit 7f567e6a424a3919337aad498543d58c1252df62) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/CMakeLists.txt1
-rw-r--r--src/qml/Qt6QmlMacros.cmake39
-rw-r--r--src/qml/Qt6QmlModuleDirMappingTemplate.qrc.in5
3 files changed, 45 insertions, 0 deletions
diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt
index 22647f680c..cefb82f2d8 100644
--- a/src/qml/CMakeLists.txt
+++ b/src/qml/CMakeLists.txt
@@ -404,6 +404,7 @@ qt_internal_add_qml_module(Qml
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlPluginTemplate.cpp.in"
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlFindQmlscInternal.cmake"
"${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlDeploySupport.cmake"
+ "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}QmlModuleDirMappingTemplate.qrc.in"
${extra_cmake_files}
EXTRA_CMAKE_INCLUDES
"${INSTALL_CMAKE_NAMESPACE}QmlFindQmlscInternal.cmake"
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 23202900fe..8b42d176e0 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -599,6 +599,14 @@ function(qt6_add_qml_module target)
target_sources(${target} PRIVATE ${arg_SOURCES})
+ # QML tooling might need to map build dir paths to source dir paths. Create
+ # a mapping file before qt6_target_qml_sources() to be able to use it
+ if(arg_ENABLE_TYPE_COMPILER)
+ # But: for now, only enable this when dealing with qmltc
+ _qt_internal_qml_map_build_files(${target} "${arg_QML_FILES}" dir_map_qrc)
+ set_property(TARGET ${target} APPEND PROPERTY _qt_generated_qrc_files "${dir_map_qrc}")
+ endif()
+
set(cache_target)
qt6_target_qml_sources(${target}
__QT_INTERNAL_FORCE_DEFER_QMLDIR
@@ -1110,6 +1118,37 @@ function(_qt_internal_qml_get_qt_framework_path_moc_option target out_var)
endif()
endfunction()
+# creates a QRC mapping between QML files in build directory and QML files in
+# source directory
+function(_qt_internal_qml_map_build_files target qml_files qrc_file_out_var)
+ get_target_property(output_dir ${target} QT_QML_MODULE_OUTPUT_DIRECTORY)
+ if(NOT output_dir)
+ # TODO: we might want to support non-qml modules here (think QML
+ # language server) but it is unclear whether the below code would
+ # succeed, so just abort here until we have a proper test case
+ message(WARNING "Target ${target} is not a QML module. Cannot detect its output directory")
+ return()
+ endif()
+
+ set(qrcContents "")
+
+ foreach(qml_file IN LISTS qml_files)
+ get_filename_component(src_dir_path ${qml_file} ABSOLUTE)
+ # Note: follow the logic of cloning the QML file over to build dir
+ __qt_get_relative_resource_path_for_file(file_resource_path ${qml_file})
+ set(build_dir_path "${output_dir}/${file_resource_path}")
+ string(APPEND qrcContents " <file alias=\"${src_dir_path}\">${build_dir_path}</file>\n")
+ endforeach()
+
+ # dump the contents into the .qrc file
+ set(template_file "${__qt_qml_macros_module_base_dir}/Qt6QmlModuleDirMappingTemplate.qrc.in")
+ set(generated_qrc_file "${output_dir}/${target}_qml_module_dir_map.qrc")
+ set(qt_qml_module_dir_mapping_contents "${qrcContents}")
+ configure_file(${template_file} ${generated_qrc_file})
+
+ set(${qrc_file_out_var} ${generated_qrc_file} PARENT_SCOPE)
+endfunction()
+
# Compile Qml files (.qml) to C++ source files with Qml Type Compiler (qmltc).
function(_qt_internal_target_enable_qmltc target)
set(args_option "")
diff --git a/src/qml/Qt6QmlModuleDirMappingTemplate.qrc.in b/src/qml/Qt6QmlModuleDirMappingTemplate.qrc.in
new file mode 100644
index 0000000000..3cbe0acea0
--- /dev/null
+++ b/src/qml/Qt6QmlModuleDirMappingTemplate.qrc.in
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/qt_qml_module_dir_mapping/">
+@qt_qml_module_dir_mapping_contents@
+ </qresource>
+</RCC>