diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-12-08 18:28:40 +0100 |
---|---|---|
committer | Amir Masoud Abdol <amir.abdol@qt.io> | 2023-02-01 23:39:19 +0100 |
commit | ec452fc6e87e82d135d7ef782d5c811583d5c433 (patch) | |
tree | d23a91de87691375298ee23435fc4bd1f21a3475 | |
parent | a6d9312c99d6f80cbea7538276d2890d0cc4c760 (diff) |
qt_add_qml_module: Make usage of AUTO_RESOURCE_PREFIX a policy
Writing AUTO_RESOURCE_PREFIX in every qt_add_qml_module call seems
rather pointless.
In addition:
- Add documentation for QTP0001.
- Adjust some of the examples to use QTP0001 policy.
- Improved the error message.
Pick-to: 6.5
Task-number: QTBUG-96233
Change-Id: I6e19a491acba97493893bf1953fca3462296c1ea
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
27 files changed, 72 insertions, 20 deletions
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt index 714e44d2f0..4a8f2e0b7b 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause +qt6_policy(SET QTP0001 NEW) qt6_add_qml_module(chartsplugin URI "Charts" PLUGIN_TARGET chartsplugin diff --git a/examples/quickcontrols/attachedstyleproperties/MyStyle/CMakeLists.txt b/examples/quickcontrols/attachedstyleproperties/MyStyle/CMakeLists.txt index e6e6e10370..9cb00a81e7 100644 --- a/examples/quickcontrols/attachedstyleproperties/MyStyle/CMakeLists.txt +++ b/examples/quickcontrols/attachedstyleproperties/MyStyle/CMakeLists.txt @@ -4,6 +4,7 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quickcontrols/attachedstyleproperties") +qt_policy(SET QTP0001 NEW) qt_add_qml_module(MyStyle URI MyStyle IMPORTS diff --git a/examples/quickcontrols/chattutorial/chapter1/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter1/CMakeLists.txt index 52a9dcb19b..549790b9e8 100644 --- a/examples/quickcontrols/chattutorial/chapter1/CMakeLists.txt +++ b/examples/quickcontrols/chattutorial/chapter1/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(chattutorial-chapter1 PRIVATE Qt::Quick ) +qt_policy(SET QTP0001 NEW) qt_add_qml_module(chattutorial-chapter1 URI chapter1 QML_FILES diff --git a/examples/quickcontrols/chattutorial/chapter1/chapter1.pro b/examples/quickcontrols/chattutorial/chapter1/chapter1.pro index c44cd50659..40c7d2ff7d 100644 --- a/examples/quickcontrols/chattutorial/chapter1/chapter1.pro +++ b/examples/quickcontrols/chattutorial/chapter1/chapter1.pro @@ -6,7 +6,7 @@ CONFIG += c++11 SOURCES += main.cpp resources.files = main.qml -resources.prefix = chapter1/ +resources.prefix = qt/qml/chapter1/ RESOURCES += resources \ qtquickcontrols2.conf diff --git a/examples/quickcontrols/chattutorial/chapter1/main.cpp b/examples/quickcontrols/chattutorial/chapter1/main.cpp index 3752f91d90..7252c0c3ad 100644 --- a/examples/quickcontrols/chattutorial/chapter1/main.cpp +++ b/examples/quickcontrols/chattutorial/chapter1/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/chapter1/main.qml"))); + engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter1/main.qml"))); return app.exec(); } diff --git a/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt index 0669626a06..561861afc0 100644 --- a/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt +++ b/examples/quickcontrols/chattutorial/chapter2/CMakeLists.txt @@ -25,6 +25,7 @@ target_link_libraries(chattutorial-chapter2 PRIVATE Qt::Quick ) +qt_policy(SET QTP0001 NEW) qt_add_qml_module(chattutorial-chapter2 URI chapter2 QML_FILES diff --git a/examples/quickcontrols/chattutorial/chapter2/chapter2.pro b/examples/quickcontrols/chattutorial/chapter2/chapter2.pro index 00cf68b57c..8679db986a 100644 --- a/examples/quickcontrols/chattutorial/chapter2/chapter2.pro +++ b/examples/quickcontrols/chattutorial/chapter2/chapter2.pro @@ -19,7 +19,7 @@ resources.files = \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ main.qml -resources.prefix = chapter2/ +resources.prefix = qt/qml/chapter2/ RESOURCES += resources \ qtquickcontrols2.conf diff --git a/examples/quickcontrols/chattutorial/chapter2/main.cpp b/examples/quickcontrols/chattutorial/chapter2/main.cpp index eeb87becca..07f034a827 100644 --- a/examples/quickcontrols/chattutorial/chapter2/main.cpp +++ b/examples/quickcontrols/chattutorial/chapter2/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/chapter2/main.qml"))); + engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter2/main.qml"))); return app.exec(); } diff --git a/examples/quickcontrols/chattutorial/chapter3/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter3/CMakeLists.txt index e55597f2c8..92ac5683fd 100644 --- a/examples/quickcontrols/chattutorial/chapter3/CMakeLists.txt +++ b/examples/quickcontrols/chattutorial/chapter3/CMakeLists.txt @@ -25,7 +25,7 @@ target_link_libraries(chattutorial-chapter3 PRIVATE Qt::Quick ) -# Resources: +qt_policy(SET QTP0001 NEW) qt_add_qml_module(chattutorial-chapter3 URI chapter3 QML_FILES diff --git a/examples/quickcontrols/chattutorial/chapter3/chapter3.pro b/examples/quickcontrols/chattutorial/chapter3/chapter3.pro index 9a4c5b5703..5314e2dd36 100644 --- a/examples/quickcontrols/chattutorial/chapter3/chapter3.pro +++ b/examples/quickcontrols/chattutorial/chapter3/chapter3.pro @@ -21,7 +21,7 @@ resources.files = \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ main.qml -resources.prefix = chapter3/ +resources.prefix = qt/qml/chapter3/ RESOURCES += resources \ qtquickcontrols2.conf diff --git a/examples/quickcontrols/chattutorial/chapter3/main.cpp b/examples/quickcontrols/chattutorial/chapter3/main.cpp index 4347d3ff6c..71e250bed5 100644 --- a/examples/quickcontrols/chattutorial/chapter3/main.cpp +++ b/examples/quickcontrols/chattutorial/chapter3/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/chapter3/main.qml"))); + engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter3/main.qml"))); return app.exec(); } diff --git a/examples/quickcontrols/chattutorial/chapter4/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter4/CMakeLists.txt index c26fe1416b..cc56b319e7 100644 --- a/examples/quickcontrols/chattutorial/chapter4/CMakeLists.txt +++ b/examples/quickcontrols/chattutorial/chapter4/CMakeLists.txt @@ -28,7 +28,7 @@ target_link_libraries(chattutorial-chapter4 PRIVATE Qt::Sql ) -# Resources: +qt_policy(SET QTP0001 NEW) qt_add_qml_module(chattutorial-chapter4 URI chapter4 QML_FILES diff --git a/examples/quickcontrols/chattutorial/chapter4/chapter4.pro b/examples/quickcontrols/chattutorial/chapter4/chapter4.pro index baf2d319d5..399b3506c2 100644 --- a/examples/quickcontrols/chattutorial/chapter4/chapter4.pro +++ b/examples/quickcontrols/chattutorial/chapter4/chapter4.pro @@ -26,7 +26,7 @@ resources.files = \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ main.qml -resources.prefix = chapter4/ +resources.prefix = qt/qml/chapter4/ RESOURCES += resources \ qtquickcontrols2.conf diff --git a/examples/quickcontrols/chattutorial/chapter4/main.cpp b/examples/quickcontrols/chattutorial/chapter4/main.cpp index 0ca281c7d9..4c7289deb3 100644 --- a/examples/quickcontrols/chattutorial/chapter4/main.cpp +++ b/examples/quickcontrols/chattutorial/chapter4/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) connectToDatabase(); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/chapter4/main.qml"))); + engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter4/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/quickcontrols/chattutorial/chapter5/CMakeLists.txt b/examples/quickcontrols/chattutorial/chapter5/CMakeLists.txt index 39126e51bd..dfffa0f6de 100644 --- a/examples/quickcontrols/chattutorial/chapter5/CMakeLists.txt +++ b/examples/quickcontrols/chattutorial/chapter5/CMakeLists.txt @@ -28,7 +28,7 @@ target_link_libraries(chattutorial-chapter5 PRIVATE Qt::Sql ) -# Resources: +qt_policy(SET QTP0001 NEW) qt_add_qml_module(chattutorial-chapter5 URI chapter5 QML_FILES diff --git a/examples/quickcontrols/chattutorial/chapter5/chapter5.pro b/examples/quickcontrols/chattutorial/chapter5/chapter5.pro index 3ba8d97ddc..9f44cb0459 100644 --- a/examples/quickcontrols/chattutorial/chapter5/chapter5.pro +++ b/examples/quickcontrols/chattutorial/chapter5/chapter5.pro @@ -28,7 +28,7 @@ resources.files = \ images/Hans_Gude@3x.png \ images/Hans_Gude@4x.png \ main.qml -resources.prefix = chapter5/ +resources.prefix = qt/qml/chapter5/ RESOURCES += resources \ qtquickcontrols2.conf diff --git a/examples/quickcontrols/chattutorial/chapter5/main.cpp b/examples/quickcontrols/chattutorial/chapter5/main.cpp index cfa5aa6f57..a084655830 100644 --- a/examples/quickcontrols/chattutorial/chapter5/main.cpp +++ b/examples/quickcontrols/chattutorial/chapter5/main.cpp @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) connectToDatabase(); QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/chapter5/main.qml"))); + engine.load(QUrl(QStringLiteral("qrc:/qt/qml/chapter5/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt index b08319090b..1b00d685b6 100644 --- a/src/qml/CMakeLists.txt +++ b/src/qml/CMakeLists.txt @@ -420,6 +420,8 @@ qt_internal_add_qml_module(Qml ${extra_cmake_includes} GENERATE_CPP_EXPORTS GENERATE_PRIVATE_CPP_EXPORTS + POLICIES + QTP0001 ) qt_update_ignore_pch_source(Qml "compat/removed_api.cpp") diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index ff84003599..6b3e8ffb08 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -437,13 +437,16 @@ function(qt6_add_qml_module target) # In that case, we assume the user knows what they want. set(arg_RESOURCE_PREFIX "/") else() - message(WARNING - "Neither RESOURCE_PREFIX nor AUTO_RESOURCE_PREFIX are specified for ${target}. " - "The resource root directory, ':/', is used as prefix. If this is what you want, " - "specify '/' as RESOURCE_PREFIX. The recommended resource directory to be used as " - "prefix is ':/qt/qml/'. Specify AUTO_RESOURCE_PREFIX to use it." + __qt_internal_setup_policy(QTP0001 "6.5.0" +"':/qt/qml/' is the default resource prefix for QML modules. \ +Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details." ) - set(arg_RESOURCE_PREFIX "/") + qt6_policy(GET QTP0001 use_auto_prefix_policy) + if ("${use_auto_prefix_policy}" STREQUAL "NEW") + set(arg_RESOURCE_PREFIX "/qt/qml") + else() + set(arg_RESOURCE_PREFIX "/") + endif() endif() if(arg_NO_RESOURCE_TARGET_PATH) diff --git a/src/qml/doc/snippets/qml/CMakeLists.txt b/src/qml/doc/snippets/qml/CMakeLists.txt index 5dd190d004..7c7ac116c3 100644 --- a/src/qml/doc/snippets/qml/CMakeLists.txt +++ b/src/qml/doc/snippets/qml/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -qt_add_library(extra_module STATIC) +qt_add_library(extra_module STATIC) qt_add_qml_module(extra_module URI "ExtraModule" VERSION 1.0 @@ -9,6 +9,7 @@ qt_add_qml_module(extra_module Extra.qml SOURCES extrathing.cpp extrathing.h + RESOURCE_PREFIX / ) add_subdirectory(ExtraModule) diff --git a/src/qml/doc/src/cmake/policy/qtp0001.qdoc b/src/qml/doc/src/cmake/policy/qtp0001.qdoc new file mode 100644 index 0000000000..a5381647c9 --- /dev/null +++ b/src/qml/doc/src/cmake/policy/qtp0001.qdoc @@ -0,0 +1,36 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! +\page qt-cmake-policy-qtp0001.html +\ingroup qt-cmake-policies + +\title QTP0001 +\keyword qt_cmake_policy_qtp0001 + +\summary {':/qt/qml/' is the default resource prefix for QML modules.} + +This policy was introduced in Qt 6.5. It changes where +\l{qt_add_qml_module}{qt_add_qml_module()} stores QML resources in +the resource system. + +The \c OLD behavior of this policy is that, unless +\c AUTO_RESOURCE_PREFIX is set, the \c RESOURCE_PREFIX argument for +\c{qt_add_qml_module()} defaults to \c{":/"}. + +The \c NEW behavior of this policy is that the \c RESOURCE_PREFIX argument +for \c{qt_add_qml_module()} defaults to \c{\":/qt/qml/"}. The new behavior +ensures that modules are put into the \l{QML Import Path} and can be +found without further setup. + +Qt 6.5 issues warnings if you do not pass any of the following arguments to the +\c qt_add_qml_module command: \c RESOURCE_PREFIX, \c AUTO_RESOURCE_PREFIX, +\c NO_RESOURCE_TARGET_PATH. Use the \l qt_policy command to suppress +the warning by explicitly setting the policy to \c OLD or \c NEW. + +\note The \c{OLD} behavior of a policy is deprecated, and may +be removed in the future. + +\sa qt_policy, qt_cmake_policies, qt_add_qml_module + +*/ diff --git a/tests/auto/cmake/qtquickcompiler/CMakeLists.txt b/tests/auto/cmake/qtquickcompiler/CMakeLists.txt index 6cfa9a0a5f..34acedff99 100644 --- a/tests/auto/cmake/qtquickcompiler/CMakeLists.txt +++ b/tests/auto/cmake/qtquickcompiler/CMakeLists.txt @@ -29,4 +29,5 @@ qt_add_qml_module(qqc_test "resources with space/main.qml" RESOURCES main.cpp + RESOURCE_PREFIX / ) diff --git a/tests/auto/cmake/test_common_import_path/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/CMakeLists.txt index 5d52274bf5..6071128010 100644 --- a/tests/auto/cmake/test_common_import_path/CMakeLists.txt +++ b/tests/auto/cmake/test_common_import_path/CMakeLists.txt @@ -27,5 +27,6 @@ qt_add_qml_module(cmake_test URI duck VERSION 1.0 QML_FILES main.qml + RESOURCE_PREFIX / ) diff --git a/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt index 99238812d3..c3ade36baf 100644 --- a/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt +++ b/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt @@ -8,5 +8,6 @@ qt_add_qml_module(duck_tick VERSION 1.0 QML_FILES Tick.qml + RESOURCE_PREFIX / ) diff --git a/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt index 5c3c8874f2..5ed512e906 100644 --- a/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt +++ b/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt @@ -8,5 +8,6 @@ qt_add_qml_module(duck_trick VERSION 1.0 QML_FILES Trick.qml + RESOURCE_PREFIX / ) diff --git a/tests/auto/cmake/tooling_imports/First/CMakeLists.txt b/tests/auto/cmake/tooling_imports/First/CMakeLists.txt index 3fc0fda56f..55a834b23e 100644 --- a/tests/auto/cmake/tooling_imports/First/CMakeLists.txt +++ b/tests/auto/cmake/tooling_imports/First/CMakeLists.txt @@ -9,4 +9,5 @@ qt_add_qml_module(BackingFirst Neighbor.h QML_FILES DoSomething.qml + RESOURCE_PREFIX / ) diff --git a/tests/auto/cmake/tooling_imports/Second/CMakeLists.txt b/tests/auto/cmake/tooling_imports/Second/CMakeLists.txt index b728c4c37e..0f988d5adc 100644 --- a/tests/auto/cmake/tooling_imports/Second/CMakeLists.txt +++ b/tests/auto/cmake/tooling_imports/Second/CMakeLists.txt @@ -5,4 +5,5 @@ qt_add_qml_module(BackingSecond URI Second VERSION 1.0 QML_FILES CheckIt.qml + RESOURCE_PREFIX / ) |