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 <alexey.edelev@qt.io>bb10
parent
30eac4a4f9
commit
2625e5f050
|
|
@ -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)
|
|||
|
||||
# <RCC><qresource ...>
|
||||
set(qrcContents "<RCC>\n <qresource")
|
||||
if (rcc_PREFIX)
|
||||
string(APPEND qrcContents " prefix=\"${rcc_PREFIX}\"")
|
||||
endif()
|
||||
string(APPEND qrcContents " prefix=\"${rcc_PREFIX}\"")
|
||||
|
||||
if (rcc_LANG)
|
||||
string(APPEND qrcContents " lang=\"${rcc_LANG}\"")
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -57,7 +57,9 @@ See \l{The Qt Resource System} for a general description of Qt resources.
|
|||
\c PREFIX specifies a path prefix under which all files of this resource are
|
||||
accessible from C++ code. This corresponds to the XML attribute \c prefix of the
|
||||
\c .qrc file format. If \c PREFIX is not given, the target property
|
||||
\l{cmake-target-property-QT_RESOURCE_PREFIX}{QT_RESOURCE_PREFIX} is used.
|
||||
\l{cmake-target-property-QT_RESOURCE_PREFIX}{QT_RESOURCE_PREFIX} is used. Since
|
||||
6.5, \c{PREFIX} is optional. If it is omitted and not specified by
|
||||
\c{QT_RESOURCE_PREFIX}, \c{"/"} will be used as the default path prefix.
|
||||
|
||||
\c LANG specifies the locale of this resource. This corresponds to the XML
|
||||
attribute \c lang of the \c .qrc file format.
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ if (NOT NO_WIDGETS)
|
|||
_qt_internal_test_expect_pass(test_dependent_modules)
|
||||
_qt_internal_test_expect_pass("test(needsquoting)dirname")
|
||||
endif()
|
||||
_qt_internal_test_expect_pass(test_add_resource_prefix BINARY test_add_resource_prefix)
|
||||
_qt_internal_test_expect_build_fail(test_add_resource_options)
|
||||
_qt_internal_test_expect_build_fail(test_wrap_cpp_options)
|
||||
_qt_internal_test_expect_pass(test_platform_defs_include)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(test_add_resource_prefix)
|
||||
|
||||
find_package(Qt6 REQUIRED
|
||||
COMPONENTS Core Test
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_executable(test_add_resource_prefix main.cpp)
|
||||
|
||||
# Tests if "/" is being used when PREFIX is missing
|
||||
qt_add_resources(test_add_resource_prefix "resources_without_prefix"
|
||||
FILES resource_file.txt)
|
||||
|
||||
# Tests if the PREFIX parameter is being respected
|
||||
qt_add_resources(test_add_resource_prefix "resources_with_prefix"
|
||||
PREFIX "/resources"
|
||||
FILES resource_file.txt)
|
||||
|
||||
target_link_libraries(test_add_resource_prefix PRIVATE Qt::Core Qt::Test)
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QFile>
|
||||
#include <QtTest>
|
||||
|
||||
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"
|
||||
|
|
@ -0,0 +1 @@
|
|||
Ken sent me.
|
||||
Loading…
Reference in New Issue