summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Edelev <[email protected]>2021-11-24 16:22:18 +0100
committerAlexey Edelev <[email protected]>2021-12-02 16:34:23 +0100
commit63b8840380e70c1258f56c67a2ec5edb5bdea53d (patch)
tree465fedceda0553c0beec5e5e0f46cd03d1d97abf
parent7a6dd6084cb6dc3d8ad0476d9630ad7c575bca19 (diff)
Fix dependency chain that collects the metatype json files
cmake_automoc_parser has the logic preventing the run of moc with the --collect-json parameter if metatype json files are not changed. This logic only verify if the file list is changed but not their content. This change adds a timestamp file that contains the last metatype json file timestamp that was modified during the last cmake_automoc_parser run. The logic still prevents of running 'moc --collect-json' when the list of metatype json files is not changed, but also checks if their content is no changed. Another approach it to generate the depfile that can be utilized by CMake in add_custom_command as DEPFILE argument. But this concept only works from the second build attempt because of an issue related to dyndep. Pick-to: 6.2 Fixes: QTBUG-98532 Change-Id: I713f8bfa9ae769cefe0beac0b7fa19750b00a765 Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r--src/corelib/Qt6CoreMacros.cmake9
-rw-r--r--src/tools/cmake_automoc_parser/main.cpp85
-rw-r--r--tests/auto/cmake/CMakeLists.txt2
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt106
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt21
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp29
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp32
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes1
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h35
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h36
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h35
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h38
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json2
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json19
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json34
15 files changed, 447 insertions, 37 deletions
diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake
index c4d0b351207..a82cf30b363 100644
--- a/src/corelib/Qt6CoreMacros.cmake
+++ b/src/corelib/Qt6CoreMacros.cmake
@@ -1169,6 +1169,8 @@ function(qt6_extract_metatypes target)
endif()
endif()
+ set(cmake_automoc_parser_timestamp "${type_list_file}.timestamp")
+
if (NOT use_dep_files)
# When a project is configured with a Visual Studio generator, CMake's
# cmQtAutoGenInitializer::InitAutogenTarget() can take one of two code paths on how to
@@ -1198,12 +1200,15 @@ function(qt6_extract_metatypes target)
add_custom_target(${target}_automoc_json_extraction
DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
- BYPRODUCTS ${type_list_file}
+ BYPRODUCTS
+ ${type_list_file}
+ "${cmake_automoc_parser_timestamp}"
COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
--cmake-autogen-cache-file "${cmake_autogen_cache_file}"
--cmake-autogen-info-file "${cmake_autogen_info_file}"
--output-file-path "${type_list_file}"
+ --timestamp-file-path "${cmake_automoc_parser_timestamp}"
${multi_config_args}
COMMENT "Running AUTOMOC file extraction for target ${target}"
COMMAND_EXPAND_LISTS
@@ -1217,11 +1222,13 @@ function(qt6_extract_metatypes target)
add_custom_command(OUTPUT ${type_list_file}
DEPENDS ${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
${cmake_autogen_timestamp_file}
+ BYPRODUCTS "${cmake_automoc_parser_timestamp}"
COMMAND
${QT_CMAKE_EXPORT_NAMESPACE}::cmake_automoc_parser
--cmake-autogen-cache-file "${cmake_autogen_cache_file}"
--cmake-autogen-info-file "${cmake_autogen_info_file}"
--output-file-path "${type_list_file}"
+ --timestamp-file-path "${cmake_automoc_parser_timestamp}"
${multi_config_args}
COMMENT "Running AUTOMOC file extraction for target ${target}"
COMMAND_EXPAND_LISTS
diff --git a/src/tools/cmake_automoc_parser/main.cpp b/src/tools/cmake_automoc_parser/main.cpp
index 6d0214638e4..70cfcb1b688 100644
--- a/src/tools/cmake_automoc_parser/main.cpp
+++ b/src/tools/cmake_automoc_parser/main.cpp
@@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdlib>
+#include <limits>
#include <qcommandlineoption.h>
#include <qcommandlineparser.h>
@@ -46,6 +47,7 @@
#include <qset.h>
#include <qstring.h>
#include <qstack.h>
+#include <qdatastream.h>
QT_BEGIN_NAMESPACE
@@ -194,38 +196,52 @@ static bool readParseCache(ParseCacheMap &entries, const QString &parseCacheFile
return true;
}
-static bool readJsonFiles(QList<QString> &entries, const QString &filePath)
+static bool writeJsonFiles(const QList<QString> &fileList, const QString &fileListFilePath,
+ const QString &timestampFilePath)
{
-
- QFile file(filePath);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- fprintf(stderr, "Could not open: %s\n", qPrintable(filePath));
+ QFile timestampFile(timestampFilePath);
+ if (!timestampFile.open(QIODevice::ReadWrite)) {
+ fprintf(stderr, "Could not open: %s\n", qPrintable(timestampFilePath));
return false;
}
- QTextStream textStream(&file);
- QString line;
- while (textStream.readLineInto(&line)) {
- entries.push_back(line);
+ qint64 timestamp = std::numeric_limits<qint64>::min();
+ QByteArray timestampBuffer = timestampFile.readAll();
+ if (timestampBuffer.size() == sizeof(timestamp)) {
+ QDataStream istream(&timestampBuffer, QIODevice::ReadOnly);
+ istream >> timestamp;
}
- file.close();
- return true;
-}
-static bool writeJsonFiles(const QList<QString> &fileList, const QString &fileListFilePath)
-{
- QFile file(fileListFilePath);
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- fprintf(stderr, "Could not open: %s\n", qPrintable(fileListFilePath));
- return false;
+ // Check if any of the metatype json files produced by automoc is newer than the last file
+ // processed by cmake_automoc parser
+ for (const auto &jsonFile : fileList) {
+ const qint64 jsonFileLastModified =
+ QFileInfo(jsonFile).lastModified().toMSecsSinceEpoch();
+ if (jsonFileLastModified > timestamp) {
+ timestamp = jsonFileLastModified;
+ }
}
- QTextStream textStream(&file);
- for (const auto &file : fileList) {
- textStream << file << Qt::endl;
- }
+ if (timestamp != std::numeric_limits<qint64>::min() || !QFile::exists(fileListFilePath)) {
+ QFile file(fileListFilePath);
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ fprintf(stderr, "Could not open: %s\n", qPrintable(fileListFilePath));
+ return false;
+ }
- file.close();
+ QTextStream textStream(&file);
+ for (const auto &jsonFile : fileList) {
+ textStream << jsonFile << Qt::endl;
+ }
+ textStream.flush();
+
+ // Update the timestamp according the newest json file timestamp.
+ timestampBuffer.clear();
+ QDataStream ostream(&timestampBuffer, QIODevice::WriteOnly);
+ ostream << timestamp;
+ timestampFile.resize(0);
+ timestampFile.write(timestampBuffer);
+ }
return true;
}
@@ -270,6 +286,13 @@ int main(int argc, char **argv)
QStringLiteral("Set this option when using CMake with a multi-config generator"));
parser.addOption(isMultiConfigOption);
+ QCommandLineOption timestampFilePathOption(QStringLiteral("timestamp-file-path"));
+ timestampFilePathOption.setDescription(
+ QStringLiteral("The path to a timestamp file that determines whether the output"
+ " file needs to be updated."));
+ timestampFilePathOption.setValueName(QStringLiteral("timestamp file"));
+ parser.addOption(timestampFilePathOption);
+
QStringList arguments = QCoreApplication::arguments();
parser.process(arguments);
@@ -378,19 +401,9 @@ int main(int argc, char **argv)
jsonFileList.sort();
// Read Previous file list (if any)
- const QString fileListFilePath = parser.value(outputFileOption);
- QList<QString> previousList;
- QFile prev_file(fileListFilePath);
-
- // Only try to open file if it exists to avoid error messages
- if (prev_file.exists()) {
- (void)readJsonFiles(previousList, fileListFilePath);
- }
-
- if (previousList != jsonFileList || !QFile(fileListFilePath).exists()) {
- if (!writeJsonFiles(jsonFileList, fileListFilePath)) {
- return EXIT_FAILURE;
- }
+ if (!writeJsonFiles(jsonFileList, parser.value(outputFileOption),
+ parser.value(timestampFilePathOption))) {
+ return EXIT_FAILURE;
}
return EXIT_SUCCESS;
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index dfbbb19828f..8073a47c161 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -282,3 +282,5 @@ _qt_internal_test_expect_pass(test_static_resources
BINARY_ARGS "-V")
_qt_internal_test_expect_pass(test_generating_cpp_exports)
+
+_qt_internal_test_expect_pass(test_qt_extract_metatypes)
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt b/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
new file mode 100644
index 00000000000..51d78dd833d
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
@@ -0,0 +1,106 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(test_qt_extract_metatypes VERSION 0.1 LANGUAGES CXX)
+
+set(test_project_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/test_qt_extract_metatypes_project")
+set(test_project_build_dir "${CMAKE_CURRENT_BINARY_DIR}/build_qt_extract_metatypes_test_project")
+
+# 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)
+
+get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
+if (CMAKE_BUILD_TYPE AND NOT is_multi_config)
+ string(TOLOWER "qt6metatypetest_${CMAKE_BUILD_TYPE}" metatypes_file_basename)
+else()
+ string(TOLOWER "qt6metatypetest" metatypes_file_basename)
+endif()
+set(meta_types_file
+ "${test_project_build_dir}/meta_types/${metatypes_file_basename}_metatypes.json")
+
+file(REMOVE_RECURSE "${test_project_build_dir}")
+file(MAKE_DIRECTORY "${test_project_build_dir}")
+
+find_package(Qt6 COMPONENTS Core REQUIRED)
+
+include("${_Qt6CTestMacros}")
+
+macro(try_build)
+ 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()
+endmacro()
+
+macro(copy_test_header header)
+ file(COPY "${test_project_source_dir}/testdata/${header}"
+ DESTINATION "${test_project_build_dir}")
+ file(RENAME "${test_project_build_dir}/${header}" "${test_project_build_dir}/MetaType.h")
+ file(TOUCH "${test_project_build_dir}/MetaType.h")
+endmacro()
+
+macro(check_generated_metatypes_file reference expect)
+ set(reference_meta_types_file "${test_project_source_dir}/testdata/${reference}")
+ execute_process(COMMAND
+ "${CMAKE_COMMAND}"
+ -E compare_files "${meta_types_file}" "${reference_meta_types_file}"
+ RESULT_VARIABLE compare_result
+ )
+ if(NOT compare_result EQUAL ${expect})
+ message(FATAL_ERROR "${meta_types_file} and ${reference_meta_types_file} content differs")
+ endif()
+ unset(reference_meta_types_file)
+endmacro()
+
+copy_test_header(MetaTypeQ_OBJECT.h)
+
+_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 test project")
+endif()
+
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesQ_OBJECT.json 0)
+
+copy_test_header(MetaTypeQ_OBJECTandQ_PROPERTY.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json 0)
+
+copy_test_header(MetaTypeEmpty.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesEmpty.json 0)
+file(TIMESTAMP "${meta_types_file}" metatypes_timestamp)
+
+copy_test_header(MetaTypeEmptyWithComment.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesEmpty.json 0)
+
+file(TIMESTAMP "${meta_types_file}" new_metatypes_timestamp)
+
+# Depending on the way how qt_extract_metatypes executes automoc it might or might not
+# change the resulting .json file content.
+set(extract_metatypes_uses_dep_files FALSE)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") # Requires automoc changes present only in 3.17
+ if(CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
+ set(extract_metatypes_uses_dep_files TRUE)
+ endif()
+endif()
+
+if(extract_metatypes_uses_dep_files)
+ if(NOT metatypes_timestamp STREQUAL new_metatypes_timestamp)
+ message(FATAL_ERROR "${meta_types_file} timestamp is changed but should not")
+ endif()
+endif()
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt
new file mode 100644
index 00000000000..88e51a0ed17
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(qt_extract_metatypes_test_project VERSION 0.1 LANGUAGES CXX)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+find_package(Qt6 COMPONENTS Core REQUIRED)
+
+set(CMAKE_AUTOUIC ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
+qt_add_executable(MetaTypeTest
+ MetaType.cpp
+ "${CMAKE_CURRENT_BINARY_DIR}/MetaType.h"
+ main.cpp
+)
+target_include_directories(MetaTypeTest PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
+qt_extract_metatypes(MetaTypeTest)
+target_link_libraries(MetaTypeTest PRIVATE Qt6::Core)
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
new file mode 100644
index 00000000000..1b1d060c6ab
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp
@@ -0,0 +1,29 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#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
new file mode 100644
index 00000000000..7c8b707b6e8
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp
@@ -0,0 +1,32 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ return 0;
+}
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes
new file mode 100644
index 00000000000..8f4efb84e5c
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes
@@ -0,0 +1 @@
+*.json text eol=lf
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
new file mode 100644
index 00000000000..aa76129a066
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+};
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
new file mode 100644
index 00000000000..5135ee098d6
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+// Changes of no value to automoc
+};
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
new file mode 100644
index 00000000000..2fcaf3c1bb9
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+#include <QObject>
+
+class MetaType : public QObject
+{
+ Q_OBJECT
+};
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
new file mode 100644
index 00000000000..680e2a8982d
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int test READ test)
+ int test() { return 0; }
+};
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json
new file mode 100644
index 00000000000..0d4f101c7a3
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json
@@ -0,0 +1,2 @@
+[
+]
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json
new file mode 100644
index 00000000000..9393eda2dfc
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json
@@ -0,0 +1,19 @@
+[
+ {
+ "classes": [
+ {
+ "className": "MetaType",
+ "object": true,
+ "qualifiedClassName": "MetaType",
+ "superClasses": [
+ {
+ "access": "public",
+ "name": "QObject"
+ }
+ ]
+ }
+ ],
+ "inputFile": "MetaType.h",
+ "outputRevision": 68
+ }
+]
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json
new file mode 100644
index 00000000000..f6a901952d9
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json
@@ -0,0 +1,34 @@
+[
+ {
+ "classes": [
+ {
+ "className": "MetaType",
+ "object": true,
+ "properties": [
+ {
+ "constant": false,
+ "designable": true,
+ "final": false,
+ "index": 0,
+ "name": "test",
+ "read": "test",
+ "required": false,
+ "scriptable": true,
+ "stored": true,
+ "type": "int",
+ "user": false
+ }
+ ],
+ "qualifiedClassName": "MetaType",
+ "superClasses": [
+ {
+ "access": "public",
+ "name": "QObject"
+ }
+ ]
+ }
+ ],
+ "inputFile": "MetaType.h",
+ "outputRevision": 68
+ }
+]