summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_qt_add_ui_common
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/cmake/test_qt_add_ui_common')
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/CMakeLists.txt7
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/RunCMake.cmake157
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/main.cpp14
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicBuildFolderLeakageCommon/mainwindow.h26
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/main.cpp14
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.cpp28
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/mainwindow.h25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/mainwindow.ui33
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/ui_files/widget1.ui52
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.cpp25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.h28
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget1.ui52
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.cpp25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/src/widget2.h29
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/sub1/sub2/sub3/sub4/CMakeLists.txt39
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncBuild_sameFileDiffFolder/widget1.ui45
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/CMakeLists.txt33
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/main.cpp14
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.cpp28
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.h25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/mainwindow.ui33
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.cpp25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.h28
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget1.ui52
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.cpp25
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.h29
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/UicIncrementalBuild/src/widget2.ui45
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/functions.cmake223
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/main.cpp4
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/uic_test/CMakeLists.txt65
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.cpp17
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/uic_test/mainwindow.ui45
-rw-r--r--tests/auto/cmake/test_qt_add_ui_common/uic_test/subdir/mainwindow.ui45
33 files changed, 1335 insertions, 0 deletions
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>