From 5cdc82e36469093fe577aeb95915a55b4cafa029 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Tue, 30 Nov 2021 12:10:19 +1100 Subject: [PATCH] Fall back to include() method for finalizers with CMake 3.17 or earlier Functionality is being added in other repos which require finalizers to be run for non-static builds. That means we now need to ensure finalizers always run even with CMake versions before cmake_language() was added. The fallback method of writing to a file and including it is slower, but that's better than missing important functionality altogether. Task-number: QTBUG-98545 Pick-to: 6.2 Change-Id: Ic8668c91c26d0c30de084b1b803032088c10fcf4 Reviewed-by: Qt CI Bot Reviewed-by: Joerg Bornemann Reviewed-by: Fabian Kosmale --- src/corelib/Qt6CoreMacros.cmake | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/corelib/Qt6CoreMacros.cmake b/src/corelib/Qt6CoreMacros.cmake index eafdd02695..1136fcbc5a 100644 --- a/src/corelib/Qt6CoreMacros.cmake +++ b/src/corelib/Qt6CoreMacros.cmake @@ -702,11 +702,15 @@ function(_qt_internal_finalize_executable target) if(finalizers) if(CMAKE_VERSION VERSION_LESS 3.18) - # cmake_language() not available - message(WARNING - "Skipping module-specific finalizers for target ${target} " - "(requires CMake 3.18 or later)" - ) + # cmake_language() not available, fall back to the slower method of + # writing a file and including it + set(contents "") + foreach(finalizer_func IN LISTS finalizers) + string(APPEND contents "${finalizer_func}(${target})\n") + endforeach() + set(finalizer_file "${CMAKE_CURRENT_BINARY_DIR}/.qt/finalize_${target}.cmake") + file(WRITE ${finalizer_file} "${contents}") + include(${finalizer_file}) else() foreach(finalizer_func IN LISTS finalizers) cmake_language(CALL ${finalizer_func} ${target})