From 2625e5f050b2bedb4aa9ff9307e90c1e3ba85e8e Mon Sep 17 00:00:00 2001 From: Amir Masoud Abdol Date: Thu, 13 Oct 2022 13:01:56 +0200 Subject: [PATCH] Make the `PREFIX` Parameter of the `qt_add_resources` Optional The `rcc_PREFIX` will be set to `/` if it is not passed to the function and it is not defined in `QT_RESOURCE_PREFIX`. I also removed an unnecessary check of the `rcc_PREFIX`. [ChangeLog][QtCore][CMake] The `PREFIX` parameter of the `qt_add_resources` is now optional. If not passed, and `QT_RESOURCE_PREFIX` is not defined, `/` will be used as the path prefix. Fixes: QTBUG-104938 Change-Id: I6524ab5dc54f035272e4c2e3154eb67591efb650 Reviewed-by: Alexey Edelev --- src/corelib/Qt6CoreMacros.cmake | 7 +++-- .../doc/src/cmake/qt_add_resources.qdoc | 4 ++- tests/auto/cmake/CMakeLists.txt | 1 + .../test_add_resource_prefix/CMakeLists.txt | 25 ++++++++++++++++++ .../cmake/test_add_resource_prefix/main.cpp | 26 +++++++++++++++++++ .../resource_file.txt | 1 + 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/auto/cmake/test_add_resource_prefix/CMakeLists.txt create mode 100644 tests/auto/cmake/test_add_resource_prefix/main.cpp create mode 100644 tests/auto/cmake/test_add_resource_prefix/resource_file.txt diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index 915b0dd972..a24fd8dd29 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -1781,7 +1781,7 @@ function(_qt_internal_process_resource target resourceName) if(NOT rcc_PREFIX) get_target_property(rcc_PREFIX ${target} QT_RESOURCE_PREFIX) if (NOT rcc_PREFIX) - message(FATAL_ERROR "_qt_internal_process_resource() was called without a PREFIX and the target does not provide QT_RESOURCE_PREFIX. Please either add a PREFIX or make the target ${target} provide a default.") + set(rcc_PREFIX "/") endif() endif() @@ -1797,9 +1797,8 @@ function(_qt_internal_process_resource target resourceName) # set(qrcContents "\n +#include + +class TestAddResourcePrefix : public QObject +{ + Q_OBJECT +private slots: + void resourceInDefaultPathExists(); + void resourceInGivenPathExists(); +}; + +void TestAddResourcePrefix::resourceInDefaultPathExists() +{ + QVERIFY(QFile::exists(":/resource_file.txt")); +} + +void TestAddResourcePrefix::resourceInGivenPathExists() +{ + QVERIFY(QFile::exists(":/resources/resource_file.txt")); +} + +QTEST_MAIN(TestAddResourcePrefix) +#include "main.moc" diff --git a/tests/auto/cmake/test_add_resource_prefix/resource_file.txt b/tests/auto/cmake/test_add_resource_prefix/resource_file.txt new file mode 100644 index 0000000000..2c604a4f18 --- /dev/null +++ b/tests/auto/cmake/test_add_resource_prefix/resource_file.txt @@ -0,0 +1 @@ +Ken sent me.