From 43cd08cde3e9115753a6b3a817419f199c703405 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 29 Mar 2021 15:00:27 +1100 Subject: Prevent CMP0116 warning with CMake 3.20 or later CMake 3.20 introduced a change in the handling of relative paths in *.d depfiles referenced by custom commands. To avoid a CMP0116 policy warning, we have to explicitly set the policy to NEW and also change the relative path(s) we embed in the depfiles to be relative to CMAKE_CURRENT_BINARY_DIR rather than the top level binary directory. Fixes: QTBUG-92026 Change-Id: I1a84d29f1a8d5c48bae5bc11596806f1e0e07919 Reviewed-by: Fabian Kosmale Reviewed-by: Andrei Golubev Reviewed-by: Ulf Hermann Reviewed-by: Alexandru Croitor (cherry picked from commit 8deb1b279fad2b10598af0870dd3b0d99f5ef128) Reviewed-by: Qt Cherry-pick Bot --- src/qml/Qt6QmlMacros.cmake | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/qml') diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 6e8bfb7d37..f9af50dcad 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -767,14 +767,6 @@ function(qt6_qml_type_registration target) set(foreign_types_file "${target_binary_dir}/qmltypes/${target}_foreign_types.txt") set(type_registration_cpp_file "${target_binary_dir}/${type_registration_cpp_file_name}") - set(dependency_file_cpp "${target_binary_dir}/qmltypes/${type_registration_cpp_file_name}.d") - file(RELATIVE_PATH cpp_file_name "${${CMAKE_PROJECT_NAME}_BINARY_DIR}" "${type_registration_cpp_file}") - - set (use_dep_files FALSE) - if (CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL "Ninja Multi-Config") - set(use_dep_files TRUE) - endif() - # Enable evaluation of metatypes.json source interfaces set_target_properties(${target} PROPERTIES QT_CONSUMES_METATYPES TRUE) set(genex_list "$,INCLUDE,metatypes.json$>>") @@ -796,9 +788,22 @@ function(qt6_qml_type_registration target) message(FATAL_ERROR "Need target metatypes.json file") endif() + cmake_policy(PUSH) + set(registration_cpp_file_dep_args) - if (use_dep_files) + if (CMAKE_GENERATOR MATCHES "Ninja") # TODO: Makefiles supported too since CMake 3.20 + if(POLICY CMP0116) + # Without explicitly setting this policy to NEW, we get a warning + # even though we ensure there's actually no problem here. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/21959 + cmake_policy(SET CMP0116 NEW) + set(relative_to_dir ${CMAKE_CURRENT_BINARY_DIR}) + else() + set(relative_to_dir ${CMAKE_BINARY_DIR}) + endif() + set(dependency_file_cpp "${target_binary_dir}/qmltypes/${type_registration_cpp_file_name}.d") set(registration_cpp_file_dep_args DEPFILE ${dependency_file_cpp}) + file(RELATIVE_PATH cpp_file_name "${relative_to_dir}" "${type_registration_cpp_file}") file(GENERATE OUTPUT "${dependency_file_cpp}" CONTENT "${cpp_file_name}: $,\\\n$, \\\n>" ) @@ -833,6 +838,8 @@ function(qt6_qml_type_registration target) COMMENT "Automatic QML type registration for target ${target}" ) + cmake_policy(POP) + target_sources(${target} PRIVATE ${type_registration_cpp_file}) # Circumvent "too many sections" error when doing a 32 bit debug build on Windows with -- cgit v1.2.3