diff options
Diffstat (limited to 'tests/auto/cmake')
190 files changed, 3540 insertions, 126 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 30cd340f16..86db954086 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# special case skip regeneration - # This is an automatic test for the CMake configuration files. # To run it manually, # 1) mkdir build # Create a build directory @@ -46,6 +44,7 @@ cmake_minimum_required(VERSION 3.16) project(cmake_usage_tests) +include(GNUInstallDirs) # Building the CMake tests as part of a Qt prefix build + in-tree tests, currently doesn't work. # Each CMake test will fail with a message like @@ -70,7 +69,8 @@ enable_testing() # flag. Notably -rpath is specified which should implicitly enable -rpath-link, but that # doesn't seem to be the case. # Until this is figured out, disable the tests when cross-compiling to Linux. -if(UNIX AND NOT APPLE AND NOT WIN32 AND CMAKE_CROSSCOMPILING AND NOT QT_ENABLE_CMAKE_BOOT2QT_TESTS) +if(UNIX AND NOT APPLE AND NOT WIN32 AND CMAKE_CROSSCOMPILING AND NOT QT_ENABLE_CMAKE_BOOT2QT_TESTS + AND NOT QT_BUILD_MINIMAL_ANDROID_MULTI_ABI_TESTS) message(STATUS "Running CMake tests is disabled when cross-compiling to Linux / Boot2Qt.") return() endif() @@ -112,6 +112,58 @@ endif() include("${_Qt6CTestMacros}") +# Test only multi-abi specific functionality when QT_BUILD_MINIMAL_ANDROID_MULTI_ABI_TESTS is ON. +# Qt::Gui is the prerequisite for all Android tests. +if(QT_BUILD_MINIMAL_ANDROID_MULTI_ABI_TESTS AND NOT NO_GUI) + unset(multi_abi_vars) + foreach(abi IN LISTS QT_ANDROID_ABIS) + list(APPEND multi_abi_vars "-DQT_PATH_ANDROID_ABI_${abi}=${QT_PATH_ANDROID_ABI_${abi}}") + endforeach() + if(QT_ANDROID_BUILD_ALL_ABIS) + list(APPEND multi_abi_vars "-DQT_ANDROID_BUILD_ALL_ABIS=${QT_ANDROID_BUILD_ALL_ABIS}") + endif() + + list(APPEND multi_abi_vars "-DQT_HOST_PATH=${QT_HOST_PATH}") + + set(multi_abi_forward_vars + TEST_SINGLE_VALUE_ARG + TEST_SPACES_VALUE_ARG + TEST_LIST_VALUE_ARG + TEST_ESCAPING_VALUE_ARG + ) + string(REPLACE ";" "[[;]]" multi_abi_forward_vars "${multi_abi_forward_vars}") + + set(single_value "TestValue") + set(list_value "TestValue[[;]]TestValue2[[;]]TestValue3") + set(escaping_value "TestValue\\\\[[;]]TestValue2\\\\[[;]]TestValue3") + set(spaces_value "TestValue TestValue2 TestValue3") + _qt_internal_test_expect_pass(test_android_multi_abi_forward_vars + BUILD_OPTIONS + ${multi_abi_vars} + "-DQT_ANDROID_MULTI_ABI_FORWARD_VARS=${multi_abi_forward_vars}" + "-DTEST_SINGLE_VALUE_ARG=${single_value}" + "-DTEST_LIST_VALUE_ARG=${list_value}" + "-DTEST_ESCAPING_VALUE_ARG=${escaping_value}" + "-DTEST_SPACES_VALUE_ARG=${spaces_value}" + ) + + #Run test_android_aar only if the host is Unix and zipinfo is available + find_program(ZIPINFO_EXECUTABLE zipinfo) + if(CMAKE_HOST_UNIX AND ZIPINFO_EXECUTABLE) + _qt_internal_test_expect_pass(test_android_aar + BUILD_OPTIONS + ${multi_abi_vars} + --build-target verify_aar + ) + else() + message(WARNING + "Skipping test_android_aar CMake build test because \ + the host is not Unix or zipinfo is not found") + endif() + + return() +endif() + if(NOT NO_WIDGETS) _qt_internal_test_expect_pass(test_build_simple_widget_app) set(extra_widget_app_options "") @@ -157,8 +209,10 @@ 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_wrap_cpp_moc) _qt_internal_test_expect_pass(test_platform_defs_include) _qt_internal_test_expect_pass(test_qtmainwin_library) @@ -183,6 +237,8 @@ endif() _qt_internal_test_expect_pass(test_multiple_find_package) _qt_internal_test_expect_pass(test_add_resources_delayed_file) _qt_internal_test_expect_pass(test_add_binary_resources_delayed_file BINARY test_add_binary_resources_delayed_file) +_qt_internal_test_expect_pass(test_qt_add_resources_rebuild) +_qt_internal_test_expect_pass(test_resource_without_obj_lib BINARY test_resource_without_obj_lib) if(NOT NO_GUI) _qt_internal_test_expect_pass(test_private_includes) @@ -194,13 +250,12 @@ _qt_internal_test_expect_pass(test_json_plugin_includes) if(NOT NO_GUI) _qt_internal_test_expect_build_fail(test_testlib_no_link_gui) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy + "${CMAKE_CURRENT_SOURCE_DIR}/test_testlib_definitions/main.cpp" + "${CMAKE_CURRENT_BINARY_DIR}/failbuild/test_testlib_no_link_gui/test_testlib_no_link_gui/" + ) endif() -execute_process(COMMAND ${CMAKE_COMMAND} -E copy - "${CMAKE_CURRENT_SOURCE_DIR}/test_testlib_definitions/main.cpp" - "${CMAKE_CURRENT_BINARY_DIR}/failbuild/test_testlib_no_link_gui/test_testlib_no_link_gui/" -) - if (NOT NO_WIDGETS) _qt_internal_test_expect_build_fail(test_testlib_no_link_widgets) execute_process(COMMAND ${CMAKE_COMMAND} -E copy @@ -273,10 +328,11 @@ if(QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX) elseif(QT6_INSTALL_PREFIX) set(qt_install_prefix "${QT6_INSTALL_PREFIX}") endif() -if(INSTALL_BINDIR) - set(qt_install_bin_dir "${INSTALL_BINDIR}") -elseif(QT6_INSTALL_BINS) - set(qt_install_bin_dir "${QT6_INSTALL_BINS}") + +if(INSTALL_LIBEXECDIR) + set(qt_install_libexec_dir "${INSTALL_LIBEXECDIR}") +elseif(QT6_INSTALL_LIBEXECS) + set(qt_install_libexec_dir "${QT6_INSTALL_LIBEXECS}") endif() # Test building and installing a few dummy Qt modules and plugins. @@ -287,7 +343,7 @@ if(is_qt_build_platform) BINARY "${CMAKE_COMMAND}" BINARY_ARGS "-DQT_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}/mockplugins" - -P "${qt_install_prefix}/${qt_install_bin_dir}/qt-cmake-private-install.cmake" + -P "${qt_install_prefix}/${qt_install_libexec_dir}/qt-cmake-private-install.cmake" ) endif() _qt_internal_test_expect_pass(mockplugins ${mockplugins_test_args}) @@ -298,6 +354,12 @@ if(is_qt_build_platform) set_tests_properties(test_import_plugins PROPERTIES FIXTURES_REQUIRED build_mockplugins) endif() +if(NOT NO_GUI) + _qt_internal_test_expect_pass(test_standalone_test + BINARY "${CMAKE_CTEST_COMMAND}" + BINARY_ARGS "-V") +endif() + _qt_internal_test_expect_pass(test_versionless_targets) if(NOT NO_GUI) @@ -332,15 +394,64 @@ set(deploy_args # Need to explicitly specify a writable install prefix. BUILD_OPTIONS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_widgets_app_deployment_installed + NO_RUN_ENVIRONMENT_PLUGIN_PATH ) -# For now, the test should only pass on Windows and macOS shared and static builds and fail on -# other platforms, because there is no support for runtime dependency deployment -# on those platforms. +set(is_desktop_linux FALSE) +if(UNIX AND NOT APPLE AND NOT ANDROID AND NOT CMAKE_CROSSCOMPILING) + set(is_desktop_linux TRUE) +endif() + +# For now, the test should only pass on Windows, macOS and desktop Linux shared and static builds +# and fail on other platforms, because there is no support for runtime dependency deployment on +# those platforms. # With static builds the runtime dependencies are just skipped, but the test should still pass. -if(WIN32 OR (APPLE AND NOT IOS) - OR (UNIX AND NOT APPLE AND NOT ANDROID AND NOT CMAKE_CROSSCOMPILING)) +if(WIN32 OR (APPLE AND NOT IOS) OR is_desktop_linux) _qt_internal_test_expect_pass(${deploy_args}) else() _qt_internal_test_expect_fail(${deploy_args}) endif() + +_qt_internal_test_expect_pass(test_config_expressions) +_qt_internal_test_expect_pass(test_QTP0003) + +if(NOT NO_GUI) + _qt_internal_test_expect_pass(test_collecting_plugins) +endif() + +_qt_internal_test_expect_pass(test_qt_manual_moc) + +# check if the os is opensuse. If it is, we need to skip tests due to CI problems +set(is_opensuse FALSE) +if(UNIX) + if(EXISTS "/etc/os-release") + file(STRINGS "/etc/os-release" os_release_content) + foreach(line IN LISTS os_release_content) + if(line MATCHES "openSUSE" OR line MATCHES "opensuse") + set(is_opensuse TRUE) + break() + endif() + endforeach() + endif() +endif() + +if(NOT QNX AND NOT WASM AND NOT (WIN32 AND QT_BUILD_MINIMAL_STATIC_TESTS) + AND NOT is_opensuse) + # Since our CI machines are slow, ctest --build-and-test buffers the output + # of the configure step of a test, and the fact that we run all the test + # logic in the configure step, we need to divide the tests into smaller + # chunks to avoid CI stdout timeout errors. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/25790 + _qt_internal_test_expect_pass(test_qt_add_ui_common) + _qt_internal_test_expect_pass(test_qt_add_ui_1) + _qt_internal_test_expect_pass(test_qt_add_ui_2) + _qt_internal_test_expect_pass(test_qt_add_ui_3) + _qt_internal_test_expect_pass(test_qt_add_ui_4) + _qt_internal_test_expect_pass(test_qt_add_ui_5) + _qt_internal_test_expect_pass(test_qt_add_ui_6) + _qt_internal_test_expect_pass(test_qt_add_ui_7) + _qt_internal_test_expect_pass(test_qt_add_ui_8) + _qt_internal_test_expect_pass(test_qt_add_ui_9) + _qt_internal_test_expect_pass(test_qt_add_ui_10) +endif() + diff --git a/tests/auto/cmake/mockplugins/.cmake.conf b/tests/auto/cmake/mockplugins/.cmake.conf index edb49ceeb2..6d83b084f7 100644 --- a/tests/auto/cmake/mockplugins/.cmake.conf +++ b/tests/auto/cmake/mockplugins/.cmake.conf @@ -1,3 +1 @@ -set(QT_REPO_MODULE_VERSION "6.5.0") - -set(QT_USE_SYNCQT_CPP TRUE) +set(QT_REPO_MODULE_VERSION "6.9.0") diff --git a/tests/auto/cmake/mockplugins/CMakeLists.txt b/tests/auto/cmake/mockplugins/CMakeLists.txt index 526abedec7..1bde9aedb1 100644 --- a/tests/auto/cmake/mockplugins/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qtsvg.pro. - cmake_minimum_required(VERSION 3.16) include(.cmake.conf) @@ -14,6 +12,8 @@ project(QtMockPlugins ) find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) +qt_internal_project_setup() + find_package(Qt6 ${PROJECT_VERSION} QUIET CONFIG OPTIONAL_COMPONENTS Gui Widgets Xml) qt_build_repo_begin() @@ -29,4 +29,5 @@ add_subdirectory(mock4plugin) add_subdirectory(mock5plugin) add_subdirectory(mock6plugin) +qt_build_repo_post_process() qt_build_repo_end() diff --git a/tests/auto/cmake/mockplugins/mock1plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock1plugin/CMakeLists.txt index ba636e6fe6..5a37ef9ea0 100644 --- a/tests/auto/cmake/mockplugins/mock1plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock1plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock1Plugin + NO_UNITY_BUILD CLASS_NAME QMock1Plugin PLUGIN_TYPE mockplugin SOURCES diff --git a/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.cpp b/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.cpp index 2ee817d80a..a2994c10e3 100644 --- a/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock1plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.h b/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.h index 192b8c0591..324d0c38f4 100644 --- a/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.h +++ b/tests/auto/cmake/mockplugins/mock1plugin/qmock1plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK1PLUGIN_H #define QMOCK1PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mock2plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock2plugin/CMakeLists.txt index acdcd7d7e2..f2705335f5 100644 --- a/tests/auto/cmake/mockplugins/mock2plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock2plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock2Plugin + NO_UNITY_BUILD CLASS_NAME QMock2Plugin PLUGIN_TYPE mockplugin SOURCES diff --git a/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.cpp b/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.cpp index 5b3280e884..8e10797997 100644 --- a/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock2plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.h b/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.h index 4d3765f28c..a1217ff4d6 100644 --- a/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.h +++ b/tests/auto/cmake/mockplugins/mock2plugin/qmock2plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK2PLUGIN_H #define QMOCK2PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mock3plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock3plugin/CMakeLists.txt index 8b8333d2cb..b165353b24 100644 --- a/tests/auto/cmake/mockplugins/mock3plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock3plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock3Plugin + NO_UNITY_BUILD CLASS_NAME QMock3Plugin PLUGIN_TYPE mockplugin SOURCES diff --git a/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.cpp b/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.cpp index b38f854e4b..53090472e0 100644 --- a/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock3plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.h b/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.h index 8143c06c43..3e152784e0 100644 --- a/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.h +++ b/tests/auto/cmake/mockplugins/mock3plugin/qmock3plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK3PLUGIN_H #define QMOCK3PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mock4plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock4plugin/CMakeLists.txt index b988e9b77f..cf09fb294b 100644 --- a/tests/auto/cmake/mockplugins/mock4plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock4plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock4Plugin + NO_UNITY_BUILD CLASS_NAME QMock4Plugin PLUGIN_TYPE mockplugin DEFAULT_IF FALSE diff --git a/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.cpp b/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.cpp index 5deaf7f43f..f2a904182d 100644 --- a/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock4plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.h b/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.h index 3aad9a6cae..1895367575 100644 --- a/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.h +++ b/tests/auto/cmake/mockplugins/mock4plugin/qmock4plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK4PLUGIN_H #define QMOCK4PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mock5plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock5plugin/CMakeLists.txt index 1bd671e97c..1d34cabe1f 100644 --- a/tests/auto/cmake/mockplugins/mock5plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock5plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock5Plugin + NO_UNITY_BUILD CLASS_NAME QMock5Plugin PLUGIN_TYPE mockplugin DEFAULT_IF FALSE diff --git a/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.cpp b/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.cpp index c5b4620516..92ea47690f 100644 --- a/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock5plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.h b/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.h index 5f2c9eeeb9..4b6c95fb23 100644 --- a/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.h +++ b/tests/auto/cmake/mockplugins/mock5plugin/qmock5plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK5PLUGIN_H #define QMOCK5PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mock6plugin/CMakeLists.txt b/tests/auto/cmake/mockplugins/mock6plugin/CMakeLists.txt index 1a1272d878..5d80407d57 100644 --- a/tests/auto/cmake/mockplugins/mock6plugin/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mock6plugin/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(QMock6Plugin + NO_UNITY_BUILD CLASS_NAME QMock6Plugin PLUGIN_TYPE mockauxplugin SOURCES diff --git a/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.cpp b/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.cpp index 4a0329c68a..9dd9e02f2a 100644 --- a/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.cpp +++ b/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qmock6plugin.h" QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.h b/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.h index e2a3eb10c5..5278d67960 100644 --- a/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.h +++ b/tests/auto/cmake/mockplugins/mock6plugin/qmock6plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCK6PLUGIN_H #define QMOCK6PLUGIN_H diff --git a/tests/auto/cmake/mockplugins/mockplugins1/CMakeLists.txt b/tests/auto/cmake/mockplugins/mockplugins1/CMakeLists.txt index 933f6dde5d..adba60e42d 100644 --- a/tests/auto/cmake/mockplugins/mockplugins1/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mockplugins1/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(MockPlugins1 + NO_UNITY_BUILD PLUGIN_TYPES mockplugin SOURCES qmockplugin.h diff --git a/tests/auto/cmake/mockplugins/mockplugins1/fake.cpp b/tests/auto/cmake/mockplugins/mockplugins1/fake.cpp index f71e2748a2..6cdf6a09ce 100644 --- a/tests/auto/cmake/mockplugins/mockplugins1/fake.cpp +++ b/tests/auto/cmake/mockplugins/mockplugins1/fake.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QtGlobal> diff --git a/tests/auto/cmake/mockplugins/mockplugins1/qmockplugin.h b/tests/auto/cmake/mockplugins/mockplugins1/qmockplugin.h index ee9db067c5..d4dcea5c20 100644 --- a/tests/auto/cmake/mockplugins/mockplugins1/qmockplugin.h +++ b/tests/auto/cmake/mockplugins/mockplugins1/qmockplugin.h @@ -1,11 +1,11 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCKPLUGIN_H #define QMOCKPLUGIN_H -#include <QString> -#include <QtPlugin> +#include <QtCore/QString> +#include <QtCore/QtPlugin> QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/mockplugins/mockplugins2/CMakeLists.txt b/tests/auto/cmake/mockplugins/mockplugins2/CMakeLists.txt index 62fd34e90b..a797206cd6 100644 --- a/tests/auto/cmake/mockplugins/mockplugins2/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mockplugins2/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(MockPlugins2 + NO_UNITY_BUILD SOURCES fake.cpp LIBRARIES diff --git a/tests/auto/cmake/mockplugins/mockplugins2/fake.cpp b/tests/auto/cmake/mockplugins/mockplugins2/fake.cpp index 2ad5f6144a..9256ef181f 100644 --- a/tests/auto/cmake/mockplugins/mockplugins2/fake.cpp +++ b/tests/auto/cmake/mockplugins/mockplugins2/fake.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QtGlobal> diff --git a/tests/auto/cmake/mockplugins/mockplugins3/CMakeLists.txt b/tests/auto/cmake/mockplugins/mockplugins3/CMakeLists.txt index 5df9c1b685..b8e3c54535 100644 --- a/tests/auto/cmake/mockplugins/mockplugins3/CMakeLists.txt +++ b/tests/auto/cmake/mockplugins/mockplugins3/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(MockPlugins3 + NO_UNITY_BUILD PLUGIN_TYPES mockauxplugin SOURCES qmockauxplugin.h diff --git a/tests/auto/cmake/mockplugins/mockplugins3/fake.cpp b/tests/auto/cmake/mockplugins/mockplugins3/fake.cpp index 5a3c187143..9ca82b9ef7 100644 --- a/tests/auto/cmake/mockplugins/mockplugins3/fake.cpp +++ b/tests/auto/cmake/mockplugins/mockplugins3/fake.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QtGlobal> diff --git a/tests/auto/cmake/mockplugins/mockplugins3/qmockauxplugin.h b/tests/auto/cmake/mockplugins/mockplugins3/qmockauxplugin.h index 80dcddf993..599c3ecbb4 100644 --- a/tests/auto/cmake/mockplugins/mockplugins3/qmockauxplugin.h +++ b/tests/auto/cmake/mockplugins/mockplugins3/qmockauxplugin.h @@ -1,11 +1,11 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QMOCKAUXPLUGIN_H #define QMOCKAUXPLUGIN_H -#include <QString> -#include <QtPlugin> +#include <QtCore/QString> +#include <QtCore/QtPlugin> QT_BEGIN_NAMESPACE diff --git a/tests/auto/cmake/test(needsquoting)dirname/mywidget.cpp b/tests/auto/cmake/test(needsquoting)dirname/mywidget.cpp index c0e3870c91..da7f51d286 100644 --- a/tests/auto/cmake/test(needsquoting)dirname/mywidget.cpp +++ b/tests/auto/cmake/test(needsquoting)dirname/mywidget.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mywidget.h" #include "ui_mywidget.h" diff --git a/tests/auto/cmake/test(needsquoting)dirname/mywidget.h b/tests/auto/cmake/test(needsquoting)dirname/mywidget.h index 8b8e2ee350..4517670b56 100644 --- a/tests/auto/cmake/test(needsquoting)dirname/mywidget.h +++ b/tests/auto/cmake/test(needsquoting)dirname/mywidget.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYWIDGET_H #define MYWIDGET_H diff --git a/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp index 52732df425..7938bbb863 100644 --- a/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp +++ b/tests/auto/cmake/test_QFINDTESTDATA/tests/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 Stephen Kelly <steveire@gmail,com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QCoreApplication> #include <QtTest/QTest> diff --git a/tests/auto/cmake/test_QTBUG-63422/mywidget.cpp b/tests/auto/cmake/test_QTBUG-63422/mywidget.cpp index 0657edf2b2..adbfcd35e8 100644 --- a/tests/auto/cmake/test_QTBUG-63422/mywidget.cpp +++ b/tests/auto/cmake/test_QTBUG-63422/mywidget.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Kevin Funk <kevin.funk@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mywidget.h" #include "ui_mywidget.h" diff --git a/tests/auto/cmake/test_QTBUG-63422/mywidget.h b/tests/auto/cmake/test_QTBUG-63422/mywidget.h index 203a3876ed..f975ae2fa3 100644 --- a/tests/auto/cmake/test_QTBUG-63422/mywidget.h +++ b/tests/auto/cmake/test_QTBUG-63422/mywidget.h @@ -1,5 +1,5 @@ // Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Kevin Funk <kevin.funk@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYWIDGET_H #define MYWIDGET_H diff --git a/tests/auto/cmake/test_QTP0003/CMakeLists.txt b/tests/auto/cmake/test_QTP0003/CMakeLists.txt new file mode 100644 index 0000000000..8dda76fdb0 --- /dev/null +++ b/tests/auto/cmake/test_QTP0003/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_QTP0003) + +find_package(Qt6 COMPONENTS Core REQUIRED) + +if(QT6_IS_SHARED_LIBS_BUILD) + set(qt_build_type "SHARED_LIBRARY") +else() + set(qt_build_type "STATIC_LIBRARY") +endif() + +set(BUILD_SHARED_LIBS ON) +qt6_add_library(MyLib source.cpp) +get_target_property(type MyLib TYPE) +if(NOT "${type}" STREQUAL "${qt_build_type}") + message(FATAL_ERROR "The library uses the default type different from Qt build type when" + "QTP0003 is not set") +endif() + +set(BUILD_SHARED_LIBS OFF) +qt6_add_library(MyLib2 source.cpp) +get_target_property(type MyLib2 TYPE) +if(NOT "${type}" STREQUAL "${qt_build_type}") + message(FATAL_ERROR "The library uses the default type different from Qt build type when" + "QTP0003 is not set") +endif() + +set(BUILD_SHARED_LIBS ON) +qt_policy(SET QTP0003 OLD) +qt6_add_library(MyLib3 source.cpp) +get_target_property(type MyLib3 TYPE) +if(NOT "${type}" STREQUAL "${qt_build_type}") + message(FATAL_ERROR "The library uses the default type different from Qt build type when" + "QTP0003 is set to OLD") +endif() + +set(BUILD_SHARED_LIBS OFF) +qt_policy(SET QTP0003 OLD) +qt6_add_library(MyLib4 source.cpp) +get_target_property(type MyLib4 TYPE) +if(NOT "${type}" STREQUAL "${qt_build_type}") + message(FATAL_ERROR "The library uses the default type different from Qt build type when" + "QTP0003 is set to OLD") +endif() + +set(BUILD_SHARED_LIBS ON) +qt_policy(SET QTP0003 NEW) +qt6_add_library(MyLib5 source.cpp) +get_target_property(type MyLib5 TYPE) +if(NOT "${type}" STREQUAL "SHARED_LIBRARY") + message(FATAL_ERROR "The library doesn't consider the BUILD_SHARED_LIBS when" + "QTP0003 is set to NEW") +endif() + +set(BUILD_SHARED_LIBS OFF) +qt_policy(SET QTP0003 NEW) +qt6_add_library(MyLib6 source.cpp) +get_target_property(type MyLib6 TYPE) +if(NOT "${type}" STREQUAL "STATIC_LIBRARY") + message(FATAL_ERROR "The library doesn't consider the BUILD_SHARED_LIBS when" + "QTP0003 is set to NEW") +endif() diff --git a/tests/auto/cmake/test_QTP0003/source.cpp b/tests/auto/cmake/test_QTP0003/source.cpp new file mode 100644 index 0000000000..273d7dade4 --- /dev/null +++ b/tests/auto/cmake/test_QTP0003/source.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +class Noop {}; diff --git a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp index 7911bf74e7..ae34d13ff1 100644 --- a/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp +++ b/tests/auto/cmake/test_QT_TESTCASE_BUILDDIR/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QCoreApplication> #include <QtTest/QTest> diff --git a/tests/auto/cmake/test_add_big_resource/myobject.cpp b/tests/auto/cmake/test_add_big_resource/myobject.cpp index 12434f4689..34c2ccc6bf 100644 --- a/tests/auto/cmake/test_add_big_resource/myobject.cpp +++ b/tests/auto/cmake/test_add_big_resource/myobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "myobject.h" diff --git a/tests/auto/cmake/test_add_big_resource/myobject.h b/tests/auto/cmake/test_add_big_resource/myobject.h index 917ae9fd24..87d7bfa3df 100644 --- a/tests/auto/cmake/test_add_big_resource/myobject.h +++ b/tests/auto/cmake/test_add_big_resource/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYOBJECT_H #define MYOBJECT_H diff --git a/tests/auto/cmake/test_add_binary_resources_delayed_file/main.cpp b/tests/auto/cmake/test_add_binary_resources_delayed_file/main.cpp index b8b6ec7717..f0bc74403c 100644 --- a/tests/auto/cmake/test_add_binary_resources_delayed_file/main.cpp +++ b/tests/auto/cmake/test_add_binary_resources_delayed_file/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2015 André Klitzing <aklitzing@gmail.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QFile> #include <QResource> diff --git a/tests/auto/cmake/test_add_resource_options/myobject.cpp b/tests/auto/cmake/test_add_resource_options/myobject.cpp index 2a90499e6a..14e00e789a 100644 --- a/tests/auto/cmake/test_add_resource_options/myobject.cpp +++ b/tests/auto/cmake/test_add_resource_options/myobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "myobject.h" diff --git a/tests/auto/cmake/test_add_resource_options/myobject.h b/tests/auto/cmake/test_add_resource_options/myobject.h index 917ae9fd24..87d7bfa3df 100644 --- a/tests/auto/cmake/test_add_resource_options/myobject.h +++ b/tests/auto/cmake/test_add_resource_options/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYOBJECT_H #define MYOBJECT_H diff --git a/tests/auto/cmake/test_add_resource_prefix/CMakeLists.txt b/tests/auto/cmake/test_add_resource_prefix/CMakeLists.txt new file mode 100644 index 0000000000..65faa4cb09 --- /dev/null +++ b/tests/auto/cmake/test_add_resource_prefix/CMakeLists.txt @@ -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) diff --git a/tests/auto/cmake/test_add_resource_prefix/main.cpp b/tests/auto/cmake/test_add_resource_prefix/main.cpp new file mode 100644 index 0000000000..1a8b37715b --- /dev/null +++ b/tests/auto/cmake/test_add_resource_prefix/main.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#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" 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. diff --git a/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.cpp b/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.cpp index 00817d496d..a8f2be6955 100644 --- a/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.cpp +++ b/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "leaf_lib.h" diff --git a/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.h b/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.h index 614ebd1abc..efa03e8a5e 100644 --- a/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.h +++ b/tests/auto/cmake/test_add_resources_big_resources/intermediate_lib.h @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once diff --git a/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.cpp b/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.cpp index 0dc07784e9..8363ceec0a 100644 --- a/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.cpp +++ b/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/qfile.h> diff --git a/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.h b/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.h index 9a6c631c1d..71195a7c74 100644 --- a/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.h +++ b/tests/auto/cmake/test_add_resources_big_resources/leaf_lib.h @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once diff --git a/tests/auto/cmake/test_add_resources_big_resources/main.cpp b/tests/auto/cmake/test_add_resources_big_resources/main.cpp index 5df2b0e5a7..8ff0c4f54c 100644 --- a/tests/auto/cmake/test_add_resources_big_resources/main.cpp +++ b/tests/auto/cmake/test_add_resources_big_resources/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "intermediate_lib.h" diff --git a/tests/auto/cmake/test_add_resources_binary_generated/main.cpp b/tests/auto/cmake/test_add_resources_binary_generated/main.cpp index 906232ca19..73177555d4 100644 --- a/tests/auto/cmake/test_add_resources_binary_generated/main.cpp +++ b/tests/auto/cmake/test_add_resources_binary_generated/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QFile> #include <QResource> diff --git a/tests/auto/cmake/test_add_resources_delayed_file/main.cpp b/tests/auto/cmake/test_add_resources_delayed_file/main.cpp index 9f722faff4..1a1596dd6a 100644 --- a/tests/auto/cmake/test_add_resources_delayed_file/main.cpp +++ b/tests/auto/cmake/test_add_resources_delayed_file/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qglobal.h> diff --git a/tests/auto/cmake/test_android_aar/CMakeLists.txt b/tests/auto/cmake/test_android_aar/CMakeLists.txt new file mode 100644 index 0000000000..88cd5abf23 --- /dev/null +++ b/tests/auto/cmake/test_android_aar/CMakeLists.txt @@ -0,0 +1,54 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_android_aar) + +find_package(Qt6 COMPONENTS Core Gui REQUIRED) + +qt6_add_executable(test_aar main.cpp) + +# To support opening the project in QtCreator +if($CACHE{QT_USE_TARGET_ANDROID_BUILD_DIR}) + set(TARGET_ANDROID_BUILD_DIR ${CMAKE_BINARY_DIR}/android-build-test_aar) +else() + set(TARGET_ANDROID_BUILD_DIR ${CMAKE_BINARY_DIR}/android-build) +endif() + +# Add common libs for available ABIs that should be present in the aar package in a list +unset(aar_content_filepaths_to_verify) +foreach(abi IN LISTS QT_ANDROID_ABIS) + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libQt6Core_${abi}.so") + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libQt6Gui_${abi}.so") + list(APPEND aar_content_filepaths_to_verify + "jni/${abi}/libplugins_platforms_qtforandroid_${abi}.so") + list(APPEND aar_content_filepaths_to_verify "jni/${abi}/libtest_aar_${abi}.so") +endforeach() + +# Add a few ABI independent file that should be present in the aar package in a list +list(APPEND aar_content_filepaths_to_verify "libs/Qt6Android.jar") +list(APPEND aar_content_filepaths_to_verify "res/xml/qtprovider_paths.xml") +list(APPEND aar_content_filepaths_to_verify "AndroidManifest.xml") +list(JOIN aar_content_filepaths_to_verify "|" grep_pattern) + +# The overall number of lines we should expect to be filtered by grep regex +list(LENGTH aar_content_filepaths_to_verify expected_file_count) + +set(zipinfo_command "zipinfo -1 ${TARGET_ANDROID_BUILD_DIR}/test_aar.aar") + +# Runs zipinfo on the aar package, greps and outputs the number of matching lines +# and finally compares the expected number of lines with the output +add_custom_target(verify_aar + bash -c "${zipinfo_command} \ + | grep -Ecx '${grep_pattern}' \ + | grep -xq ${expected_file_count} \ + || { echo 'Error: The aar package is missing at least one file.'; exit 1; };" + COMMENT "Verifying aar package content" + VERBATIM +) + +# Build aar package before verification +add_dependencies(verify_aar aar) + +target_link_libraries(test_aar PRIVATE Qt::Core Qt::Gui) diff --git a/tests/auto/cmake/test_android_aar/main.cpp b/tests/auto/cmake/test_android_aar/main.cpp new file mode 100644 index 0000000000..90df9ee937 --- /dev/null +++ b/tests/auto/cmake/test_android_aar/main.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) { return 0; } diff --git a/tests/auto/cmake/test_android_multi_abi_forward_vars/CMakeLists.txt b/tests/auto/cmake/test_android_multi_abi_forward_vars/CMakeLists.txt new file mode 100644 index 0000000000..0f84d5ff3e --- /dev/null +++ b/tests/auto/cmake/test_android_multi_abi_forward_vars/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_android_multi_abi_forward_vars) + +find_package(Qt6 COMPONENTS Core Gui REQUIRED) + +if(NOT TEST_SINGLE_VALUE_ARG STREQUAL "TestValue") + message(FATAL_ERROR + "TEST_SINGLE_VALUE_ARG is not valid: ${TEST_SINGLE_VALUE_ARG}") +endif() + +if(NOT TEST_LIST_VALUE_ARG STREQUAL "TestValue;TestValue2;TestValue3") + message(FATAL_ERROR + "TEST_LIST_VALUE_ARG is not valid: ${TEST_LIST_VALUE_ARG}") +endif() + +if(NOT TEST_ESCAPING_VALUE_ARG STREQUAL "TestValue\;TestValue2\;TestValue3") + message(FATAL_ERROR + "TEST_ESCAPING_VALUE_ARG is not valid: ${TEST_ESCAPING_VALUE_ARG}") +endif() + +if(NOT TEST_SPACES_VALUE_ARG STREQUAL "TestValue TestValue2 TestValue3") + message(FATAL_ERROR + "TEST_SPACES_VALUE_ARG is not valid: ${TEST_SPACES_VALUE_ARG}") +endif() + +# Make sure that ABI external projects are created +qt6_add_executable(test_executable main.cpp) + +target_link_libraries(test_executable PRIVATE Qt::Core Qt::Gui) diff --git a/tests/auto/cmake/test_android_multi_abi_forward_vars/main.cpp b/tests/auto/cmake/test_android_multi_abi_forward_vars/main.cpp new file mode 100644 index 0000000000..304c7b20dc --- /dev/null +++ b/tests/auto/cmake/test_android_multi_abi_forward_vars/main.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) { return 0; } diff --git a/tests/auto/cmake/test_build_simple_widget_app/main.cpp b/tests/auto/cmake/test_build_simple_widget_app/main.cpp index 734c72a263..b4502fa05a 100644 --- a/tests/auto/cmake/test_build_simple_widget_app/main.cpp +++ b/tests/auto/cmake/test_build_simple_widget_app/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> #include <QWidget> diff --git a/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt b/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt new file mode 100644 index 0000000000..246acd4c71 --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_collecting_plugins + VERSION + "${CMAKE_Core_MODULE_MAJOR_VERSION}.${CMAKE_Core_MODULE_MINOR_VERSION}.${CMAKE_Core_MODULE_PATCH_VERSION}") + +find_package(Qt6 COMPONENTS Core Gui BuildInternals REQUIRED) + +qt_prepare_standalone_project() + +qt_internal_add_plugin(QTestImagePlugin + SHARED + PLUGIN_TYPE imageformats + SOURCES + plugin.cpp + LIBRARIES + Qt6::Gui + SKIP_INSTALL # Make sure that we do not package this plugin +) + +qt_add_executable(TestExecutable main.cpp) +target_link_libraries(TestExecutable PRIVATE Qt6::Gui) + +__qt_internal_collect_plugin_targets_from_dependencies(TestExecutable plugin_targets) + +if(NOT "QTestImagePlugin" IN_LIST plugin_targets) + message(FATAL_ERROR "QTestImagePlugin plugin is missing") +endif() diff --git a/tests/auto/cmake/test_collecting_plugins/main.cpp b/tests/auto/cmake/test_collecting_plugins/main.cpp new file mode 100644 index 0000000000..09225de205 --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/main.cpp @@ -0,0 +1,7 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main(int, char *[]) +{ + return 0; +} diff --git a/tests/auto/cmake/test_collecting_plugins/plugin.cpp b/tests/auto/cmake/test_collecting_plugins/plugin.cpp new file mode 100644 index 0000000000..f844d86c4e --- /dev/null +++ b/tests/auto/cmake/test_collecting_plugins/plugin.cpp @@ -0,0 +1,18 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <qimageiohandler.h> + +class TestImagePlugin : public QImageIOPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface") +public: + Capabilities capabilities(QIODevice *, const QByteArray &) const override { return {}; } + QImageIOHandler *create(QIODevice *, const QByteArray & = QByteArray()) const override + { + return nullptr; + } +}; + +#include "plugin.moc" diff --git a/tests/auto/cmake/test_concurrent_module/main.cpp b/tests/auto/cmake/test_concurrent_module/main.cpp index afecfadf27..9412c60638 100644 --- a/tests/auto/cmake/test_concurrent_module/main.cpp +++ b/tests/auto/cmake/test_concurrent_module/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtConcurrent> #include <QtConcurrent/QtConcurrent> diff --git a/tests/auto/cmake/test_config_expressions/CMakeLists.txt b/tests/auto/cmake/test_config_expressions/CMakeLists.txt new file mode 100644 index 0000000000..e3863b738a --- /dev/null +++ b/tests/auto/cmake/test_config_expressions/CMakeLists.txt @@ -0,0 +1,134 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_config_expressions) + +find_package(Qt6 REQUIRED) +include(QtFeature) + +function(assert expected_value) + set(expression ${ARGN}) + qt_evaluate_config_expression(result ${expression}) + if(NOT "${result}" STREQUAL "${expected_value}") + message(FATAL_ERROR + "Unexpected value '${result}' when evaluating expression '${expression}'.") + endif() +endfunction() + +function(assert_T) + assert(ON ${ARGN}) +endfunction() + +function(assert_F) + assert(OFF ${ARGN}) +endfunction() + +function(expect_failure expected_value) + set(expression ${ARGN}) + qt_evaluate_config_expression(result ${expression}) + if("${result}" STREQUAL "${expected_value}") + message(FATAL_ERROR + "Expression '${expression}' unexpectedly evaluated to the correct value '${result}'.") + endif() +endfunction() + +function(expect_failure_T) + expect_failure(ON ${ARGN}) +endfunction() + +function(expect_failure_F) + expect_failure(OFF ${ARGN}) +endfunction() + +assert_T(ON) +assert_T(TRUE) +assert_F(OFF) +assert_F(FALSE) + +assert_T(NOT FALSE) +assert_F(NOT TRUE) + +assert_T(TRUE OR TRUE) +assert_T(TRUE OR FALSE) +assert_T(FALSE OR TRUE) +assert_F(FALSE OR FALSE) + +assert_T(TRUE AND TRUE) +assert_F(TRUE AND FALSE) +assert_F(FALSE AND TRUE) +assert_F(FALSE AND FALSE) + +# string comparison +set(str1 "foo") +set(str2 "bar") +assert_T(str1 STREQUAL "foo") +assert_T(str1 STREQUAL 'foo') +expect_failure_T(str1 STREQUAL str1) # variable on rhs not supported +expect_failure_T("foo" STREQUAL "foo") # literal on lhs not supported +expect_failure_T('foo' STREQUAL 'foo') # literal on lhs not supported + +# comparison with empty string +set(empty_string "") +assert_T(empty_string STREQUAL '') +assert_F(empty_string STREQUAL "x") + +# string matching +set(processor ppc64) +assert_T(${processor} MATCHES "(ppc|ppc64)$") +assert_F(${processor} MATCHES "i[3-6]86$") + +# logical operators and parentheses +set(A TRUE) +set(B FALSE) +set(C TRUE) +assert_F(B OR B) +assert_F(A AND B) +assert_T(A AND (B OR C)) +assert_T((A AND B) OR C) +assert_T((A AND B) OR (NOT B AND C)) +assert_F(NOT (B OR C)) +assert_T(NOT (A AND B)) +assert_F(NOT (B OR C)) + +# target check +set(lib1_cpp "${CMAKE_CURRENT_BINARY_DIR}/lib1.cpp") +file(WRITE "${lib1_cpp}" "int foo() { return 42; }") +add_library(lib1 STATIC EXCLUDE_FROM_ALL "${lib1_cpp}") +assert_T(TARGET lib1) +assert_F(TARGET does_not_exist) + +# IN_LIST +set(primary_colors red yellow blue) +assert_T(yellow IN_LIST primary_colors) +assert_F(mauve IN_LIST primary_colors) + +# more complex string check from a real world feature +set(INPUT_xcb "") +set(INPUT_xkbcommon no) +assert_F(NOT INPUT_xcb STREQUAL '' AND ( NOT INPUT_xcb STREQUAL 'no' ) + AND INPUT_xkbcommon STREQUAL 'no') +set(INPUT_xcb no) +set(INPUT_xkbcommon no) +assert_F(NOT INPUT_xcb STREQUAL '' AND ( NOT INPUT_xcb STREQUAL 'no' ) + AND INPUT_xkbcommon STREQUAL 'no') +set(INPUT_xcb yes) +set(INPUT_xkbcommon no) +assert_T(NOT INPUT_xcb STREQUAL '' AND ( NOT INPUT_xcb STREQUAL 'no' ) + AND INPUT_xkbcommon STREQUAL 'no') +set(INPUT_xcb no) +set(INPUT_xkbcommon yes) +assert_F(NOT INPUT_xcb STREQUAL '' AND ( NOT INPUT_xcb STREQUAL 'no' ) + AND INPUT_xkbcommon STREQUAL 'no') + +set(FEATURE_shared ON) +set(FEATURE_debug ON) +set(FEATURE_debug_and_release OFF) +set(FEATURE_force_debug_info OFF) +set(TEST_separate_debug_info ON) +assert_T( + ( FEATURE_shared ) + AND ( FEATURE_debug OR FEATURE_debug_and_release OR FEATURE_force_debug_info ) + AND ( MSVC OR APPLE OR TEST_separate_debug_info ) +) diff --git a/tests/auto/cmake/test_dbus_module/mydbusobject.cpp b/tests/auto/cmake/test_dbus_module/mydbusobject.cpp index 356b09d2fa..c9420812b4 100644 --- a/tests/auto/cmake/test_dbus_module/mydbusobject.cpp +++ b/tests/auto/cmake/test_dbus_module/mydbusobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mydbusobject.h" #include "mydbusobjectadaptor.h" diff --git a/tests/auto/cmake/test_dbus_module/mydbusobject.h b/tests/auto/cmake/test_dbus_module/mydbusobject.h index 3559ecd4dc..8a95c99f04 100644 --- a/tests/auto/cmake/test_dbus_module/mydbusobject.h +++ b/tests/auto/cmake/test_dbus_module/mydbusobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYDBUSOBJECT_H #define MYDBUSOBJECT_H diff --git a/tests/auto/cmake/test_dependent_modules/mywidget.cpp b/tests/auto/cmake/test_dependent_modules/mywidget.cpp index c0e3870c91..da7f51d286 100644 --- a/tests/auto/cmake/test_dependent_modules/mywidget.cpp +++ b/tests/auto/cmake/test_dependent_modules/mywidget.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mywidget.h" #include "ui_mywidget.h" diff --git a/tests/auto/cmake/test_dependent_modules/mywidget.h b/tests/auto/cmake/test_dependent_modules/mywidget.h index 8b8e2ee350..4517670b56 100644 --- a/tests/auto/cmake/test_dependent_modules/mywidget.h +++ b/tests/auto/cmake/test_dependent_modules/mywidget.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYWIDGET_H #define MYWIDGET_H diff --git a/tests/auto/cmake/test_egl_lib/main.cpp b/tests/auto/cmake/test_egl_lib/main.cpp index 39d4d8b14c..b5faa46dd3 100644 --- a/tests/auto/cmake/test_egl_lib/main.cpp +++ b/tests/auto/cmake/test_egl_lib/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <EGL/egl.h> diff --git a/tests/auto/cmake/test_generating_cpp_exports/.cmake.conf b/tests/auto/cmake/test_generating_cpp_exports/.cmake.conf index 377be0059e..6d83b084f7 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/.cmake.conf +++ b/tests/auto/cmake/test_generating_cpp_exports/.cmake.conf @@ -1 +1 @@ -set(QT_REPO_MODULE_VERSION "6.5.0") +set(QT_REPO_MODULE_VERSION "6.9.0") diff --git a/tests/auto/cmake/test_generating_cpp_exports/CMakeLists.txt b/tests/auto/cmake/test_generating_cpp_exports/CMakeLists.txt index 3de368ba1a..564d23ca05 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/CMakeLists.txt +++ b/tests/auto/cmake/test_generating_cpp_exports/CMakeLists.txt @@ -13,10 +13,12 @@ project(TestGeneratingCppExports ) find_package(Qt6 COMPONENTS Core BuildInternals Test CONFIG REQUIRED) +qt_internal_project_setup() qt_build_repo_begin() add_subdirectory(test_autogenerating_cpp_exports) add_subdirectory(test_autogenerating_cpp_exports_custom_name) +qt_build_repo_post_process() qt_build_repo_end() diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/CMakeLists.txt b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/CMakeLists.txt index 53cf02acaf..f1cc6906f8 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/CMakeLists.txt +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(TestAutogeneratingCppExports - GENERATE_CPP_EXPORTS + NO_UNITY_BUILD SOURCES module_api.h module_api.cpp @@ -18,3 +18,4 @@ qt_internal_extend_target(TestAutogeneratingCppExports add_executable(TestAutogeneratingCppExportsApp use_api.cpp) target_link_libraries(TestAutogeneratingCppExportsApp PRIVATE TestAutogeneratingCppExports) +set_target_properties(TestAutogeneratingCppExportsApp PROPERTIES UNITY_BUILD OFF) diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.cpp b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.cpp index 53eab3ef6f..e77895e719 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.cpp +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "module_api.h" diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.h b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.h index a6c20fb402..6c8112c617 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.h +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/module_api.h @@ -1,9 +1,14 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MODULE_API_H #define MODULE_API_H +#if 0 +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif + #include <QtTestAutogeneratingCppExports/qttestautogeneratingcppexportsexports.h> struct Q_TESTAUTOGENERATINGCPPEXPORTS_EXPORT TestApi diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/use_api.cpp b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/use_api.cpp index 5bce4e524e..f84931300f 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/use_api.cpp +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports/use_api.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "module_api.h" diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/CMakeLists.txt b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/CMakeLists.txt index d203fd6b87..87a83bd013 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/CMakeLists.txt +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(TestAutogeneratingCppExportsCustomName - GENERATE_CPP_EXPORTS + NO_UNITY_BUILD CPP_EXPORT_HEADER_BASE_NAME "customname_exports" SOURCES @@ -20,3 +20,4 @@ qt_internal_extend_target(TestAutogeneratingCppExportsCustomName add_executable(testapp2 use_api.cpp) target_link_libraries(testapp2 PRIVATE TestAutogeneratingCppExportsCustomName) +set_target_properties(testapp2 PROPERTIES UNITY_BUILD OFF) diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.cpp b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.cpp index 53eab3ef6f..e77895e719 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.cpp +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "module_api.h" diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.h b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.h index 961a631c80..62c1b31ac4 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.h +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/module_api.h @@ -1,9 +1,14 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MODULE_API_H #define MODULE_API_H +#if 0 +#pragma qt_sync_skip_header_check +#pragma qt_sync_stop_processing +#endif + #include <QtTestAutogeneratingCppExportsCustomName/customname_exports.h> struct Q_TESTAUTOGENERATINGCPPEXPORTSCUSTOMNAME_EXPORT TestApi diff --git a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/use_api.cpp b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/use_api.cpp index 5bce4e524e..f84931300f 100644 --- a/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/use_api.cpp +++ b/tests/auto/cmake/test_generating_cpp_exports/test_autogenerating_cpp_exports_custom_name/use_api.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "module_api.h" diff --git a/tests/auto/cmake/test_import_plugins/main.cpp b/tests/auto/cmake/test_import_plugins/main.cpp index 8de124c41d..69293f3abd 100644 --- a/tests/auto/cmake/test_import_plugins/main.cpp +++ b/tests/auto/cmake/test_import_plugins/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2018 Kitware, Inc. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QList> #include <QPluginLoader> diff --git a/tests/auto/cmake/test_interface/main.cpp b/tests/auto/cmake/test_interface/main.cpp index a8f072aff3..56b442a4ce 100644 --- a/tests/auto/cmake/test_interface/main.cpp +++ b/tests/auto/cmake/test_interface/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QApplication> diff --git a/tests/auto/cmake/test_interface/mainwindow.cpp b/tests/auto/cmake/test_interface/mainwindow.cpp index 878265f9c3..2fec6400f6 100644 --- a/tests/auto/cmake/test_interface/mainwindow.cpp +++ b/tests/auto/cmake/test_interface/mainwindow.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "mainwindow.h" diff --git a/tests/auto/cmake/test_interface/mainwindow.h b/tests/auto/cmake/test_interface/mainwindow.h index 1f938d2bd9..345c4f69e9 100644 --- a/tests/auto/cmake/test_interface/mainwindow.h +++ b/tests/auto/cmake/test_interface/mainwindow.h @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/tests/auto/cmake/test_interface/widget_test/main.cpp b/tests/auto/cmake/test_interface/widget_test/main.cpp index e6a8ab5fe9..0a47f43d84 100644 --- a/tests/auto/cmake/test_interface/widget_test/main.cpp +++ b/tests/auto/cmake/test_interface/widget_test/main.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QString> #include <QWidget> diff --git a/tests/auto/cmake/test_interface_link_libraries/main.cpp b/tests/auto/cmake/test_interface_link_libraries/main.cpp index 75e6f22db0..7d4ca031db 100644 --- a/tests/auto/cmake/test_interface_link_libraries/main.cpp +++ b/tests/auto/cmake/test_interface_link_libraries/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "somelib.h" diff --git a/tests/auto/cmake/test_interface_link_libraries/somelib.cpp b/tests/auto/cmake/test_interface_link_libraries/somelib.cpp index 106f534bb2..de51a8e60f 100644 --- a/tests/auto/cmake/test_interface_link_libraries/somelib.cpp +++ b/tests/auto/cmake/test_interface_link_libraries/somelib.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "somelib.h" diff --git a/tests/auto/cmake/test_interface_link_libraries/somelib.h b/tests/auto/cmake/test_interface_link_libraries/somelib.h index 828937c13c..d2f0cfd554 100644 --- a/tests/auto/cmake/test_interface_link_libraries/somelib.h +++ b/tests/auto/cmake/test_interface_link_libraries/somelib.h @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef SOMELIB_H #define SOMELIB_H diff --git a/tests/auto/cmake/test_json_plugin_includes/plugin.cpp b/tests/auto/cmake/test_json_plugin_includes/plugin.cpp index 8979c56b77..5554fe737a 100644 --- a/tests/auto/cmake/test_json_plugin_includes/plugin.cpp +++ b/tests/auto/cmake/test_json_plugin_includes/plugin.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "plugin.h" diff --git a/tests/auto/cmake/test_json_plugin_includes/plugin.h b/tests/auto/cmake/test_json_plugin_includes/plugin.h index 36e5eb55b2..7e3e9b4569 100644 --- a/tests/auto/cmake/test_json_plugin_includes/plugin.h +++ b/tests/auto/cmake/test_json_plugin_includes/plugin.h @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef JSON_TEST_PLUGIN_H #define JSON_TEST_PLUGIN_H diff --git a/tests/auto/cmake/test_moc_macro_target/CMakeLists.txt b/tests/auto/cmake/test_moc_macro_target/CMakeLists.txt index 1af937bc10..f9ca294bd2 100644 --- a/tests/auto/cmake/test_moc_macro_target/CMakeLists.txt +++ b/tests/auto/cmake/test_moc_macro_target/CMakeLists.txt @@ -14,7 +14,14 @@ qt_generate_moc(main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc" TARGET QtGenerateMacroTest ) +list(APPEND CMAKE_AUTOMOC_MACRO_NAMES MySpecialMacro) add_executable(QtGenerateMacroTest main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc") +get_target_property(current_macros QtGenerateMacroTest AUTOMOC_MACRO_NAMES) + +if(NOT "${CMAKE_AUTOMOC_MACRO_NAMES}" STREQUAL "${current_macros}") + message(FATAL_ERROR "Expected ${CMAKE_AUTOMOC_MACRO_NAMES} but received ${current_macros}") +endif() + target_include_directories(QtGenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface") target_link_libraries(QtGenerateMacroTest PRIVATE Qt6::Core) @@ -24,3 +31,25 @@ qt_wrap_cpp(moc_file mywrapobject.h add_executable(QtWrapMacroTest main_wrap_test.cpp ${moc_file}) target_include_directories(QtWrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface") target_link_libraries(QtWrapMacroTest PRIVATE Qt::Core) + +target_compile_definitions(QtWrapMacroTest PRIVATE "$<$<BOOL:TRUE>:MY_OPTION>" + "$<$<BOOL:TRUE>:DEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int$<COMMA> int$<ANGLE-R> &i)>" + "DEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)") + +set(parameters_file_base "${CMAKE_CURRENT_BINARY_DIR}/moc_mywrapobject.cpp_parameters") +# check if generator is multi-config +if(CMAKE_CONFIGURATION_TYPES) + set(parameters_file "${parameters_file_base}_$<CONFIG>") +else() + if(NOT CMAKE_BUILD_TYPE STREQUAL "") + set(parameters_file "${parameters_file_base}_${CMAKE_BUILD_TYPE}") + else() + set(parameters_file "${parameters_file_base}") + endif() +endif() + +add_custom_command(TARGET QtWrapMacroTest + POST_BUILD + COMMAND ${CMAKE_COMMAND} "-DPARAMETERS_FILE_PATH=${parameters_file}" -P check_moc_parameters.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/tests/auto/cmake/test_moc_macro_target/check_moc_parameters.cmake b/tests/auto/cmake/test_moc_macro_target/check_moc_parameters.cmake new file mode 100644 index 0000000000..5388816c07 --- /dev/null +++ b/tests/auto/cmake/test_moc_macro_target/check_moc_parameters.cmake @@ -0,0 +1,17 @@ + +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause +function(check_parameters file_path) + file(READ ${file_path} file_content) + foreach(compile_option IN ITEMS "-DDEFINE_CMDLINE_SIGNAL" "-DMY_OPTION") + string(REGEX MATCHALL "${compile_option}" matches ${file_content}) + list(LENGTH matches matches_length) + if(matches_length GREATER 1) + message(FATAL_ERROR "${compile_option} is defined multiple times in ${file_path}") + elseif(matches_length EQUAL 0) + message(FATAL_ERROR "${compile_option} is not defined in ${file_path}") + endif() + endforeach() +endfunction() + +check_parameters(${PARAMETERS_FILE_PATH}) diff --git a/tests/auto/cmake/test_moc_macro_target/interface/myinterface.h b/tests/auto/cmake/test_moc_macro_target/interface/myinterface.h index 60ff102037..3c18c9a10d 100644 --- a/tests/auto/cmake/test_moc_macro_target/interface/myinterface.h +++ b/tests/auto/cmake/test_moc_macro_target/interface/myinterface.h @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYINTERFACE_H #define MYINTERFACE_H diff --git a/tests/auto/cmake/test_moc_macro_target/main_gen_test.cpp b/tests/auto/cmake/test_moc_macro_target/main_gen_test.cpp index 5ffb740e9d..ef58aa025a 100644 --- a/tests/auto/cmake/test_moc_macro_target/main_gen_test.cpp +++ b/tests/auto/cmake/test_moc_macro_target/main_gen_test.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> diff --git a/tests/auto/cmake/test_moc_macro_target/main_wrap_test.cpp b/tests/auto/cmake/test_moc_macro_target/main_wrap_test.cpp index 2f403d95c6..bf4b6193fe 100644 --- a/tests/auto/cmake/test_moc_macro_target/main_wrap_test.cpp +++ b/tests/auto/cmake/test_moc_macro_target/main_wrap_test.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> diff --git a/tests/auto/cmake/test_moc_macro_target/mywrapobject.h b/tests/auto/cmake/test_moc_macro_target/mywrapobject.h index 7398cce9ee..28030a5832 100644 --- a/tests/auto/cmake/test_moc_macro_target/mywrapobject.h +++ b/tests/auto/cmake/test_moc_macro_target/mywrapobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYWRAPOBJECT_H #define MYWRAPOBJECT_H diff --git a/tests/auto/cmake/test_multiple_find_package/main.cpp b/tests/auto/cmake/test_multiple_find_package/main.cpp index 7db90ad9c5..820a550917 100644 --- a/tests/auto/cmake/test_multiple_find_package/main.cpp +++ b/tests/auto/cmake/test_multiple_find_package/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QString> diff --git a/tests/auto/cmake/test_opengl_lib/main.cpp b/tests/auto/cmake/test_opengl_lib/main.cpp index 86cdd29a48..b29d11f667 100644 --- a/tests/auto/cmake/test_opengl_lib/main.cpp +++ b/tests/auto/cmake/test_opengl_lib/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qglobal.h> diff --git a/tests/auto/cmake/test_platform_defs_include/main.cpp b/tests/auto/cmake/test_platform_defs_include/main.cpp index 5e61b3f393..30d2e2065a 100644 --- a/tests/auto/cmake/test_platform_defs_include/main.cpp +++ b/tests/auto/cmake/test_platform_defs_include/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qplatformdefs.h" diff --git a/tests/auto/cmake/test_plugin_shared_static_flavor.cmake b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake index f692abdb45..ffe5fb5447 100644 --- a/tests/auto/cmake/test_plugin_shared_static_flavor.cmake +++ b/tests/auto/cmake/test_plugin_shared_static_flavor.cmake @@ -1,5 +1,5 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only _qt_internal_test_expect_pass(test_plugin_shared_static_flavor TESTNAME test_plugin_flavor_static diff --git a/tests/auto/cmake/test_private_includes/main.cpp b/tests/auto/cmake/test_private_includes/main.cpp index fee93f978d..6dc90fbae0 100644 --- a/tests/auto/cmake/test_private_includes/main.cpp +++ b/tests/auto/cmake/test_private_includes/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QGuiApplication> #include <QScreen> diff --git a/tests/auto/cmake/test_private_targets/main.cpp b/tests/auto/cmake/test_private_targets/main.cpp index 509d27d23b..4566fd6ce6 100644 --- a/tests/auto/cmake/test_private_targets/main.cpp +++ b/tests/auto/cmake/test_private_targets/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 Stephen Kelly <steveire@gmail.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QGuiApplication> diff --git a/tests/auto/cmake/test_qt_add_resources_rebuild/CMakeLists.txt b/tests/auto/cmake/test_qt_add_resources_rebuild/CMakeLists.txt new file mode 100644 index 0000000000..e7b35b332f --- /dev/null +++ b/tests/auto/cmake/test_qt_add_resources_rebuild/CMakeLists.txt @@ -0,0 +1,123 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_qt_add_resources_rebuild) + +set(test_project_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/sample") +set(test_project_build_dir "${CMAKE_CURRENT_BINARY_DIR}/build_sample") + +# Make sure that file paths are 'real' paths +get_filename_component(test_project_source_dir "${test_project_source_dir}" REALPATH) +get_filename_component(test_project_build_dir "${test_project_build_dir}" REALPATH) + +file(REMOVE_RECURSE "${test_project_build_dir}") +file(MAKE_DIRECTORY "${test_project_build_dir}") + +# For access to _qt_internal_get_cmake_test_configure_options +find_package(Qt6 COMPONENTS Core REQUIRED) +include("${_Qt6CTestMacros}") + +set(indent " ") +list(APPEND CMAKE_MESSAGE_INDENT "${indent}") + +function(configure_project) + message(STATUS "Configuring build") + _qt_internal_get_cmake_test_configure_options(option_list) + execute_process(COMMAND + "${CMAKE_COMMAND}" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + "-G${CMAKE_GENERATOR}" + ${option_list} + -B "${test_project_build_dir}" + -S "${test_project_source_dir}" + RESULT_VARIABLE result + ) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to configure sample project") + endif() +endfunction() + +function(try_build) + message(STATUS "Building project") + execute_process(COMMAND + "${CMAKE_COMMAND}" + --build "${test_project_build_dir}" + RESULT_VARIABLE result + ) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Unable to build test project") + endif() +endfunction() + +function(get_target_path out_var) + file(STRINGS "${test_project_build_dir}/targets.txt" targets) + list(GET targets 0 first_target_path) + message(STATUS "Built target is at '${first_target_path}'") + set(${out_var} "${first_target_path}" PARENT_SCOPE) +endfunction() + +function(get_timestamp file_path out_var) + message(STATUS "Getting timestamp of built target.") + file(TIMESTAMP "${file_path}" value "%s") + set(${out_var} "${value}" PARENT_SCOPE) +endfunction() + +function(sleep) + # Avoids issues with low resolution modification times (like HFS on macOS). + set(seconds 2) + message(STATUS "Sleeping for ${seconds} seconds.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep ${seconds}) +endfunction() + +function(touch_file) + set(input "input.ts") + set(input_path "${test_project_source_dir}/${input}") + message(STATUS "Touching ${input_path}") + file(TOUCH "${input_path}") +endfunction() + +function(assert_timestamp_is_equal before after) + set(timestamps "\n${indent}Before TS: ${before}\n${indent} After TS: ${after}") + if("${after}" EQUAL "${before}") + message(STATUS "Target was not rebuilt. ${timestamps}") + else() + message(FATAL_ERROR "Target WAS rebuilt. ${timestamps}") + endif() +endfunction() + +function(assert_timestamp_is_greater before after) + set(timestamps "\n${indent}Before TS: ${before}\n${indent} After TS: ${after}") + if("${after}" GREATER "${before}") + message(STATUS "Target was correctly rebuilt. ${timestamps}") + else() + message(FATAL_ERROR "Target was NOT rebuilt. ${timestamps}") + endif() +endfunction() + +configure_project() +try_build() +get_target_path(target_path) + +# Make sure that a second build without changes doesn't rebuild the executable. +get_timestamp("${target_path}" ts_1) +sleep() +try_build() +get_timestamp("${target_path}" ts_2) +assert_timestamp_is_equal("${ts_1}" "${ts_2}") + +# Touching the input file should cause rcc to rerun, then the compiler, then the linker, +# and thus the executable timestamp should be updated. +touch_file() +try_build() +get_timestamp("${target_path}" ts_3) +assert_timestamp_is_greater("${ts_2}" "${ts_3}") + +# Check that building again doesn't rebuild the executable. +sleep() +try_build() +get_timestamp("${target_path}" ts_4) +assert_timestamp_is_equal("${ts_3}" "${ts_4}") + +list(POP_BACK CMAKE_MESSAGE_INDENT) diff --git a/tests/auto/cmake/test_qt_add_resources_rebuild/sample/CMakeLists.txt b/tests/auto/cmake/test_qt_add_resources_rebuild/sample/CMakeLists.txt new file mode 100644 index 0000000000..1696eae261 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_resources_rebuild/sample/CMakeLists.txt @@ -0,0 +1,47 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause +cmake_minimum_required(VERSION 3.16) +project(sample LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core) + +set(source "${CMAKE_BINARY_DIR}/main.cpp") +file(GENERATE OUTPUT "${source}" CONTENT "int main() { return 0; }") + +qt_add_executable(${PROJECT_NAME} ${source}) + +# This is a poor man's implementation of qt_add_lupdate. +set(input "${CMAKE_SOURCE_DIR}/input.ts") +set(output "${CMAKE_BINARY_DIR}/output.qm") +add_custom_command( + OUTPUT "${output}" + COMMAND ${CMAKE_COMMAND} -E copy "${input}" "${output}" + DEPENDS "${input}" + VERBATIM +) + +# This is where the bug happened before. Adding the target dependency properties used the target +# as an order-only dependency, instead of depending on the actual dependency file. +set_source_files_properties("${output}" + PROPERTIES _qt_resource_target_dependency "output_target") + +add_custom_target(output_target + DEPENDS "${output}" +) + +qt_add_resources(${PROJECT_NAME} "res" + PREFIX "/" + BASE "${CMAKE_CURRENT_BINARY_DIR}" + FILES "${output}" +) + +# Write out the location of the binary so its timestamp can be checked by the driving parent +# project. +set(target_file_out "${CMAKE_BINARY_DIR}/targets.txt") +add_custom_target(all_built ALL + COMMAND + ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:${PROJECT_NAME}>" > "${target_file_out}" + VERBATIM +) +# Make sure the file path is written out after the executable is linked. +add_dependencies(all_built ${PROJECT_NAME}) diff --git a/tests/auto/cmake/test_qt_add_resources_rebuild/sample/input.ts b/tests/auto/cmake/test_qt_add_resources_rebuild/sample/input.ts new file mode 100644 index 0000000000..20a96e90c4 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_resources_rebuild/sample/input.ts @@ -0,0 +1 @@ +bonk diff --git a/tests/auto/cmake/test_qt_add_ui_1/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_1/CMakeLists.txt new file mode 100644 index 0000000000..882abecc0b --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_1/CMakeLists.txt @@ -0,0 +1,62 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + if(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: ui_mainwindow.h is included as + # "sub1/sub2/sub3/sub4/../../../../src/ui_files/ui_mainwindow.h". + # Expect 1: Successful build without the double build issue. + # Expect 2: No build folder leakage and generation of the + # sub1/sub2/sub3/sub4 folder in ${hash_folder}/include + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder( "example" "${test_ui_file}" hash_folder) + string(CONCAT test_build_dir + "${CMAKE_CURRENT_BINARY_DIR}/UicBuildLeak_incPathGen" + "${config_path}-build") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_additional_args "-DMAINWINDOW_UI_PATH=sub1/sub2/" + "sub3/sub4/../../../../src/ui_files/") + string(CONCAT test_file_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/src/ui_files/ui_mainwindow.h") + string(CONCAT test_folder_to_check "${test_build_dir}/.qt/" + "${hash_folder}/${config_arg}/sub1/sub2/sub3/sub4") + incremental_build_test( + TEST_NAME UicBuildLeak_incPathGen + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + ADDITIONAL_ARGS "${test_additional_args}" + FILE_TO_TOUCH "${test_ui_file}" + FILE_TO_CHECK "${test_file_to_check}" + FOLDER_TO_CHECK "${test_folder_to_check}" + ) + endforeach() +endforeach() + diff --git a/tests/auto/cmake/test_qt_add_ui_10/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_10/CMakeLists.txt new file mode 100644 index 0000000000..6b223fb281 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_10/CMakeLists.txt @@ -0,0 +1,62 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: mainwindow.ui file is touched after the first build. The + # ui_mainwindow.h should be generated without the ${config_arg} folder. + # Expect 1: Successful build without the double build issue. + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "qt_add_ui_simple_no_config${config_path}-build") + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_file_to_touch "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder( + "example" + "${test_ui_file}" + hash_folder) + incremental_build_test( + TEST_NAME qt6_add_ui_simple_no_config + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + CONFIG "${config_arg}" + ADDITIONAL_ARGS "-DUI_NO_CONFIG_OPTIONS=ON" + FILE_TO_TOUCH "${test_file_to_touch}" + FILE_TO_CHECK + "${test_build_dir}/.qt/${hash_folder}/ui_mainwindow.h" + ) + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_2/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_2/CMakeLists.txt new file mode 100644 index 0000000000..dceb0c7a2e --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_2/CMakeLists.txt @@ -0,0 +1,60 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: mainwindow.ui file is touched after the first build. + # Expect 1: Successful build without the double build issue. + set(test_build_dir + "${CMAKE_CURRENT_BINARY_DIR}/qt_add_ui_simple${config_path}-build") + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_file_to_touch "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder( + "example" + "${test_ui_file}" + hash_folder) + incremental_build_test( + TEST_NAME qt6_add_ui_simple + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + CONFIG "${config_arg}" + FILE_TO_TOUCH "${test_file_to_touch}" + FILE_TO_CHECK + "${test_build_dir}/.qt/${hash_folder}/${config_arg}/ui_mainwindow.h" + ) + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_3/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_3/CMakeLists.txt new file mode 100644 index 0000000000..81a9a38431 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_3/CMakeLists.txt @@ -0,0 +1,199 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + if(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: Check whether api sets warning against AUTOUIC activation. + # Expect 1: Printing of the error message and failure of the build. + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_warning_test${config_path}-build") + run_cmake_configure(SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + CLEAN_FIRST + ADDITIONAL_ARGS "-DCMAKE_AUTOUIC=ON" + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + if(NOT cmake_result EQUAL 0) + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error: " + "${cmake_error}\nFAIL: \"uic_warning_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" + "build failed to configure") + else() + message(STATUS "PASS: \"uic_warning_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" + "build was configured successfully") + endif() + + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_warning_test${config_path}-build") + run_cmake_build( + BUILD_DIR "${test_build_dir}" + VERBOSE ON + CONFIG "${config_arg}" + OUTPUT_VARIABLE cmake_build_output + RESULT_VARIABLE cmake_build_result) + if(NOT cmake_build_result EQUAL 0) + message(STATUS "PASS: \"uic_warning_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}" + "-build failed to build") + else() + message(FATAL_ERROR "FAIL: \"uic_warning_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-" + "build was built successfully") + endif() + expect_string_contains("${cmake_build_output}" "has \"AUTOUIC\" enabled" + SUCCESS_MESSAGE "\"uic_warning_test\" test in \ +${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-build \ +has \"has AUTOUIC enabled\"" + FAILURE_MESSAGE "\"uic_warning_test\" test in \ +${CMAKE_CURRENT_BINARY_DIR}/uic_warning_test${config_path}-build \ +does not have \"has AUTOUIC enabled\"") + + + if("${generator}" MATCHES "Ninja") + # Test case: If INCLUDE_PREFIX is changed without changing the + # corresponding include path in the source file and Ninja generator + # is used, this casues the double build issue. + # Note: Only happens in Ninja generator. + # Expect 1: Failure of the build in the first build. + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_double_build_test${config_path}-build") + run_cmake_configure(SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + CLEAN_FIRST + ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/" + "-DDO_NOT_GENERATE_FILE=ON" + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + + if(NOT cmake_result EQUAL 0) + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" + ": ${cmake_error}\nFAIL: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build failed to configure") + else() + message(STATUS "PASS: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build was configured successfully") + endif() + + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_double_build_test${config_path}-build") + run_cmake_build( + BUILD_DIR "${test_build_dir}" + VERBOSE ON + CONFIG "${config_arg}" + OUTPUT_VARIABLE cmake_build_output + RESULT_VARIABLE cmake_build_result) + + if(NOT cmake_build_result EQUAL 0) + message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}" + "FAIL: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build failed to build in the first build") + else() + message(STATUS "PASS: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build was built successfully in the first " + "build") + endif() + + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_double_build_test${config_path}-build") + run_cmake_configure(SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + # We change the INCLUDE_PREFIX here. + ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub/" + "-DDO_NOT_GENERATE_FILE=ON" + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + + if(NOT cmake_result EQUAL 0) + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" + ":${cmake_error}\nFAIL: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build failed to configure in the second " + "build") + else() + message(STATUS "PASS: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build was configured successfully in the " + "second build") + endif() + + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_double_build_test${config_path}-build") + run_cmake_build( + BUILD_DIR "${test_build_dir}" + VERBOSE ON + CONFIG "${config_arg}" + OUTPUT_VARIABLE cmake_build_output + ERROR_VARIABLE cmake_build_error + RESULT_VARIABLE cmake_build_result) + + if(NOT cmake_build_result EQUAL 0) + message(STATUS "PASS: \"uic_double_build_test\" test in" + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build failed to build in the first build " + "after changing INCLUDE_PREFIX") + else() + message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}" + "\ncmake_build_error: ${cmake_build_error}\n" + "FAIL: \"uic_double_build_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test" + "${config_path}-build was built successfully in the first " + "build after changing INCLUDE_PREFIX") + endif() + + set(expected_fail_string "No such file or directory|file not found") + expect_string_contains(${cmake_build_output} + "${expected_fail_string}" + SUCCESS_MESSAGE "\"uic_double_build_test\" test in \ +${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test${config_path}\ +-build has \"ui_mainwindow.h: No such file or directory\" in \ +the first build after changing INCLUDE_PREFIX" + FAILURE_MESSAGE "\"uic_double_build_test\" test in \ +${CMAKE_CURRENT_BINARY_DIR}/uic_double_build_test${config_path}\ +-build does not have \"ui_mainwindow.h: No such file or \ +directory\" in the first build after changing INCLUDE_PREFIX") + + endif() + endforeach() +endforeach() + diff --git a/tests/auto/cmake/test_qt_add_ui_4/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_4/CMakeLists.txt new file mode 100644 index 0000000000..51c74352d6 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_4/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: widget1.ui file is touched after the first build. + # Expect 1: Successful build without the double build issue. + # Expect 2: Only touched files to be built + set(test_build_dir + "${CMAKE_CURRENT_BINARY_DIR}/UicIncrementalBuild${config_path}-build") + string(CONCAT ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/UicIncrementalBuild/src/widget1.ui") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/UicIncrementalBuild") + + generate_hash_folder( + "example" + "${ui_file}" + hash_folder) + string(CONCAT test_file_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/src/ui_widget1.h") + incremental_build_test( + TEST_NAME UicIncrementalBuild + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + FILE_TO_TOUCH "${ui_file}" + FILE_TO_CHECK + "${test_file_to_check}" + FOLDER_TO_CHECK + "${test_build_dir}/.qt/${hash_folder}/${config_arg}/src" + CHECK_UNWANTED_BUILDS + ) + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_5/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_5/CMakeLists.txt new file mode 100644 index 0000000000..7b29bcf52b --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_5/CMakeLists.txt @@ -0,0 +1,164 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + if(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + + if("${generator}" MATCHES "Ninja") + # Test case: Add a new ui file to CMakeLists.txt after the first + # build. + # Expect 1: Expect ${target}_autogen/prefix_info.cmake to be + # generated as expected. + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_prefix_info_cmake_test${config_path}-build") + run_cmake_configure(SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + CLEAN_FIRST + ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/" + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + + if(NOT cmake_result EQUAL 0) + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" + ":${cmake_error}\nFAIL: \"uic_prefix_info_cmake_test\" test" + " in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build failed to configure") + else() + message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in" + "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build was configured successfully") + endif() + + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder("example" "${test_ui_file}" + hash_folder_mainwindow) + string(CONCAT expected_prefix_info_cmake_content + "include_guard()\nset(${hash_folder_mainwindow}_prefix \"" + "sub1/sub2/sub3\")") + # read the content of the prefix_info.cmake file + string(CONCAT "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_prefix_info_cmake_test${config_path}-build") + file(READ + "${test_build_dir}/example_autogen/prefix_info.cmake" + prefix_info_cmake_content) + + if("${prefix_info_cmake_content}" STREQUAL + "${expected_prefix_info_cmake_content}") + message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build has the expected content in " + "prefix_info.cmake") + else() + message(FATAL_ERROR "FAIL: \"uic_prefix_info_cmake_test\" test " + "in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build does not have the expected content in" + " prefix_info.cmake") + endif() + + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_prefix_info_cmake_test${config_path}-build") + run_cmake_build( + BUILD_DIR "${test_build_dir}" + VERBOSE ON + CONFIG "${config_arg}" + OUTPUT_VARIABLE cmake_build_output + ERROR_VARIABLE cmake_build_error + RESULT_VARIABLE cmake_build_result) + + if(NOT cmake_build_result EQUAL 0) + message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}" + "\ncmake_build_error: ${cmake_build_error}\n" + "FAIL: \"uic_prefix_info_cmake_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build failed to build in the first build") + else() + message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build was built successfully in the first " + "build") + endif() + + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_prefix_info_cmake_test${config_path}-build") + run_cmake_configure(SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + GENERATOR "${generator}" + ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/" + "-DNEW_UI_PATH=sub5/sub6/sub7/ " "-DADD_NEW_UI=ON" + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + + if(NOT cmake_result EQUAL 0) + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error" + ": ${cmake_error}\nFAIL: \"uic_prefix_info_cmake_test\" " + "test in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_" + "test ${config_path}-build failed to configure in the" + "second build") + else() + message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in" + " ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build was configured successfully in the " + "second build") + endif() + + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/subdir/mainwindow.ui") + generate_hash_folder("example" "${test_ui_file}" + hash_folder_subdir_mainwindow) + set(expected_prefix_info_cmake_content + "include_guard()\nset(${hash_folder_subdir_mainwindow}_prefix \ +\"sub5/sub6/sub7\")") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "uic_prefix_info_cmake_test${config_path}-build") + file(READ + "${test_build_dir}/example_autogen/prefix_info.cmake" + prefix_info_cmake_content) + + if("${prefix_info_cmake_content}" STREQUAL + "${expected_prefix_info_cmake_content}") + message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in " + "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build has the expected content in " + "prefix_info.cmake") + else() + message(FATAL_ERROR "FAIL: \"uic_prefix_info_cmake_test\" test " + "in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test" + "${config_path}-build does not have the expected content " + "in prefix_info.cmake") + endif() + endif() + endforeach() +endforeach() + diff --git a/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt new file mode 100644 index 0000000000..2d57c6067d --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt @@ -0,0 +1,64 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: ui_mainwindow.h is included as + # "../../../../src/ui_files/ui_mainwindow.h". + # Test case: mainwindow1.ui file is touched after the first build. + # Expect 1: Successful build without the double build issue. + # Expect 2: No build folder leakage and generation of the "_/_/_/_/" + # folder in ${hash_folder}/include. + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../test_qt_add_ui_" + "common/uic_test/mainwindow.ui") + generate_hash_folder("example" "${test_ui_file}" hash_folder) + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/UicBuildLeak_" + "subFolderGen${config_path}-build") + string(CONCAT test_file_to_touch "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + string(CONCAT test_file_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/src/ui_files/ui_mainwindow.h") + incremental_build_test( + TEST_NAME UicBuildLeak_subFolderGen + SOURCE_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/../test_qt_add_ui_common/uic_test" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=../../../../src/ui_files/" + FILE_TO_TOUCH "${test_file_to_touch}" + FILE_TO_CHECK "${test_file_to_check}" + FOLDER_TO_CHECK + "${test_build_dir}/.qt/${hash_folder}/${config_arg}/_/_/_/_" + ) + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_7/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_7/CMakeLists.txt new file mode 100644 index 0000000000..8278f13a72 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_7/CMakeLists.txt @@ -0,0 +1,62 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case 1: There are two widget1.ui files in different folders. + # Expect 1: Successful build without the double build issue. + # Expect 2: Only touched files to be built. + string(CONCAT ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/sub1/sub2/sub3/" + "sub4") + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "UicIncBuild_sameFileDiffFolder${config_path}-build") + string(CONCAT test_file_to_touch "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui") + generate_hash_folder( + "example" + "${ui_file}" + hash_folder) + incremental_build_test( + TEST_NAME UicIncBuild_sameFileDiffFolder + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + FILE_TO_TOUCH "${test_file_to_touch}" + CHECK_UNWANTED_BUILDS + ) + + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt new file mode 100644 index 0000000000..f8d0763d35 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt @@ -0,0 +1,67 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + # A CI test fails with the below condition. So, we are running the test + # only for the Debug configuration. + if ("${generator}" MATCHES "Xcode" AND + CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(configs "Debug") + elseif(multi_config_out) + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: ui_mainwindow.h is included as + # "sub1/sub2/sub3/../../../../../../../../../../../../../ui_mainwindow.h". + # Test case: mainwindow1.ui file is touched after the first build. + # Expect 1: Successful build without the double build issue. + # Expect 2: No build folder leakage and generation of the + # "_/_/_/_/_/_/_/_/_/_/sub1/sub2/sub3" folder in ${hash_folder}/include. + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder("example" "${test_ui_file}" hash_folder) + string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/" + "UicBuildLeak_subFolderGen_complex${config_path}-build") + string(CONCAT test_additional_args "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3" + "/../../../../../../../../../../../../../") + string(CONCAT test_file_to_touch "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + string(CONCAT test_file_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/ui_mainwindow.h") + string(CONCAT test_folder_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/_/_/_/_/_/_/_/_/_/_/sub1/sub2/sub3") + incremental_build_test( + TEST_NAME UicBuildLeak_subFolderGen_complex + SOURCE_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/../test_qt_add_ui_common/uic_test" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + ADDITIONAL_ARGS "${test_additional_args}" + FILE_TO_TOUCH "${test_file_to_touch}" + FILE_TO_CHECK "${test_file_to_check}" + FOLDER_TO_CHECK "${test_folder_to_check}" + ) + endforeach() +endforeach() diff --git a/tests/auto/cmake/test_qt_add_ui_9/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_9/CMakeLists.txt new file mode 100644 index 0000000000..9e28ddc927 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_9/CMakeLists.txt @@ -0,0 +1,66 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +include(../test_qt_add_ui_common/RunCMake.cmake) +include(../test_qt_add_ui_common/functions.cmake) + +get_generators(generators) + +foreach(generator IN ITEMS ${generators}) + message(STATUS "Running tests for generator: ${generator}") + is_multi_config(${generator} multi_config_out) + if(multi_config_out) + # Since our CI machines are slow, ctest --build-and-test buffers the + # output of the configure step of a test, and the fact that we run all + # the test logic in the configure step, we need to exclude Release + # to avoid CI stdout timeout errors. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/25790 + set(configs "Debug" "Release") + else() + set(configs "single_config") + endif() + + foreach(config IN ITEMS ${configs}) + if("${config}" STREQUAL "single_config") + set(config_path "") + set(config_arg "") + else() + set(config_path "_${config}") + set(config_arg "${config}") + endif() + + # Test case: ui_mainwindow.h is included as + # "sub2/sub3/../../../src/ui_files/ui_mainwindow.h". + # Expect 1: Successful build without the double build issue. + # Expect 2: No build folder leakage and generation of + # _/sub2/sub3 in ${hash_folder}/include. + # Note: This test case is a mix of previous two test cases. + string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test/mainwindow.ui") + generate_hash_folder("example" "${test_ui_file}" hash_folder) + set(test_build_dir + "${CMAKE_CURRENT_BINARY_DIR}/UicBuildLeak_mix${config_path}-build") + string(CONCAT test_additional_args "-DMAINWINDOW_UI_PATH=sub2/sub3/" + "../../../src/ui_files/") + string(CONCAT test_file_to_check "${test_build_dir}/.qt/${hash_folder}/" + "${config_arg}/src/ui_files/ui_mainwindow.h") + string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../" + "test_qt_add_ui_common/uic_test") + incremental_build_test( + TEST_NAME UicBuildLeak_mix + SOURCE_DIR "${test_source_dir}" + BUILD_DIR "${test_build_dir}" + CONFIG "${config_arg}" + GENERATOR "${generator}" + ADDITIONAL_ARGS "${test_additional_args}" + FILE_TO_TOUCH "${test_ui_file}" + FILE_TO_CHECK "${test_file_to_check}" + FOLDER_TO_CHECK + "${test_build_dir}/.qt/${hash_folder}/${config_arg}/_/sub2/sub3" + ) + endforeach() +endforeach() + diff --git a/tests/auto/cmake/test_qt_add_ui_common/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_common/CMakeLists.txt new file mode 100644 index 0000000000..628dc9373a --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(test) + +add_executable(test main.cpp) diff --git a/tests/auto/cmake/test_qt_add_ui_common/RunCMake.cmake b/tests/auto/cmake/test_qt_add_ui_common/RunCMake.cmake new file mode 100644 index 0000000000..6b39fe3398 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/RunCMake.cmake @@ -0,0 +1,157 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +function(run_cmake_configure) + set(options CLEAN_FIRST) + set(oneValueArgs SOURCE_DIR BUILD_DIR RESULT_VARIABLE OUTPUT_VARIABLE + ERROR_VARIABLE GENERATOR) + set(multiValueArgs ADDITIONAL_ARGS) + + cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN}) + + if(NOT arg_SOURCE_DIR) + message(FATAL_ERROR "SOURCE_DIR not specified") + endif() + + if(NOT arg_BUILD_DIR) + message(FATAL_ERROR "BUILD_DIR not specified") + endif() + + is_multi_config(arg_GENERATOR multi_config_out) + if (NOT ${multi_config_out}) + set(run_arg_config_arg -Darg_TYPE=Debug) + endif() + + set(test_project_source_dir ${arg_SOURCE_DIR}) + set(test_project_build_dir ${arg_BUILD_DIR}) + + # Make sure that file paths are 'real' paths + get_filename_component(test_project_source_dir "${test_project_source_dir}" + REALPATH) + get_filename_component(test_project_build_dir "${test_project_build_dir}" + REALPATH) + + if(arg_CLEAN_FIRST) + file(REMOVE_RECURSE "${test_project_build_dir}") + endif() + file(MAKE_DIRECTORY "${test_project_build_dir}") + + execute_process(COMMAND + "${CMAKE_COMMAND}" + -S "${test_project_source_dir}" + -B "${test_project_build_dir}" + -G "${arg_GENERATOR}" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ${run_arg_config_arg} + ${arg_ADDITIONAL_ARGS} + RESULT_VARIABLE cmake_result + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ECHO_OUTPUT_VARIABLE + ECHO_ERROR_VARIABLE + ) + + # set output variables + set(${arg_RESULT_VARIABLE} ${cmake_result} PARENT_SCOPE) + set(${arg_OUTPUT_VARIABLE} ${cmake_output} PARENT_SCOPE) + set(${arg_ERROR_VARIABLE} ${cmake_error} PARENT_SCOPE) +endfunction() + +function(run_cmake_build) + set(options VERBOSE) + set(oneValueArgs CONFIG BUILD_DIR RESULT_VARIABLE OUTPUT_VARIABLE + ERROR_VARIABLE) + cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN}) + + if(NOT arg_BUILD_DIR) + message(FATAL_ERROR "BUILD_DIR not specified") + endif() + + if (arg_VERBOSE OR arg_VERBOSE STREQUAL "") + set(arg_VERBOSE_ARG --verbose) + endif() + + if(arg_CONFIG) + set(arg_BUILD_CONFIG_ARG --config ${arg_CONFIG}) + endif() + + execute_process(COMMAND ${CMAKE_COMMAND} + --build ${arg_BUILD_DIR} + ${arg_VERBOSE_ARG} + ${arg_BUILD_CONFIG_ARG} + RESULT_VARIABLE cmake_result + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE + ECHO_OUTPUT_VARIABLE + ECHO_ERROR_VARIABLE) + + set(${arg_RESULT_VARIABLE} ${cmake_result} PARENT_SCOPE) + set(${arg_OUTPUT_VARIABLE} ${cmake_output} PARENT_SCOPE) + set(${arg_ERROR_VARIABLE} ${cmake_error} PARENT_SCOPE) +endfunction() + +function(is_multi_config generator output) + if ("${generator}" MATCHES "Visual Studio" OR "${generator}" MATCHES "Xcode" + OR "${generator}" MATCHES "Ninja Multi-Config") + set(${output} TRUE PARENT_SCOPE) + else() + set(${output} FALSE PARENT_SCOPE) + endif() +endfunction() + +# check if string includes substring +function(_internal_string_contains output string substring) + if("${string}" MATCHES "${substring}") + set(${output} TRUE PARENT_SCOPE) + else() + set(${output} FALSE PARENT_SCOPE) + endif() +endfunction() + +function(expect_string_contains string substring) + set(oneValueArgs SUCCESS_MESSAGE FAILURE_MESSAGE) + cmake_parse_arguments(expect_string_contains "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + _internal_string_contains(result "${string}" "${substring}") + if("${result}" STREQUAL TRUE) + if (expect_string_contains_SUCCESS_MESSAGE) + message(STATUS "PASS: ${expect_string_contains_SUCCESS_MESSAGE}") + else() + message(STATUS "PASS: \"${string}\" contains \"${substring}\"") + endif() + else() + if (expect_string_contains_FAILURE_MESSAGE) + message(FATAL_ERROR + "FAIL: ${expect_string_contains_FAILURE_MESSAGE}") + else() + message(FATAL_ERROR "FAIL: \"${string}\" contains \"${substring}\"") + endif() + endif() +endfunction() + +function(expect_string_not_contains string substring) + set(oneValueArgs SUCCESS_MESSAGE FAILURE_MESSAGE) + cmake_parse_arguments(expect_string_not_contains + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + _internal_string_contains(result ${string} ${substring}) + if(${result} STREQUAL FALSE) + if (expect_string_not_contains_SUCCESS_MESSAGE) + message(STATUS "PASS: ${expect_string_not_contains_SUCCESS_MESSAGE}") + else() + message(STATUS "PASS: \"${string}\" not contains \"${substring}\"") + endif() + else() + if (expect_string_not_contains_FAILURE_MESSAGE) + message(FATAL_ERROR + "FAIL: ${expect_string_not_contains_FAILURE_MESSAGE}") + else() + message(FATAL_ERROR "FAIL: \"${string}\" contains \"${substring}\"") + endif() + endif() +endfunction() diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/main.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/main.cpp new file mode 100644 index 0000000000..27296cb9a0 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/main.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char* argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/mainwindow.h b/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/mainwindow.h new file mode 100644 index 0000000000..9aeaefbe08 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/mainwindow.h @@ -0,0 +1,26 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget* parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow* ui; +}; +#endif // MAINWINDOW_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/main.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/main.cpp new file mode 100644 index 0000000000..27296cb9a0 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/main.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char* argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.cpp new file mode 100644 index 0000000000..d4302325fb --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "mainwindow.h" + +#include <QVBoxLayout> + +#include "../../../../src/ui_files/ui_mainwindow.h" +#include "widget1.h" + +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + auto layout = new QVBoxLayout; + layout->addWidget(new Widget1); + + QWidget* w = new QWidget(this); + w->setLayout(layout); + + setCentralWidget(w); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.h new file mode 100644 index 0000000000..46dc7690cc --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget* parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow* ui; +}; +#endif // MAINWINDOW_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/mainwindow.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/mainwindow.ui new file mode 100644 index 0000000000..828d7c1782 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/mainwindow.ui @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"/> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/widget1.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/widget1.ui new file mode 100644 index 0000000000..db0c58d5df --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/widget1.ui @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Widget1</class> + <widget class="QWidget" name="Widget1"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Input:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>OnTextChanged:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="OnTextChanged"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.cpp new file mode 100644 index 0000000000..2139ff2c84 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "widget1.h" + +#include "../../../../src/ui_files/ui_widget1.h" + +Widget1::Widget1(QWidget* parent) + : QWidget(parent) + , ui(new Ui::Widget1) +{ + ui->setupUi(this); + connect(ui->lineEdit, SIGNAL(textChanged(const QString&)), this, + SLOT(onTextChanged(const QString&))); +} + +Widget1::~Widget1() +{ + delete ui; +} + +void Widget1::onTextChanged(const QString& text) +{ + ui->OnTextChanged->setText(text); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.h new file mode 100644 index 0000000000..f8a5ad57d5 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.h @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WIDGET1_H +#define WIDGET1_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class Widget1; +} +QT_END_NAMESPACE + +class Widget1 : public QWidget +{ + Q_OBJECT +public: + explicit Widget1(QWidget* parent = nullptr); + ~Widget1(); +public slots: + void onTextChanged(const QString& text); + +private: + Ui::Widget1* ui; +}; + +#endif // WIDGET1_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui new file mode 100644 index 0000000000..db0c58d5df --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Widget1</class> + <widget class="QWidget" name="Widget1"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Input:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>OnTextChanged:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="OnTextChanged"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.cpp new file mode 100644 index 0000000000..721f0c868f --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "widget2.h" + +#include "../../../../ui_widget1.h" + +Widget2::Widget2(QWidget* parent) + : QWidget(parent) + , ui(new Ui::Widget2) +{ + ui->setupUi(this); + connect(ui->lineEdit, SIGNAL(textChanged(const QString&)), this, + SLOT(onTextChanged(const QString&))); +} + +Widget2::~Widget2() +{ + delete ui; +} + +void Widget2::onTextChanged(const QString& text) +{ + ui->OnTextChanged->setText(text); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.h new file mode 100644 index 0000000000..e448b12caf --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WIDGET2_H +#define WIDGET2_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class Widget2; +} +QT_END_NAMESPACE + +class Widget2 : public QWidget +{ + Q_OBJECT + +public: + explicit Widget2(QWidget* parent = nullptr); + ~Widget2(); +public slots: + void onTextChanged(const QString& text); + +private: + Ui::Widget2* ui; +}; + +#endif // WIDGET2_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/sub1/sub2/sub3/sub4/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/sub1/sub2/sub3/sub4/CMakeLists.txt new file mode 100644 index 0000000000..b8443c370d --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/sub1/sub2/sub3/sub4/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(UicIncrementalBuild_sameFileDifferentFolder LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui) + +set(CMAKE_AUTOMOC ON) + +qt_add_executable(example + ../../../../src/ui_files/mainwindow.ui + ../../../../src/ui_files/widget1.ui + ../../../../widget1.ui + ../../../../src/mainwindow.h + ../../../../src/widget1.h + ../../../../src/widget2.h + ../../../../src/main.cpp + ../../../../src/mainwindow.cpp + ../../../../src/widget1.cpp + ../../../../src/widget2.cpp +) + +target_link_libraries(example PRIVATE Qt6::Widgets + Qt6::Core + Qt6::Gui) + +qt6_add_ui(example + INCLUDE_PREFIX "../../../../src/ui_files" + SOURCES "../../../../src/ui_files/mainwindow.ui" + "../../../../src/ui_files/widget1.ui" + OPTIONS "$<$<CONFIG:Debug>:-a>") + +qt6_add_ui(example + INCLUDE_PREFIX "../../../../" + SOURCES "../../../../widget1.ui" + OPTIONS "$<$<CONFIG:Debug>:-a>") + diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/widget1.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/widget1.ui new file mode 100644 index 0000000000..facf4678f2 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/widget1.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Widget2</class> + <widget class="QWidget" name="Widget2"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Input:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>OnTextChanged:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="OnTextChanged"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/CMakeLists.txt new file mode 100644 index 0000000000..81023c3382 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(UicIncrementalBuild LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) + +set(CMAKE_AUTOMOC ON) + +qt_add_executable(example + src/mainwindow.ui + src/widget1.ui + src/widget2.ui + src/mainwindow.h + src/widget1.h + src/widget2.h + src/main.cpp + src/mainwindow.cpp + src/widget1.cpp + src/widget2.cpp +) + +target_link_libraries(example PRIVATE Qt6::Widgets + Qt6::Core + Qt6::Gui) + +qt6_add_ui(example + INCLUDE_PREFIX "src" + SOURCES "src/mainwindow.ui" "src/widget1.ui" "src/widget2.ui" + OPTIONS "$<$<CONFIG:Debug>:-a>") + diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/main.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/main.cpp new file mode 100644 index 0000000000..27296cb9a0 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/main.cpp @@ -0,0 +1,14 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QApplication> + +#include "mainwindow.h" + +int main(int argc, char* argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.cpp new file mode 100644 index 0000000000..ef582f187c --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "mainwindow.h" + +#include <QVBoxLayout> + +#include "src/ui_mainwindow.h" +#include "widget1.h" + +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + auto layout = new QVBoxLayout; + layout->addWidget(new Widget1); + + QWidget* w = new QWidget(this); + w->setLayout(layout); + + setCentralWidget(w); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.h new file mode 100644 index 0000000000..46dc7690cc --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget* parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow* ui; +}; +#endif // MAINWINDOW_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.ui new file mode 100644 index 0000000000..828d7c1782 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.ui @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"/> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>22</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.cpp new file mode 100644 index 0000000000..4047ea4d9c --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "widget1.h" + +#include "src/ui_widget1.h" + +Widget1::Widget1(QWidget* parent) + : QWidget(parent) + , ui(new Ui::Widget1) +{ + ui->setupUi(this); + connect(ui->lineEdit, SIGNAL(textChanged(const QString&)), this, + SLOT(onTextChanged(const QString&))); +} + +Widget1::~Widget1() +{ + delete ui; +} + +void Widget1::onTextChanged(const QString& text) +{ + ui->OnTextChanged->setText(text); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.h new file mode 100644 index 0000000000..f8a5ad57d5 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.h @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WIDGET1_H +#define WIDGET1_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class Widget1; +} +QT_END_NAMESPACE + +class Widget1 : public QWidget +{ + Q_OBJECT +public: + explicit Widget1(QWidget* parent = nullptr); + ~Widget1(); +public slots: + void onTextChanged(const QString& text); + +private: + Ui::Widget1* ui; +}; + +#endif // WIDGET1_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.ui new file mode 100644 index 0000000000..db0c58d5df --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.ui @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Widget1</class> + <widget class="QWidget" name="Widget1"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Input:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>OnTextChanged:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="OnTextChanged"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.cpp b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.cpp new file mode 100644 index 0000000000..1dc28b0c8b --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "widget2.h" + +#include "src/ui_widget2.h" + +Widget2::Widget2(QWidget* parent) + : QWidget(parent) + , ui(new Ui::Widget2) +{ + ui->setupUi(this); + connect(ui->lineEdit, SIGNAL(textChanged(const QString&)), this, + SLOT(onTextChanged(const QString&))); +} + +Widget2::~Widget2() +{ + delete ui; +} + +void Widget2::onTextChanged(const QString& text) +{ + ui->OnTextChanged->setText(text); +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.h b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.h new file mode 100644 index 0000000000..e448b12caf --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef WIDGET2_H +#define WIDGET2_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class Widget2; +} +QT_END_NAMESPACE + +class Widget2 : public QWidget +{ + Q_OBJECT + +public: + explicit Widget2(QWidget* parent = nullptr); + ~Widget2(); +public slots: + void onTextChanged(const QString& text); + +private: + Ui::Widget2* ui; +}; + +#endif // WIDGET2_H diff --git a/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.ui b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.ui new file mode 100644 index 0000000000..facf4678f2 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Widget2</class> + <widget class="QWidget" name="Widget2"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Input:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>OnTextChanged:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="OnTextChanged"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/functions.cmake b/tests/auto/cmake/test_qt_add_ui_common/functions.cmake new file mode 100644 index 0000000000..efb8b09774 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/functions.cmake @@ -0,0 +1,223 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +function(generate_hash_folder target_name infile out_folder) + get_filename_component(infile_abs "${infile}" ABSOLUTE) + string(SHA1 infile_hash "${target_name}${infile_abs}") + string(SUBSTRING "${infile_hash}" 0 6 short_hash) + set(${out_folder} "${short_hash}" PARENT_SCOPE) +endfunction() + +function(get_latest_vs_generator output) + execute_process(COMMAND ${CMAKE_COMMAND} -G + ERROR_VARIABLE CMAKE_GENERATORS_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCHALL "Visual Studio [0-9]+ [0-9]+" vs_generators + "${CMAKE_GENERATORS_ERROR}") + + if(NOT vs_generators) + message(FATAL_ERROR "No visual studio generators found") + endif() + + set(last_version "0") + set(last_generator "") + foreach(generator IN LISTS vs_generators) + string(REGEX MATCH "Visual Studio ([0-9]+) [0-9]+" unused "${generator}") + if("${CMAKE_MATCH_1}" VERSION_GREATER "${last_version}") + set(last_version "${CMAKE_MATCH_1}") + set(last_generator "${CMAKE_MATCH_0}") + endif() + endforeach() + set(${output} "${last_generator}" PARENT_SCOPE) +endfunction() + +function(check_unwanted_builds_after_first_build cmake_output test_name test_dir + generator) + set(unwanted_builds_success_message + "\"${test_name}\" in \"${test_dir}\" -> No unwanted builds") + set(unwanted_builds_failure_message + "\"${test_name}\" in \"${test_dir}\" -> Unwanted builds found") + if(${generator} MATCHES "Ninja") + expect_string_not_contains(${cmake_output} + "widget2.cpp.o.d|mainwindow.cpp.o.d" + SUCCESS_MESSAGE ${unwanted_builds_success_message} + FAILURE_MESSAGE ${unwanted_builds_failure_message}) + elseif(${generator} MATCHES "Make") + string(CONCAT not_expect_string + "Building CXX object UicIncrementalBuild/CMakeFiles" + "/example.dir/src/widget2.cpp.o|Building CXX object UicIncremental" + "Build/CMakeFiles/example.dir/src/mainwindow.cpp.o") + expect_string_not_contains(${cmake_output} "${not_expect_string}" + SUCCESS_MESSAGE ${unwanted_builds_success_message} + FAILURE_MESSAGE ${unwanted_builds_failure_message}) + elseif(${generator} MATCHES "Visual Studio") + expect_string_not_contains(${cmake_output} "widget2.cpp|mainwindow.cpp" + SUCCESS_MESSAGE ${unwanted_builds_success_message} + FAILURE_MESSAGE ${unwanted_builds_failure_message}) + elseif(${generator} MATCHES "Xcode") + expect_string_not_contains(${cmake_output} "widget2.cpp|mainwindow.cpp" + SUCCESS_MESSAGE ${unwanted_builds_success_message} + FAILURE_MESSAGE ${unwanted_builds_failure_message}) + endif() +endfunction() + +function(check_output_after_second_build cmake_output test_name + test_dir generator) + set(second_build_success_message + "\"${test_name}\" in \"${test_dir}\" -> Generation of UI files were not \ +triggered in the second build") + set(second_build_failure_message + "\"${test_name}\" in \"${test_dir}\" -> Generation of UI files were \ +triggered in the second build") + + if(${generator} MATCHES "Ninja") + expect_string_contains(${cmake_output} "ninja: no work to do." + SUCCESS_MESSAGE ${second_build_success_message} + FAILURE_MESSAGE ${second_build_failure_message}) + elseif(${generator} MATCHES "Visual Studio" OR ${generator} MATCHES "Xcode") + expect_string_not_contains(${cmake_output} "mainwindow" + SUCCESS_MESSAGE + ${second_build_success_message} + FAILURE_MESSAGE + ${second_build_failure_message}) + elseif(${generator} MATCHES "Makefiles") + expect_string_not_contains(${cmake_output} "mainwindow.cpp.o.d -o" + SUCCESS_MESSAGE ${second_build_success_message} + FAILURE_MESSAGE ${second_build_failure_message}) + endif() +endfunction() + +function(incremental_build_test) + set(options CHECK_UNWANTED_BUILDS) + set(oneValueArgs CONFIG TEST_NAME SOURCE_DIR BUILD_DIR FILE_TO_TOUCH + FILE_TO_CHECK FOLDER_TO_CHECK GENERATOR) + set(multiValueArgs ADDITIONAL_ARGS) + + cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" + ${ARGN}) + + string(REPLACE ";" " " arg_ADDITIONAL_ARGS "${arg_ADDITIONAL_ARGS}") + if ("${arg_SOURCE_DIR}" STREQUAL "") + message(FATAL_ERROR "FAIL: \"${arg_TEST_NAME}\" test failed because " + "SOURCE_DIR is empty") + endif() + + if ("${arg_BUILD_DIR}" STREQUAL "") + message(FATAL_ERROR "FAIL: \"${arg_TEST_NAME}\" test failed because " + "BUILD_DIR is empty") + endif() + + if ("${arg_GENERATOR}" STREQUAL "") + message(FATAL_ERROR "FAIL: \"${arg_TEST_NAME}\" test failed because " + "GENERATOR is empty") + endif() + + run_cmake_configure(SOURCE_DIR "${arg_SOURCE_DIR}" + BUILD_DIR "${arg_BUILD_DIR}" + GENERATOR "${arg_GENERATOR}" + CLEAN_FIRST + ADDITIONAL_ARGS ${arg_ADDITIONAL_ARGS} + OUTPUT_VARIABLE cmake_output + ERROR_VARIABLE cmake_error + RESULT_VARIABLE cmake_result) + + if(${cmake_result} EQUAL 0) + message(STATUS + "PASS: \"${arg_TEST_NAME}\" test in ${arg_BUILD_DIR} was configured " + "successfully") + else() + message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error: " + "${cmake_error}\nFAIL: \"${arg_TEST_NAME}\" test in ${arg_BUILD_DIR}" + " failed to configure") + endif() + + if(NOT "${arg_CONFIG}" STREQUAL "single_config") + set(config_arg "${arg_CONFIG}") + endif() + + run_cmake_build(BUILD_DIR ${arg_BUILD_DIR} + VERBOSE ON + CONFIG ${config_arg} + OUTPUT_VARIABLE cmake_build_output + ERROR_VARIABLE cmake_build_error + RESULT_VARIABLE cmake_build_result) + + if(${cmake_build_result} EQUAL 0) + message(STATUS + "PASS: \"${arg_TEST_NAME}\" test in ${arg_BUILD_DIR} was built " + "successfully") + else() + message(FATAL_ERROR + "cmake_build_output: ${cmake_build_output}\ncmake_build_error: " + "${cmake_build_error}\nFAIL: \"${arg_TEST_NAME}\" test in " + "${arg_BUILD_DIR} failed to build") + endif() + + if(NOT "${arg_FILE_TO_CHECK}" STREQUAL "") + if(NOT EXISTS "${arg_FILE_TO_CHECK}") + message(FATAL_ERROR "FAIL: \"${arg_TEST_NAME}\" ${arg_FILE_TO_CHECK}" + " could not be found") + else() + message(STATUS "PASS: \"${arg_TEST_NAME}\" \"${arg_FILE_TO_CHECK}\" " + "was generated successfully") + endif() + endif() + + if(NOT "${arg_FOLDER_TO_CHECK}" STREQUAL "" AND NOT WIN32) + if(NOT EXISTS "${arg_FOLDER_TO_CHECK}") + message(FATAL_ERROR + "FAIL: \"${arg_TEST_NAME}\" Folder \"${arg_FOLDER_TO_CHECK}\" " + "does not exist") + else() + message(STATUS + "PASS: \"${arg_TEST_NAME}\" Folder \"${arg_FOLDER_TO_CHECK}\" " + "exists") + endif() + endif() + + if(NOT "${arg_FILE_TO_TOUCH}" STREQUAL "") + file(TOUCH "${arg_FILE_TO_TOUCH}") + endif() + + run_cmake_build(BUILD_DIR ${arg_BUILD_DIR} + VERBOSE ON + CONFIG ${arg_CONFIG} + OUTPUT_VARIABLE cmake_build_output) + if(${arg_CHECK_UNWANTED_BUILDS}) + check_unwanted_builds_after_first_build(${cmake_build_output} + ${arg_TEST_NAME} ${arg_BUILD_DIR} ${arg_GENERATOR}) + endif() + + run_cmake_build(BUILD_DIR ${arg_BUILD_DIR} + VERBOSE ON + CONFIG ${arg_CONFIG} + OUTPUT_VARIABLE cmake_build_output) + check_output_after_second_build(${cmake_build_output} + ${arg_TEST_NAME} ${arg_BUILD_DIR} ${arg_GENERATOR}) +endfunction() + +function(get_generators output) + if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux") + set(generators "Unix Makefiles" "Ninja" "Ninja Multi-Config") + elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows") + # CI fails with Clang and Visual Studio generators. + # That's why discard that combination. + if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND + NOT MINGW) + get_latest_vs_generator(latest_vs) + endif() + set(generators "Ninja" "Ninja Multi-Config" "${latest_vs}") + elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + # TODO: Add Xcode generator when + # https://gitlab.kitware.com/cmake/cmake/-/issues/25790 is fixed. + # Otherwise, adding Xcode generator might fail CI due to the timeout + # issue. + set(generators "Unix Makefiles" "Ninja" "Ninja Multi-Config") + else() + string(JOIN "" ERROR_MESSAGE + "FAIL: host OS not supported for this test." + "host : ${CMAKE_HOST_SYSTEM_NAME}") + message(FATAL_ERROR "${ERROR_MESSAGE}") + endif() + set(${output} "${generators}" PARENT_SCOPE) +endfunction() diff --git a/tests/auto/cmake/test_qt_add_ui_common/main.cpp b/tests/auto/cmake/test_qt_add_ui_common/main.cpp new file mode 100644 index 0000000000..c93c3fc6a0 --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/main.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +int main() { return 0; } diff --git a/tests/auto/cmake/test_qt_add_ui_common/uic_test/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_common/uic_test/CMakeLists.txt new file mode 100644 index 0000000000..b05efd5e4d --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/uic_test/CMakeLists.txt @@ -0,0 +1,65 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(UicTest LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui) + +set(CMAKE_AUTOMOC ON) + +if (NOT DO_NOT_GENERATE_FILE) + file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mainwindow.cpp" + CONTENT " \ +#include \"${CMAKE_CURRENT_SOURCE_DIR}/../UicBuildFolderLeakageCommon/mainwindow.h\" \n \ +#include \"${MAINWINDOW_UI_PATH}ui_mainwindow.h\" \n \ +MainWindow::MainWindow(QWidget* parent) \n \ + : QMainWindow(parent) \n \ + , ui(new Ui::MainWindow) \n \ +{ \n \ + ui->setupUi(this); \n \ +} \n \ + \n \ +MainWindow::~MainWindow() \n \ +{ \n \ + delete ui; \n \ +} \n \ +") +endif() + +qt_add_executable(example + ../UicBuildFolderLeakageCommon/main.cpp + ../UicBuildFolderLeakageCommon/mainwindow.h + mainwindow.ui +) + +if (${DO_NOT_GENERATE_FILE}) + target_sources(example PRIVATE mainwindow.cpp) +else() + target_sources(example PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/mainwindow.cpp") +endif() + +target_link_libraries(example PRIVATE Qt6::Widgets + Qt6::Core + Qt6::Gui) + +if (NOT UI_NO_CONFIG_OPTIONS) + set(uic_options "$<$<CONFIG:Debug>:-a>") +endif() +qt6_add_ui(example + INCLUDE_PREFIX "${MAINWINDOW_UI_PATH}" + SOURCES "mainwindow.ui" + OPTIONS "${uic_options}") + +if(ADD_NEW_UI) + qt6_add_ui(example INCLUDE_PREFIX "${NEW_UI_PATH}" + SOURCES "subdir/mainwindow.ui" + OPTIONS "${uic_options}") +endif() + +# Enable AUTOUIC after qt6_add_ui() has been called +if (CMAKE_AUTOUIC) + set_property(TARGET example PROPERTY AUTOUIC ON) +endif() + diff --git a/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.cpp b/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.cpp new file mode 100644 index 0000000000..1c4b48b49e --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.cpp @@ -0,0 +1,17 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "../UicBuildFolderLeakageCommon/mainwindow.h" +#include "sub1/sub2/sub3/ui_mainwindow.h" + +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} diff --git a/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.ui b/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.ui new file mode 100644 index 0000000000..4e57b05eac --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>PushButton</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>23</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_add_ui_common/uic_test/subdir/mainwindow.ui b/tests/auto/cmake/test_qt_add_ui_common/uic_test/subdir/mainwindow.ui new file mode 100644 index 0000000000..4e57b05eac --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_common/uic_test/subdir/mainwindow.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>PushButton</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>23</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp index f133f67d05..40fb1dffbe 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp @@ -1,4 +1,4 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "MetaType.h" diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp index 670f038749..b141c894ab 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only int main(int argc, char *argv[]) { diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h index cc5c4a772d..bcd7594d9a 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h index 08c84c85c3..1c38ae2f5e 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h index d2e4db9314..104dd6d7a9 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once #include <QObject> diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h index 56d6c56bb5..f3a9ececb7 100644 --- a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h +++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #pragma once diff --git a/tests/auto/cmake/test_qt_manual_moc/CMakeLists.txt b/tests/auto/cmake/test_qt_manual_moc/CMakeLists.txt new file mode 100644 index 0000000000..513995c4cf --- /dev/null +++ b/tests/auto/cmake/test_qt_manual_moc/CMakeLists.txt @@ -0,0 +1,61 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core) + +set(CMAKE_AUTOMOC FALSE) + +qt_manual_moc(moc_files testclass.h + DEFINITIONS + -DMY_FIRST_DEF + MY_SECOND_DEF + -DMY_THIRD_DEF=1 + MY_FOURTH_DEF=1 +) + +add_custom_target(verify_testclass ALL COMMAND ${CMAKE_COMMAND} + "-DMOC_ARGS=moc_testclass.cpp_parameters$<$<BOOL:$<CONFIG>>:_$<CONFIG>>" + "-DDEFINITIONS=MY_FIRST_DEF;MY_SECOND_DEF;MY_THIRD_DEF=1;MY_FOURTH_DEF=1" + -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyDefines.cmake" + VERBATIM +) + +add_library(MyInterfaceLib INTERFACE) +target_compile_definitions(MyInterfaceLib INTERFACE -DMY_TRANSITIVE_DEF=1) + +add_library(MyLib SHARED testclass1.h testclass.cpp) +target_link_libraries(MyLib PRIVATE Qt6::Core MyInterfaceLib) +target_compile_definitions(MyLib PRIVATE + -DMY_FIRST_DEF + MY_SECOND_DEF + -DMY_THIRD_DEF=1 + MY_FOURTH_DEF=1 +) + +add_library(MyLib2 SHARED testclass1.h testclass.cpp) +target_link_libraries(MyLib2 PRIVATE Qt6::Core) +target_compile_definitions(MyLib2 PRIVATE + -DMY_FOREIGN_DEF +) + +qt_manual_moc(moc_files testclass1.h TARGETS MyLib MyLib2) +target_sources(MyLib PRIVATE ${moc_files}) +target_sources(MyLib2 PRIVATE ${moc_files}) + +string(JOIN ";" expected + "MY_FIRST_DEF" + "MY_SECOND_DEF" + "MY_THIRD_DEF=1" + "MY_FOURTH_DEF=1" + "MY_TRANSITIVE_DEF=1" + "MY_FOREIGN_DEF" +) + +add_custom_target(verify_testclass1 ALL COMMAND ${CMAKE_COMMAND} + "-DMOC_ARGS=moc_testclass1.cpp_parameters$<$<BOOL:$<CONFIG>>:_$<CONFIG>>" + "-DDEFINITIONS=${expected}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/VerifyDefines.cmake" + VERBATIM +) diff --git a/tests/auto/cmake/test_qt_manual_moc/VerifyDefines.cmake b/tests/auto/cmake/test_qt_manual_moc/VerifyDefines.cmake new file mode 100644 index 0000000000..b3acedb014 --- /dev/null +++ b/tests/auto/cmake/test_qt_manual_moc/VerifyDefines.cmake @@ -0,0 +1,30 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +if(NOT DEFINITIONS) + message(FATAL_ERROR "No definitions are provided to test") +endif() + +if(NOT MOC_ARGS) + message(FATAL_ERROR "The moc RSP file is not specified") +endif() + +file(READ "${MOC_ARGS}" moc_args_data) + +string(REPLACE "\n" ";" moc_args_data "${moc_args_data}") + +foreach(def IN LISTS DEFINITIONS) + set(found FALSE) + foreach(data IN LISTS moc_args_data) + if(data MATCHES "^(-D)?${def}") + set(found TRUE) + break() + endif() + endforeach() + if(NOT found) + message(FATAL_ERROR "The ${def} is missing in the moc argument list:\n${moc_args_data}") + endif() +endforeach() + diff --git a/tests/auto/cmake/test_qt_manual_moc/testclass.cpp b/tests/auto/cmake/test_qt_manual_moc/testclass.cpp new file mode 100644 index 0000000000..5323e18136 --- /dev/null +++ b/tests/auto/cmake/test_qt_manual_moc/testclass.cpp @@ -0,0 +1,8 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#include "testclass.h" + +TestClass::TestClass(QObject *parent) : QObject(parent) +{ + +} diff --git a/tests/auto/cmake/test_qt_manual_moc/testclass.h b/tests/auto/cmake/test_qt_manual_moc/testclass.h new file mode 100644 index 0000000000..84fc656f1a --- /dev/null +++ b/tests/auto/cmake/test_qt_manual_moc/testclass.h @@ -0,0 +1,17 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef TESTCLASS_H +#define TESTCLASS_H + +#include <QObject> + +class TestClass : public QObject +{ + Q_OBJECT + +public: + TestClass(QObject *parent = nullptr); +}; + +#endif // TESTCLASS_H diff --git a/tests/auto/cmake/test_qt_manual_moc/testclass1.h b/tests/auto/cmake/test_qt_manual_moc/testclass1.h new file mode 100644 index 0000000000..84fc656f1a --- /dev/null +++ b/tests/auto/cmake/test_qt_manual_moc/testclass1.h @@ -0,0 +1,17 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef TESTCLASS_H +#define TESTCLASS_H + +#include <QObject> + +class TestClass : public QObject +{ + Q_OBJECT + +public: + TestClass(QObject *parent = nullptr); +}; + +#endif // TESTCLASS_H diff --git a/tests/auto/cmake/test_qtmainwin_library/myobject.cpp b/tests/auto/cmake/test_qtmainwin_library/myobject.cpp index 71d734f5fe..bb06a5bb8b 100644 --- a/tests/auto/cmake/test_qtmainwin_library/myobject.cpp +++ b/tests/auto/cmake/test_qtmainwin_library/myobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "myobject.h" diff --git a/tests/auto/cmake/test_qtmainwin_library/myobject.h b/tests/auto/cmake/test_qtmainwin_library/myobject.h index ccf0a310ff..90bb75640f 100644 --- a/tests/auto/cmake/test_qtmainwin_library/myobject.h +++ b/tests/auto/cmake/test_qtmainwin_library/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYOBJECT_H #define MYOBJECT_H diff --git a/tests/auto/cmake/test_resource_without_obj_lib/CMakeLists.txt b/tests/auto/cmake/test_resource_without_obj_lib/CMakeLists.txt new file mode 100644 index 0000000000..16563141f4 --- /dev/null +++ b/tests/auto/cmake/test_resource_without_obj_lib/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_resource_without_obj_lib) + +if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHints.cmake") +endif() + +find_package(Qt6 REQUIRED + COMPONENTS Core Test + HINTS ${Qt6Tests_PREFIX_PATH} +) + +qt6_add_library(helper_lib STATIC helper_lib.cpp) +qt6_add_resources(helper_lib "helper_res" FILES resource.txt PREFIX "/") + +# Link to Core, to ensure both the helper_lib and the main executable +# inherit the QT_NAMESPACE if it is set, otherwise we get undefined +# linker errors due to the mismatch in symbol names. +target_link_libraries(helper_lib PRIVATE Qt6::Core) + +set(CMAKE_AUTOMOC ON) + +qt6_add_executable(test_resource_without_obj_lib main.cpp) +target_link_libraries(test_resource_without_obj_lib PRIVATE Qt6::Core Qt6::Test) + +# Link against the library file and not the target, so that we can confirm +# the ability to manually initialize the resource via Q_INIT_RESOURCE. +target_link_libraries(test_resource_without_obj_lib PRIVATE $<TARGET_FILE:helper_lib>) + diff --git a/tests/auto/cmake/test_resource_without_obj_lib/helper_lib.cpp b/tests/auto/cmake/test_resource_without_obj_lib/helper_lib.cpp new file mode 100644 index 0000000000..cd21e6c476 --- /dev/null +++ b/tests/auto/cmake/test_resource_without_obj_lib/helper_lib.cpp @@ -0,0 +1,4 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +void nothing() {} diff --git a/tests/auto/cmake/test_resource_without_obj_lib/main.cpp b/tests/auto/cmake/test_resource_without_obj_lib/main.cpp new file mode 100644 index 0000000000..bffbf81b87 --- /dev/null +++ b/tests/auto/cmake/test_resource_without_obj_lib/main.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtCore/qtresource.h> +#include <QtTest/QtTest> + +class TestManualResourceInit : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + void resourceExistsAfterManualInit(); +}; + +void TestManualResourceInit::initTestCase() +{ + // Manually initialize the resource like we used to do it in qt5 + qmake times. + Q_INIT_RESOURCE(helper_res); +} + +void TestManualResourceInit::resourceExistsAfterManualInit() +{ + QVERIFY(QFile::exists(":/resource.txt")); +} + +QTEST_MAIN(TestManualResourceInit) +#include "main.moc" + diff --git a/tests/auto/cmake/test_resource_without_obj_lib/resource.txt b/tests/auto/cmake/test_resource_without_obj_lib/resource.txt new file mode 100644 index 0000000000..7804a324a4 --- /dev/null +++ b/tests/auto/cmake/test_resource_without_obj_lib/resource.txt @@ -0,0 +1 @@ +Test resource diff --git a/tests/auto/cmake/test_standalone_test/CMakeLists.txt b/tests/auto/cmake/test_standalone_test/CMakeLists.txt new file mode 100644 index 0000000000..169d824c88 --- /dev/null +++ b/tests/auto/cmake/test_standalone_test/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) +project(tststandalone_test LANGUAGES CXX) +find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) + +qt_internal_add_test(tst_standalone_test + GUI + SOURCES + tst_standalone_test.cpp + LIBRARIES + Qt::Gui +) diff --git a/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp b/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp new file mode 100644 index 0000000000..fa533602ec --- /dev/null +++ b/tests/auto/cmake/test_standalone_test/tst_standalone_test.cpp @@ -0,0 +1,22 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QTest> +#include <QWindow> + +class tst_standalone_test : public QObject +{ + Q_OBJECT + +private slots: + void testLaunched() + { + QWindow w; + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + } +}; + +QTEST_MAIN(tst_standalone_test) + +#include "tst_standalone_test.moc" diff --git a/tests/auto/cmake/test_static_resources/.cmake.conf b/tests/auto/cmake/test_static_resources/.cmake.conf index 377be0059e..6d83b084f7 100644 --- a/tests/auto/cmake/test_static_resources/.cmake.conf +++ b/tests/auto/cmake/test_static_resources/.cmake.conf @@ -1 +1 @@ -set(QT_REPO_MODULE_VERSION "6.5.0") +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 index bddc1df932..e3cab9cf4a 100644 --- a/tests/auto/cmake/test_static_resources/CMakeLists.txt +++ b/tests/auto/cmake/test_static_resources/CMakeLists.txt @@ -13,6 +13,7 @@ project(TestStaticResources ) find_package(Qt6 COMPONENTS Core BuildInternals Test CONFIG REQUIRED) +qt_internal_project_setup() qt_build_repo_begin() @@ -21,4 +22,5 @@ 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 index c45af80781..f866f0af46 100644 --- a/tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt +++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/CMakeLists.txt @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_module(MockStaticResources1 + NO_UNITY_BUILD STATIC PLUGIN_TYPES mockstaticresources SOURCES 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 index 31f62648f6..b6c23a82eb 100644 --- a/tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp +++ b/tests/auto/cmake/test_static_resources/mock_static_resources1/dummy.cpp @@ -1,4 +1,4 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only void dummy() { } 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 index d017ba8ab0..dec5588a6d 100644 --- 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 @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause qt_internal_add_plugin(TestInitResourcesStaticPlugin STATIC + NO_UNITY_BUILD OUTPUT_NAME testinitresourcesstaticplugin PLUGIN_TYPE mockstaticresources 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 index da2ed67973..a95e54ee4f 100644 --- 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 @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/qfile.h> #include <QtCore/qdebug.h> 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 index 352ae57fac..2067b8c920 100644 --- 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 @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> #include <QtCore/qfile.h> 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 index 2606cd88d9..b802323cfc 100644 --- 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 @@ -11,6 +11,7 @@ # 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. @@ -19,6 +20,7 @@ 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 @@ -37,6 +39,7 @@ endif() 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 @@ -54,6 +57,7 @@ add_test(NAME test_static_resources_propagation_manual_finalize 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 @@ -76,6 +80,7 @@ if(NOT link_order_matters) 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 @@ -123,6 +128,7 @@ if(POLICY CMP0099) 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 @@ -142,6 +148,7 @@ if(POLICY CMP0099) 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 @@ -157,6 +164,7 @@ if(POLICY CMP0099) 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 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 index fc048bb61e..c5d5312eb8 100644 --- 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 @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest/QtTest> #include <QtCore/qfile.h> diff --git a/tests/auto/cmake/test_testlib_definitions/main.cpp b/tests/auto/cmake/test_testlib_definitions/main.cpp index 750e42cfdf..9452adb817 100644 --- a/tests/auto/cmake/test_testlib_definitions/main.cpp +++ b/tests/auto/cmake/test_testlib_definitions/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> #include <QTest> diff --git a/tests/auto/cmake/test_versionless_targets/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/CMakeLists.txt index 3514f4e0f9..1afcaa6a93 100644 --- a/tests/auto/cmake/test_versionless_targets/CMakeLists.txt +++ b/tests/auto/cmake/test_versionless_targets/CMakeLists.txt @@ -5,22 +5,99 @@ cmake_minimum_required(VERSION 3.16) project(versionless_targets) -set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) +function(check_versionless_targets) + set(known_interface_properties + QT_MAJOR_VERSION + AUTOMOC_MACRO_NAMES + AUTOUIC_OPTIONS + COMPILE_DEFINITIONS + COMPILE_FEATURES + COMPILE_OPTIONS + CXX_MODULE_SETS + HEADER_SETS + HEADER_SETS_TO_VERIFY + INCLUDE_DIRECTORIES + LINK_DEPENDS + LINK_DIRECTORIES + LINK_LIBRARIES + LINK_LIBRARIES_DIRECT + LINK_LIBRARIES_DIRECT_EXCLUDE + LINK_OPTIONS + POSITION_INDEPENDENT_CODE + PRECOMPILE_HEADERS + SOURCES + SYSTEM_INCLUDE_DIRECTORIES + ) -find_package(Qt6Core REQUIRED) + set(known_qt_exported_properties + MODULE_PLUGIN_TYPES + QT_DISABLED_PRIVATE_FEATURES + QT_DISABLED_PUBLIC_FEATURES + QT_ENABLED_PRIVATE_FEATURES + QT_ENABLED_PUBLIC_FEATURES + QT_QMAKE_PRIVATE_CONFIG + QT_QMAKE_PUBLIC_CONFIG + QT_QMAKE_PUBLIC_QT_CONFIG + _qt_config_module_name + _qt_is_public_module + _qt_module_has_headers + _qt_module_has_private_headers + _qt_module_has_public_headers + _qt_module_has_qpa_headers + _qt_module_has_rhi_headers + _qt_module_include_name + _qt_module_interface_name + _qt_package_name + _qt_package_version + _qt_private_module_target_name + ) -if (NOT TARGET Qt6::Core) - message(SEND_ERROR "Qt6::Core target not defined!") -endif() + foreach(prop ${known_interface_properties}) + set(versionless_prop "") + set(versioned_prop "") + get_target_property(versionless_prop Qt::Core INTERFACE_${prop}) + get_target_property(versioned_prop Qt6::Core INTERFACE_${prop}) + if(NOT versionless_prop AND NOT versioned_prop) + continue() + endif() -if (TARGET Qt::Core) - message(SEND_ERROR "Qt::Core target defined despite QT_NO_CREATE_VERSIONLESS_TARGETS!") -endif() + if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}") + message(SEND_ERROR "INTERFACE_${prop} doesn't match versionless ${versionless_prop}" + " versioned ${versioned_prop}") + endif() + endforeach() -set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF) + foreach(prop ${known_qt_exported_properties}) + set(versionless_prop "") + set(versioned_prop "") + get_target_property(versionless_prop Qt::Core ${prop}) + get_target_property(versioned_prop Qt6::Core ${prop}) + if(NOT versionless_prop AND NOT versioned_prop) + continue() + endif() -find_package(Qt6Core REQUIRED) + if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}") + message(SEND_ERROR "${prop} doesn't match versionless ${versionless_prop}" + " versioned ${versioned_prop}") + endif() + endforeach() -if (NOT TARGET Qt::Core) - message(SEND_ERROR "Qt::Core target not defined!") -endif() + foreach(conf "" _RELEASE _DEBUG _RELWITHDEBINFO _MINSIZEREL) + set(versionless_prop "") + set(versioned_prop "") + get_target_property(versionless_prop Qt::Core IMPORTED_LOCATION${conf}) + get_target_property(versioned_prop Qt6::Core IMPORTED_LOCATION${conf}) + if(NOT versionless_prop AND NOT versioned_prop) + continue() + endif() + if(NOT "${versionless_prop}" STREQUAL "${versioned_prop}") + message(SEND_ERROR "IMPORTED_LOCATION${conf} doesn't match versionless ${versionless_prop}" + " versioned ${versioned_prop}") + endif() + endforeach() +endfunction() + +add_subdirectory(default) +add_subdirectory(force_off) +add_subdirectory(force_on) +add_subdirectory(force_old) diff --git a/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt new file mode 100644 index 0000000000..a8757607cf --- /dev/null +++ b/tests/auto/cmake/test_versionless_targets/default/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +message("Test default creating of versionless targets") +find_package(Qt6Core REQUIRED) + +if(NOT TARGET Qt6::Core) + message(SEND_ERROR "Qt6::Core target not defined!") +endif() + +if(NOT TARGET Qt::Core) + message(SEND_ERROR "Qt::Core target not defined!") +endif() + +check_versionless_targets() diff --git a/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt new file mode 100644 index 0000000000..247b1b8c27 --- /dev/null +++ b/tests/auto/cmake/test_versionless_targets/force_off/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +message("Test disabled versionless targets") + +set(QT_NO_CREATE_VERSIONLESS_TARGETS ON) + +find_package(Qt6Core REQUIRED) + +if(NOT TARGET Qt6::Core) + message(SEND_ERROR "Qt6::Core target not defined!") +endif() + +if(TARGET Qt::Core) + message(SEND_ERROR "Qt::Core target defined despite QT_NO_CREATE_VERSIONLESS_TARGETS!") +endif() diff --git a/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt new file mode 100644 index 0000000000..9e83fec7b3 --- /dev/null +++ b/tests/auto/cmake/test_versionless_targets/force_old/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +message("Test force old versionless targets") + +set(QT_USE_OLD_VERSION_LESS_TARGETS ON) + +find_package(Qt6Core REQUIRED) + +if(NOT TARGET Qt6::Core) + message(SEND_ERROR "Qt6::Core target not defined!") +endif() + +if(NOT TARGET Qt::Core) + message(SEND_ERROR "Qt::Core target not defined!") +endif() + +check_versionless_targets() + diff --git a/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt b/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt new file mode 100644 index 0000000000..b3d7596143 --- /dev/null +++ b/tests/auto/cmake/test_versionless_targets/force_on/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +message("Test enabled versionless targets") + +set(QT_NO_CREATE_VERSIONLESS_TARGETS OFF) + +find_package(Qt6Core REQUIRED) + +if(NOT TARGET Qt6::Core) + message(SEND_ERROR "Qt6::Core target not defined!") +endif() + +if(NOT TARGET Qt::Core) + message(SEND_ERROR "Qt::Core target not defined!") +endif() + +check_versionless_targets() diff --git a/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt b/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt index 60e3f0af75..9457278e12 100644 --- a/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt +++ b/tests/auto/cmake/test_widgets_app_deployment/CMakeLists.txt @@ -33,7 +33,7 @@ function(create_test_executable target) qt_generate_deploy_app_script( TARGET ${target} - FILENAME_VARIABLE deploy_script + OUTPUT_SCRIPT deploy_script # Don't fail at configure time on unsupported platforms NO_UNSUPPORTED_PLATFORM_ERROR ) diff --git a/tests/auto/cmake/test_widgets_app_deployment/main.cpp b/tests/auto/cmake/test_widgets_app_deployment/main.cpp index 1823a50169..939cd72380 100644 --- a/tests/auto/cmake/test_widgets_app_deployment/main.cpp +++ b/tests/auto/cmake/test_widgets_app_deployment/main.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtTest> #include <QMainWindow> diff --git a/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.cpp b/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.cpp index 8330e3250d..3adda87348 100644 --- a/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.cpp +++ b/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "myobject.h" diff --git a/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.h b/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.h index 917ae9fd24..87d7bfa3df 100644 --- a/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.h +++ b/tests/auto/cmake/test_wrap_cpp_and_resources/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYOBJECT_H #define MYOBJECT_H diff --git a/tests/auto/cmake/test_wrap_cpp_moc/CMakeLists.txt b/tests/auto/cmake/test_wrap_cpp_moc/CMakeLists.txt new file mode 100644 index 0000000000..c00a9d83c5 --- /dev/null +++ b/tests/auto/cmake/test_wrap_cpp_moc/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.16) + +project(test_wrap_cpp_and_resources) + +find_package(Qt6Core REQUIRED) + +add_executable(example main.cpp) + +qt_wrap_cpp(moc_files main.cpp TARGET example) + +# expect the generated moc files to be empty when a source file is passed +if (NOT moc_files STREQUAL "") + message(FATAL_ERROR "test_qt_wrap_cpp_moc: moc_files should be empty") +endif() + +target_link_libraries(example PRIVATE Qt::Core) diff --git a/tests/auto/cmake/test_wrap_cpp_moc/main.cpp b/tests/auto/cmake/test_wrap_cpp_moc/main.cpp new file mode 100644 index 0000000000..28ebfe0536 --- /dev/null +++ b/tests/auto/cmake/test_wrap_cpp_moc/main.cpp @@ -0,0 +1,17 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QObject> + +class MyObject2 : public QObject { + Q_OBJECT +public: + MyObject2() = default; +}; + +#include "main.moc" + +int main() +{ + return 0; +} diff --git a/tests/auto/cmake/test_wrap_cpp_options/myobject.cpp b/tests/auto/cmake/test_wrap_cpp_options/myobject.cpp index 2a90499e6a..14e00e789a 100644 --- a/tests/auto/cmake/test_wrap_cpp_options/myobject.cpp +++ b/tests/auto/cmake/test_wrap_cpp_options/myobject.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "myobject.h" diff --git a/tests/auto/cmake/test_wrap_cpp_options/myobject.h b/tests/auto/cmake/test_wrap_cpp_options/myobject.h index 917ae9fd24..87d7bfa3df 100644 --- a/tests/auto/cmake/test_wrap_cpp_options/myobject.h +++ b/tests/auto/cmake/test_wrap_cpp_options/myobject.h @@ -1,5 +1,5 @@ // Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef MYOBJECT_H #define MYOBJECT_H diff --git a/tests/auto/cmake/tst_qaddpreroutine/CMakeLists.txt b/tests/auto/cmake/tst_qaddpreroutine/CMakeLists.txt index a9892a94ec..bc1a6339db 100644 --- a/tests/auto/cmake/tst_qaddpreroutine/CMakeLists.txt +++ b/tests/auto/cmake/tst_qaddpreroutine/CMakeLists.txt @@ -25,6 +25,7 @@ qt_prepare_standalone_project() find_package(Qt6 COMPONENTS Gui Test CONFIG REQUIRED) qt_internal_add_plugin(QTBUG_90341ThemePlugin + NO_UNITY_BUILD OUTPUT_NAME QTBUG_90341 OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" CLASS_NAME ThemePlugin diff --git a/tests/auto/cmake/tst_qaddpreroutine/plugin.cpp b/tests/auto/cmake/tst_qaddpreroutine/plugin.cpp index ccb0096730..1647d8d3a8 100644 --- a/tests/auto/cmake/tst_qaddpreroutine/plugin.cpp +++ b/tests/auto/cmake/tst_qaddpreroutine/plugin.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 zccrs <zccrs@live.com>, JiDe Zhang <zhangjide@uniontech.com>. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qpa/qplatformthemeplugin.h> #include <qpa/qplatformtheme.h> diff --git a/tests/auto/cmake/tst_qaddpreroutine/tst_qaddpreroutine.cpp b/tests/auto/cmake/tst_qaddpreroutine/tst_qaddpreroutine.cpp index 42c7a07b08..21394648c0 100644 --- a/tests/auto/cmake/tst_qaddpreroutine/tst_qaddpreroutine.cpp +++ b/tests/auto/cmake/tst_qaddpreroutine/tst_qaddpreroutine.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 zccrs <zccrs@live.com>, JiDe Zhang <zhangjide@uniontech.com>. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QGuiApplication> |