aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/Qt6QmlBuildInternals.cmake
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-10-20 11:14:52 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2021-11-16 09:02:57 +0100
commit6ec7953257ef1155aef8a0a4b8379205ee850283 (patch)
tree1dac0463d8500bb3a90c37095a09890607423ec7 /src/qml/Qt6QmlBuildInternals.cmake
parent88dfbe0deaa780f1cb5793d644341367d02e3073 (diff)
qmltc: support user-specified namespaces in the generated code
Already during the prototyping phase, conflicts in class names were encountered within Qt code base. Those could be avoided by namespaces. Initial qmltc logic was using meaningless "q_qmltc" namespace, so let's improve that by allowing user-specified namespaces + making Qt's own QML files (compiled to C++) being available under QT_NAMESPACE. The latter is achieved by providing (and using) the internal version of a qmltc-invoking function Task-number: QTBUG-84368 Task-number: QTBUG-96040 Change-Id: I99cdf1baba8838c093b6b469f6744869f72af093 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/Qt6QmlBuildInternals.cmake')
-rw-r--r--src/qml/Qt6QmlBuildInternals.cmake52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/qml/Qt6QmlBuildInternals.cmake b/src/qml/Qt6QmlBuildInternals.cmake
index ee535d51c9..788f950c9a 100644
--- a/src/qml/Qt6QmlBuildInternals.cmake
+++ b/src/qml/Qt6QmlBuildInternals.cmake
@@ -426,3 +426,55 @@ function(qt_internal_add_qml_module target)
endif()
endif()
endfunction()
+
+# This function is an internal wrapper around qt6_target_compile_qml_to_cpp().
+# It sets up some pre-defined Qt-specific arguments when calling the
+# qt6_target_compile_qml_to_cpp(). All keywords supported by
+# qt6_target_compile_qml_to_cpp() can be used.
+#
+# Unlike the public command version, the following changes are present:
+# - NAMESPACE argument is set to QT_NAMESPACE by default
+#
+# See qt6_target_compile_qml_to_cpp() for the full set of supported keywords.
+function(qt_internal_target_compile_qml_to_cpp target)
+ set(option_args "")
+ set(single_args NAMESPACE)
+ set(multi_args FILES)
+ qt_parse_all_arguments(arg "qt_internal_target_compile_qml_to_cpp"
+ "${option_args}"
+ "${single_args}"
+ "${multi_args}"
+ ${ARGN}
+ )
+
+ # internal-only logic:
+ if(NOT arg_NAMESPACE)
+ # NB: assume Qt Core is present. we're in an internal function, so it's
+ # a safe enough assumption
+
+ # Apparently, -DQT_NAMESPACE only exists within qtbase or qt5's
+ # top-level build. Thus, in many other cases that option is unspecified.
+ # To avoid dealing with this, we can query the QT_NAMESPACE for QtCore's
+ # compile definitions (because we have it there).
+ get_target_property(arg_NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE}::Core _qt_namespace)
+ endif()
+
+ set(target_compile_qml_to_cpp_args "")
+ # Pass through options if given (these are present/absent, not true/false)
+ foreach(opt IN LISTS option_args)
+ if(arg_${opt})
+ list(APPEND target_compile_qml_to_cpp_args ${opt})
+ endif()
+ endforeach()
+ # Pass through single and multi-value args as provided.
+ foreach(arg IN LISTS single_args multi_args)
+ if(DEFINED arg_${arg})
+ list(APPEND target_compile_qml_to_cpp_args ${arg} ${arg_${arg}})
+ endif()
+ endforeach()
+
+ qt6_target_compile_qml_to_cpp(${target}
+ ${target_compile_qml_to_cpp_args}
+ )
+
+endfunction()