summaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2021-11-24 16:22:18 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2021-12-02 16:34:23 +0100
commit63b8840380e70c1258f56c67a2ec5edb5bdea53d (patch)
tree465fedceda0553c0beec5e5e0f46cd03d1d97abf /tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
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 <alexandru.croitor@qt.io>
Diffstat (limited to 'tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt')
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt106
1 files changed, 106 insertions, 0 deletions
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 0000000000..51d78dd833
--- /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()