CMake: Fix undefined symbol: qt_resourceFeatureZstd issue

When cross-compiling, host rcc might generate zstd compressed
resources, even though the target might not support zstd
decompression.

To avoid that, we made sure to disable zstd compression when using
cmake api like qt_add_resources if the target platform does not
support it.
We did not do it for CMAKE_AUTORCC though.

In such a situation, the linker would fail with:
 error: undefined symbol: qt_resourceFeatureZstd

Add the --no-zstd option to AUTORCC_OPTIONS for targets that are
created by Qt CMake public API like qt_add_executable and
qt_add_library if the target platform does not support zstd
decompression (check via the QT_FEATURE_zstd variable).

This in turn applies to our own qt_internal_add_ API as well.

Allow opting out via the QT_NO_AUTORCC_ZSTD CMake variable.

[ChangeLog][Build System] Targets created with qt_add_executable
and qt_add_library will now add the --no-zstd option to AUTORCC_OPTIONS
when the target platform does not support zstd decompression. You can
opt out via the QT_NO_AUTORCC_ZSTD cmake variable.

Pick-to: 6.6 6.5
Fixes: QTBUG-121948
Task-number: QTBUG-106466
Task-number: QTBUG-101353
Change-Id: Ibdcfecd9a4b1e206479a3f4588b1b624dd91e122
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 329dbfcc78d067d26b5a4dd99f4284900fd68f2c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2024-02-06 12:09:58 +01:00 committed by Qt Cherry-pick Bot
parent 7ccd63fd89
commit 2cf327be82

View File

@ -594,6 +594,18 @@ function(qt6_add_executable target)
endif()
endfunction()
# Just like for qt_add_resources, we should disable zstd compression when cross-compiling to a
# target that doesn't support zstd decompression, even if the host tool supports it.
# Allow an opt out via a QT_NO_AUTORCC_ZSTD variable.
function(_qt_internal_disable_autorcc_zstd_when_not_supported target)
if(TARGET "${target}"
AND DEFINED QT_FEATURE_zstd
AND NOT QT_FEATURE_zstd
AND NOT QT_NO_AUTORCC_ZSTD)
set_property(TARGET "${target}" APPEND PROPERTY AUTORCC_OPTIONS "--no-zstd")
endif()
endfunction()
function(_qt_internal_create_executable target)
if(ANDROID)
list(REMOVE_ITEM ARGN "WIN32" "MACOSX_BUNDLE")
@ -614,6 +626,7 @@ function(_qt_internal_create_executable target)
add_executable("${target}" ${ARGN})
endif()
_qt_internal_disable_autorcc_zstd_when_not_supported("${target}")
_qt_internal_set_up_static_runtime_library("${target}")
endfunction()
@ -2641,6 +2654,7 @@ function(_qt_internal_add_library target)
endif()
add_library(${target} ${type_to_create} ${arg_UNPARSED_ARGUMENTS})
_qt_internal_disable_autorcc_zstd_when_not_supported("${target}")
_qt_internal_set_up_static_runtime_library(${target})
if(NOT type_to_create STREQUAL "INTERFACE" AND NOT type_to_create STREQUAL "OBJECT")