From 1c4ba17015fe99da48ce73fab75ecc60cf9cb975 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 2 Jun 2021 16:54:21 +1000 Subject: Refactor and update qml CMake API The existing CMake API for qml modules had a number of shortcomings. Refactor it to achieve the following: - Clearly separate public and internal aspects. - Re-use code from qtbase for adding plugins and module targets rather than reimplementing close variations. - Provide more robust and complete support for qmllint, qmlcachegen and automatic generation of qmldir files. - Reduce the steps needed for more common scenarios. - Encourage the use of separate backing library and plugin targets. - Automatically generate the plugin class .cpp file where possible. - Specify .qml files directly through qml-specific API elements rather than assuming they can be extracted out of a set of resources. [ChangeLog][QtQml] The qml CMake API has changed from 6.1 and is now out of Technical Preview status. The most notable change is that .qml files should no longer be specified as resources, there is dedicated handling for them in the qt6_add_qml_module(). A related change is that the qt6_target_qml_files() command has been replaced by qt6_target_qml_sources(). More complete integration with qmlcachegen, qmllint and qmldir generation is also part of the CMake API. Fixes: QTBUG-91621 Task-number: QTBUG-82598 Task-number: QTBUG-88763 Task-number: QTBUG-89274 Task-number: QTBUG-91444 Change-Id: I25aae1b0e89890394dfe2ba2824008164b2ca8d9 Reviewed-by: Qt CI Bot Reviewed-by: Ulf Hermann --- examples/qml/qmlextensionplugins/CMakeLists.txt | 39 +++++++++++----------- .../chapter6-plugins/import/CMakeLists.txt | 10 +----- 2 files changed, 21 insertions(+), 28 deletions(-) (limited to 'examples/qml') diff --git a/examples/qml/qmlextensionplugins/CMakeLists.txt b/examples/qml/qmlextensionplugins/CMakeLists.txt index 7fc2b7268f..dcfde4a8ae 100644 --- a/examples/qml/qmlextensionplugins/CMakeLists.txt +++ b/examples/qml/qmlextensionplugins/CMakeLists.txt @@ -1,7 +1,7 @@ # Generated from qmlextensionplugins.pro. cmake_minimum_required(VERSION 3.14) -project(qmlqtimeexampleplugin LANGUAGES CXX) +project(qmlqtimeexample LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -19,37 +19,38 @@ find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Gui) find_package(Qt6 COMPONENTS Qml) -qt6_add_qml_module(qmlqtimeexampleplugin +set_source_files_properties(imports/TimeExample/Clock.qml PROPERTIES + QT_RESOURCE_ALIAS Clock.qml +) +qt6_add_qml_module(qmlqtimeexample OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/imports/TimeExample" VERSION 1.0 URI "TimeExample" - INSTALL_LOCATION ${INSTALL_EXAMPLEDIR} -) - -target_sources(qmlqtimeexampleplugin PRIVATE - plugin.cpp - timemodel.cpp timemodel.h + SOURCES timemodel.cpp timemodel.h + QML_FILES imports/TimeExample/Clock.qml ) -set_target_properties(qmlqtimeexampleplugin PROPERTIES +set_target_properties(qmlqtimeexample PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_link_libraries(qmlqtimeexampleplugin PUBLIC +target_link_libraries(qmlqtimeexample PUBLIC Qt::Core Qt::Gui Qt::Qml ) -install(TARGETS qmlqtimeexampleplugin +qt6_add_resources(qmlqtimeexample example_images + PREFIX "/TimeExample" + BASE imports/TimeExample + FILES + imports/TimeExample/center.png + imports/TimeExample/clock.png + imports/TimeExample/hour.png + imports/TimeExample/minute.png +) + +install(TARGETS qmlqtimeexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(qmlqtimeexampleplugin PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI TimeExample - QT_QMLTYPES_FILENAME imports/TimeExample/plugins.qmltypes -) - -qt6_qml_type_registration(qmlqtimeexampleplugin) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt index ad3a5972e8..f75028aa69 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt @@ -24,11 +24,10 @@ qt6_add_qml_module(chartsplugin OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../Charts" VERSION 1.0 URI "Charts" - INSTALL_LOCATION ${INSTALL_EXAMPLEDIR} + PLUGIN_TARGET chartsplugin ) target_sources(chartsplugin PRIVATE - chartsplugin.h piechart.cpp piechart.h pieslice.cpp pieslice.h ) @@ -48,10 +47,3 @@ install(TARGETS chartsplugin BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chartsplugin PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chartsplugin) -- cgit v1.2.3