summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_static_resources
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/cmake/test_static_resources')
-rw-r--r--tests/auto/cmake/test_static_resources/.cmake.conf1
-rw-r--r--tests/auto/cmake/test_static_resources/CMakeLists.txt26
-rw-r--r--tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt21
-rw-r--r--tests/auto/cmake/test_static_resources/mock_static_resources1/configure.cmake2
-rw-r--r--tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp4
-rw-r--r--tests/auto/cmake/test_static_resources/mock_static_resources1/testfile1.txt0
-rw-r--r--tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/CMakeLists.txt36
-rw-r--r--tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/pluginmain.cpp24
-rw-r--r--tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/test_init_resources_static_plugin.cpp33
-rw-r--r--tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile1.txt0
-rw-r--r--tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile2.txt0
-rw-r--r--tests/auto/cmake/test_static_resources/test_static_resources_propagation/CMakeLists.txt180
-rw-r--r--tests/auto/cmake/test_static_resources/test_static_resources_propagation/main.cpp23
13 files changed, 350 insertions, 0 deletions
diff --git a/tests/auto/cmake/test_static_resources/.cmake.conf b/tests/auto/cmake/test_static_resources/.cmake.conf
new file mode 100644
index 0000000000..6d83b084f7
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/.cmake.conf
@@ -0,0 +1 @@
+set(QT_REPO_MODULE_VERSION "6.9.0")
diff --git a/tests/auto/cmake/test_static_resources/CMakeLists.txt b/tests/auto/cmake/test_static_resources/CMakeLists.txt
new file mode 100644
index 0000000000..e3cab9cf4a
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/CMakeLists.txt
@@ -0,0 +1,26 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+include(.cmake.conf)
+
+project(TestStaticResources
+ DESCRIPTION "Test of the static resources"
+ HOMEPAGE_URL "https://qt.io/"
+ LANGUAGES CXX C
+ VERSION "${QT_REPO_MODULE_VERSION}"
+)
+
+find_package(Qt6 COMPONENTS Core BuildInternals Test CONFIG REQUIRED)
+qt_internal_project_setup()
+
+qt_build_repo_begin()
+
+enable_testing()
+add_subdirectory(mock_static_resources1)
+add_subdirectory(test_init_resources_static_plugin)
+add_subdirectory(test_static_resources_propagation)
+
+qt_build_repo_post_process()
+qt_build_repo_end()
diff --git a/tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt b/tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt
new file mode 100644
index 0000000000..f866f0af46
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_module(MockStaticResources1
+ NO_UNITY_BUILD
+ STATIC
+ PLUGIN_TYPES mockstaticresources
+ SOURCES
+ dummy.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ PUBLIC_LIBRARIES
+ Qt::Core
+)
+
+qt_internal_add_resource(MockStaticResources1 "teststaticmodule1"
+ PREFIX
+ "/teststaticmodule1"
+ FILES
+ "testfile1.txt"
+)
diff --git a/tests/auto/cmake/test_static_resources/mock_static_resources1/configure.cmake b/tests/auto/cmake/test_static_resources/mock_static_resources1/configure.cmake
new file mode 100644
index 0000000000..46da2db2b8
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/configure.cmake
@@ -0,0 +1,2 @@
+# This is needed so that MODULE_PLUGIN_TYPES property is set on the exported target.
+# Fun times.
diff --git a/tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp b/tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp
new file mode 100644
index 0000000000..b6c23a82eb
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp
@@ -0,0 +1,4 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+void dummy() { }
diff --git a/tests/auto/cmake/test_static_resources/mock_static_resources1/testfile1.txt b/tests/auto/cmake/test_static_resources/mock_static_resources1/testfile1.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/testfile1.txt
diff --git a/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/CMakeLists.txt b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/CMakeLists.txt
new file mode 100644
index 0000000000..dec5588a6d
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/CMakeLists.txt
@@ -0,0 +1,36 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+qt_internal_add_plugin(TestInitResourcesStaticPlugin STATIC
+ NO_UNITY_BUILD
+ OUTPUT_NAME
+ testinitresourcesstaticplugin
+ PLUGIN_TYPE mockstaticresources
+ SOURCES
+ pluginmain.cpp
+ SKIP_INSTALL
+ LIBRARIES
+ Qt::Core
+)
+
+qt_internal_add_resource(TestInitResourcesStaticPlugin "teststaticplugin1"
+ PREFIX
+ "/teststaticplugin1"
+ FILES
+ "testfile1.txt"
+)
+
+qt_internal_add_resource(TestInitResourcesStaticPlugin "teststaticplugin2"
+ PREFIX
+ "/teststaticplugin2"
+ FILES
+ "testfile2.txt"
+)
+
+qt_internal_add_test(test_init_resources_static_plugin
+ SOURCES
+ test_init_resources_static_plugin.cpp
+ LIBRARIES
+ Qt::Core
+ TestInitResourcesStaticPlugin
+)
diff --git a/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/pluginmain.cpp b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/pluginmain.cpp
new file mode 100644
index 0000000000..a95e54ee4f
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/pluginmain.cpp
@@ -0,0 +1,24 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtCore/qfile.h>
+#include <QtCore/qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+class TestStaticPlugin : public QObject
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID "TestStaticPlugin" URI "qt.teststaticplugin")
+public:
+ TestStaticPlugin() = default;
+ Q_INVOKABLE bool checkResources()
+ {
+ return QFile::exists(":/teststaticplugin1/testfile1.txt")
+ && QFile::exists(":/teststaticplugin2/testfile2.txt");
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "pluginmain.moc"
diff --git a/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/test_init_resources_static_plugin.cpp b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/test_init_resources_static_plugin.cpp
new file mode 100644
index 0000000000..2067b8c920
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/test_init_resources_static_plugin.cpp
@@ -0,0 +1,33 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtTest/QtTest>
+#include <QtCore/qfile.h>
+#include <QtCore/qobject.h>
+#include <QtCore/qpluginloader.h>
+#include <QtPlugin>
+
+Q_IMPORT_PLUGIN(TestStaticPlugin)
+
+class TestInitResourcesStaticPlugin : public QObject
+{
+ Q_OBJECT
+private slots:
+ void resourceFilesExist();
+};
+
+void TestInitResourcesStaticPlugin::resourceFilesExist()
+{
+ bool result = false;
+ for (QObject *obj : QPluginLoader::staticInstances()) {
+ if (obj->metaObject()->className() == QLatin1String("TestStaticPlugin")) {
+ QMetaObject::invokeMethod(obj, "checkResources", Qt::DirectConnection,
+ Q_RETURN_ARG(bool, result));
+ }
+ break;
+ }
+ QVERIFY(result);
+}
+
+QTEST_MAIN(TestInitResourcesStaticPlugin)
+#include "test_init_resources_static_plugin.moc"
diff --git a/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile1.txt b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile1.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile1.txt
diff --git a/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile2.txt b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile2.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_init_resources_static_plugin/testfile2.txt
diff --git a/tests/auto/cmake/test_static_resources/test_static_resources_propagation/CMakeLists.txt b/tests/auto/cmake/test_static_resources/test_static_resources_propagation/CMakeLists.txt
new file mode 100644
index 0000000000..b802323cfc
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_static_resources_propagation/CMakeLists.txt
@@ -0,0 +1,180 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# TODO: Revisit which of these tests makes sense to keep now that we depend on CMake 3.21 to
+# properly place object libraries object files on the link line.
+# See QTBUG-95601
+#
+#
+#
+#
+# Add a dummy library that links the static "Qt" module containing resources
+file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" CONTENT "void dummy() { }")
+add_library(dummy STATIC "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp")
+set_target_properties(dummy PROPERTIES UNITY_BUILD OFF)
+target_link_libraries(dummy PRIVATE MockStaticResources1)
+
+# Add the executable using qt_add_executable that needs to initialize the propagated resources.
+# Finalize it implicitly(since CMake version 3.19).
+if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
+ qt_add_executable(test_static_resources_propagation main.cpp)
+ set_target_properties(test_static_resources_propagation PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+ )
+ target_link_libraries(test_static_resources_propagation
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+ )
+ add_test(NAME test_static_resources_propagation
+ COMMAND test_static_resources_propagation
+ )
+endif()
+
+
+# Add the executable using qt_add_executable that needs to initialize the propagated resources.
+# Finalize it explicitly.
+qt_add_executable(test_static_resources_propagation_manual_finalize main.cpp MANUAL_FINALIZATION)
+set_target_properties(test_static_resources_propagation_manual_finalize PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+)
+target_link_libraries(test_static_resources_propagation_manual_finalize
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+)
+qt_finalize_target(test_static_resources_propagation_manual_finalize)
+add_test(NAME test_static_resources_propagation_manual_finalize
+ COMMAND test_static_resources_propagation_manual_finalize
+)
+
+# Add the executable using add_executable that needs to initialize the propagated resources.
+# Finalize it explicitly.
+add_executable(test_static_resources_propagation_non_qt main.cpp)
+set_target_properties(test_static_resources_propagation_non_qt PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+)
+target_link_libraries(test_static_resources_propagation_non_qt
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+)
+qt_finalize_target(test_static_resources_propagation_non_qt)
+add_test(NAME test_static_resources_propagation_non_qt
+ COMMAND test_static_resources_propagation_non_qt
+)
+
+get_target_property(link_order_matters
+ ${QT_CMAKE_EXPORT_NAMESPACE}::Platform
+ _qt_link_order_matters
+)
+
+if(NOT link_order_matters)
+ # Add the executable using add_executable, expecting resources to be linked regardless of order.
+ add_executable(test_static_resources_propagation_non_ld main.cpp)
+ set_target_properties(test_static_resources_propagation_non_ld PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+ )
+ target_link_libraries(test_static_resources_propagation_non_ld
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+ )
+ add_test(NAME test_static_resources_propagation_non_ld
+ COMMAND test_static_resources_propagation_non_ld
+ )
+
+# FIXME: qt6_enable_object_libraries_finalizer_mode is not available anymore. See QTBUG-95601
+#
+# if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
+# qt_add_executable(test_static_resources_propagation_not_finalize main.cpp)
+# qt6_enable_object_libraries_finalizer_mode(
+# test_static_resources_propagation_not_finalize FALSE
+# )
+# set_target_properties(test_static_resources_propagation_not_finalize PROPERTIES
+# AUTOMOC TRUE
+# )
+# target_link_libraries(test_static_resources_propagation_not_finalize
+# PRIVATE
+# dummy
+# Qt::Core
+# Qt::Test
+# )
+# add_test(NAME test_static_resources_propagation_not_finalize
+# COMMAND test_static_resources_propagation_not_finalize
+# )
+# endif()
+endif()
+
+# Add the executable using add_executable, expecting resources are propagated using
+# target_link_options approach. The test is not applicable for qt_add_executable call since
+# we use the CMP0099 policy NEW unless the actual version of CMake is lower than 3.17, that means
+# target_link_options will always be preferable to finalizers.
+if(POLICY CMP0099)
+ cmake_policy(PUSH)
+
+ cmake_policy(SET CMP0099 OLD)
+ # When CMP0099 is set to OLD target_link_options doesn't propagate the linker options when
+ # linking static libraries with a PRIVATE visibility but we finalize it explicitly. This
+ # is a pure finalizer use case for platforms where link order matters.
+ add_executable(test_static_resources_propagation_cmp0099_old_finalize main.cpp)
+ set_target_properties(test_static_resources_propagation_cmp0099_old_finalize PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+ )
+ target_link_libraries(test_static_resources_propagation_cmp0099_old_finalize
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+ )
+ qt_finalize_target(test_static_resources_propagation_cmp0099_old_finalize)
+ add_test(NAME test_static_resources_propagation_cmp0099_old_finalize
+ COMMAND test_static_resources_propagation_cmp0099_old_finalize
+ )
+
+ # When CMP0099 is set to NEW target_link_options propagates the linker options when linking
+ # static libraries with a PRIVATE visibility. This is a pure target_link_options use case for
+ # platforms where link order matters.
+ cmake_policy(SET CMP0099 NEW)
+ add_executable(test_static_resources_propagation_cmp0099_new main.cpp)
+ set_target_properties(test_static_resources_propagation_cmp0099_new PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+ )
+ target_link_libraries(test_static_resources_propagation_cmp0099_new
+ PRIVATE
+ dummy
+ Qt::Core
+ Qt::Test
+ )
+ add_test(NAME test_static_resources_propagation_cmp0099_new
+ COMMAND test_static_resources_propagation_cmp0099_new
+ )
+
+ # Check if linking libraries using genex propagates resource objects when CMP0099 is enabled
+ add_executable(test_static_resources_propagation_cmp0099_new_genex main.cpp)
+ set_target_properties(test_static_resources_propagation_cmp0099_new_genex PROPERTIES
+ AUTOMOC TRUE
+ UNITY_BUILD OFF
+ )
+ target_link_libraries(test_static_resources_propagation_cmp0099_new_genex
+ PRIVATE
+ $<1:dummy>
+ Qt::Core
+ Qt::Test
+ )
+ add_test(NAME test_static_resources_propagation_cmp0099_new_genex
+ COMMAND test_static_resources_propagation_cmp0099_new_genex
+ )
+
+ cmake_policy(POP)
+endif()
diff --git a/tests/auto/cmake/test_static_resources/test_static_resources_propagation/main.cpp b/tests/auto/cmake/test_static_resources/test_static_resources_propagation/main.cpp
new file mode 100644
index 0000000000..c5d5312eb8
--- /dev/null
+++ b/tests/auto/cmake/test_static_resources/test_static_resources_propagation/main.cpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtTest/QtTest>
+#include <QtCore/qfile.h>
+#include <QtCore/qobject.h>
+#include <QtPlugin>
+
+class TestStaticResourcePropagation : public QObject
+{
+ Q_OBJECT
+private slots:
+ void resourceFilesExist();
+};
+
+void TestStaticResourcePropagation::resourceFilesExist()
+{
+ bool result = QFile::exists(":/teststaticmodule1/testfile1.txt");
+ QVERIFY(result);
+}
+
+QTEST_MAIN(TestStaticResourcePropagation)
+#include "main.moc"