diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2020-11-10 15:18:49 +0100 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2020-11-12 22:11:37 +0100 |
commit | 558f5a2d7ba99d1c00132a6664f428837715e649 (patch) | |
tree | a6119b74aa164943c48a89200f5c0b29f7c5eb0b /tests/auto | |
parent | 29b17fa335388c9b93f70c29b2398cf2fee65785 (diff) |
CMake: Add support for -binary option for generated resources
Add handling of -binary flag in qt6_add_resources for generated
resource file variant.
If -binary argument is provided in OPTIONS section of
qt6_add_resources function, it will be passed to rcc as argument.
File path to output .rcc could be additionally specified by
DESTINATION argument. Extra target generated_<resource_filename>
will be added to project's 'all' set.
Implement tests for new functionality.
Fixes: QTBUG-87644
Change-Id: Id1313da499d86f82859d1757c3cfae2d84e894d4
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'tests/auto')
5 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 27ceae74fb..e8a60840a6 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -221,3 +221,6 @@ endif() # FIXME: Needs porting of the qmake .pro files to create the modules and plugins in Qt6 CMake land. # _qt_internal_test_expect_pass(test_import_plugins BINARY ${CMAKE_CTEST_COMMAND}) _qt_internal_test_expect_pass(test_versionless_targets) + +_qt_internal_test_expect_pass(test_add_resources_binary_generated + BINARY test_add_resources_binary_generated) diff --git a/tests/auto/cmake/test_add_resources_binary_generated/CMakeLists.txt b/tests/auto/cmake/test_add_resources_binary_generated/CMakeLists.txt new file mode 100644 index 0000000000..c7839348a7 --- /dev/null +++ b/tests/auto/cmake/test_add_resources_binary_generated/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.14) + +project(test_add_resources_binary_generated) + +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") +endif() + +find_package(Qt6Core REQUIRED HINTS ${Qt6Tests_PREFIX_PATH}) + +qt6_add_executable(test_add_resources_binary_generated main.cpp) + +qt6_add_resources(test_add_resources_binary_generated resources1 FILES resource1.txt PREFIX "/" + OPTIONS "--binary") +qt6_add_resources(test_add_resources_binary_generated resources2 FILES resource2.txt PREFIX "/" + OPTIONS "--binary" + DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/resources2_custom.rcc") + +target_compile_definitions(test_add_resources_binary_generated + PRIVATE + RESOURCE1_FULL_PATH="${CMAKE_CURRENT_BINARY_DIR}/generated_resources1.rcc") +target_compile_definitions(test_add_resources_binary_generated + PRIVATE + RESOURCE2_FULL_PATH="${CMAKE_CURRENT_BINARY_DIR}/resources2_custom.rcc") + +if(NOT TARGET binary_resource_generated_resources1) + message(FATAL_ERROR "Generated resources binary target was not created") +endif() + +if(NOT TARGET binary_resource_generated_resources2) + message(FATAL_ERROR "Generated resources binary target was not created") +endif() diff --git a/tests/auto/cmake/test_add_resources_binary_generated/main.cpp b/tests/auto/cmake/test_add_resources_binary_generated/main.cpp new file mode 100644 index 0000000000..bee714bcf9 --- /dev/null +++ b/tests/auto/cmake/test_add_resources_binary_generated/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QFile> +#include <QResource> + +int main(int, char **) +{ + if (!QResource::registerResource(RESOURCE1_FULL_PATH) + || !QFile::exists(":/resource1.txt") + || !QResource::registerResource(RESOURCE2_FULL_PATH) + || !QFile::exists(":/resource2.txt")) { + return -1; + } + return 0; +} diff --git a/tests/auto/cmake/test_add_resources_binary_generated/resource1.txt b/tests/auto/cmake/test_add_resources_binary_generated/resource1.txt new file mode 100644 index 0000000000..bc06a6d721 --- /dev/null +++ b/tests/auto/cmake/test_add_resources_binary_generated/resource1.txt @@ -0,0 +1 @@ +Test resource1 diff --git a/tests/auto/cmake/test_add_resources_binary_generated/resource2.txt b/tests/auto/cmake/test_add_resources_binary_generated/resource2.txt new file mode 100644 index 0000000000..b8f9e67458 --- /dev/null +++ b/tests/auto/cmake/test_add_resources_binary_generated/resource2.txt @@ -0,0 +1 @@ +Test resource2 |