diff --git a/src/widgets/Qt6WidgetsMacros.cmake b/src/widgets/Qt6WidgetsMacros.cmake index 2df25812fd1..1ce4cdb6619 100644 --- a/src/widgets/Qt6WidgetsMacros.cmake +++ b/src/widgets/Qt6WidgetsMacros.cmake @@ -164,6 +164,8 @@ function(qt6_add_ui target) set(prefix_info_file_cmake_exists false) endif() + target_sources(${target} PRIVATE ${sources}) + foreach(source_file ${sources}) get_filename_component(outfile "${source_file}" NAME_WE) get_filename_component(infile "${source_file}" ABSOLUTE) diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 58c89d0861a..751f040c81c 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -462,5 +462,6 @@ if(NOT QNX AND NOT WASM AND NOT (WIN32 AND QT_BUILD_MINIMAL_STATIC_TESTS) _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) + _qt_internal_test_expect_pass(test_qt_add_ui_11) endif() diff --git a/tests/auto/cmake/test_qt_add_ui_11/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_11/CMakeLists.txt new file mode 100644 index 00000000000..f557ce91f2f --- /dev/null +++ b/tests/auto/cmake/test_qt_add_ui_11/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) + # 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: mainwindow.ui file is touched after the first build. + # Test case: mainwindow.ui is also passed to qt_add_resources. + # 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 uic_with_rcc + 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/" + "-DTEST_WITH_QRC=ON" + 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_6/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt index 2d57c6067d2..4ed55264219 100644 --- a/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt +++ b/tests/auto/cmake/test_qt_add_ui_6/CMakeLists.txt @@ -34,7 +34,7 @@ foreach(generator IN ITEMS ${generators}) # 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. + # Test case: mainwindow.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. diff --git a/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt b/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt index f8d0763d355..6fa43e17d0e 100644 --- a/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt +++ b/tests/auto/cmake/test_qt_add_ui_8/CMakeLists.txt @@ -34,7 +34,7 @@ foreach(generator IN ITEMS ${generators}) # 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. + # Test case: mainwindow.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. diff --git a/tests/auto/cmake/test_qt_add_ui_common/functions.cmake b/tests/auto/cmake/test_qt_add_ui_common/functions.cmake index efb8b097748..85ee29214a2 100644 --- a/tests/auto/cmake/test_qt_add_ui_common/functions.cmake +++ b/tests/auto/cmake/test_qt_add_ui_common/functions.cmake @@ -96,7 +96,6 @@ function(incremental_build_test) 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") 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 index b05efd5e4d7..a918e222781 100644 --- 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 @@ -63,3 +63,7 @@ if (CMAKE_AUTOUIC) set_property(TARGET example PROPERTY AUTOUIC ON) endif() + +if (TEST_WITH_QRC) + qt_add_resources(example "example.qrc" FILES "mainwindow.ui") +endif()