summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake
diff options
context:
space:
mode:
authorOrkun Tokdemir <orkun.tokdemir@qt.io>2023-07-21 16:41:48 +0200
committerOrkun Tokdemir <orkun.tokdemir@qt.io>2024-01-19 16:16:51 +0100
commitdc4159286b8571a3f3543e457fe1b51b9f5965b7 (patch)
tree695e999bbda78b6e85cccaa7e8ad7b2fae738682 /tests/auto/cmake
parentbcdd51cfae24731a73d008add23d3c1e85bbd8d0 (diff)
qt6_wrap_cpp: Add .moc generation
When a `.moc` file is included in a source file and that source passed to `qt_wrap_cpp`, Users should add the generated `.moc`s path to the target's include path. Since we don't share anything about the output path of generated files by `qt_wrap_cpp`, it makes sense to add in inside `qt_wrap_cpp`. And also, the generated `.moc` file is added to target's source to complete the dependency graph. Otherwise, Users need to get output variable and pass it to target's sources. * Update docs * Add test [ChangeLog][Build System] qt_wrap_cpp will accept .cpp files from now on. When .cpp a file is passed to qt_wrap_cpp, TARGET parameter becomes required. Generated .moc files are added to target's sources inside qt_wrap_cpp. That's why the output parameter will not contain generated .moc files. Fixes: QTBUG-113402 Change-Id: I54dd2b1ff8e5c9ba457b1eb4f73b0a8190d9c659 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests/auto/cmake')
-rw-r--r--tests/auto/cmake/CMakeLists.txt1
-rw-r--r--tests/auto/cmake/test_wrap_cpp_moc/CMakeLists.txt19
-rw-r--r--tests/auto/cmake/test_wrap_cpp_moc/main.cpp17
3 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index 3fe358cd0b..b8d8f50d6b 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -197,6 +197,7 @@ 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)
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..4be0326971
--- /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: BSD-3-Clause
+
+#include <QObject>
+
+class MyObject2 : public QObject {
+ Q_OBJECT
+public:
+ MyObject2() = default;
+};
+
+#include "main.moc"
+
+int main()
+{
+ return 0;
+}