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 <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
bb10
Craig Scott 2021-11-30 12:10:19 +11:00 committed by Alexandru Croitor
parent 22c92f3967
commit 5cdc82e364
1 changed files with 9 additions and 5 deletions

View File

@ -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})