Skip to content

Commit

Permalink
CMake: Fix undefined symbol: qt_resourceFeatureZstd issue
Browse files Browse the repository at this point in the history
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 329dbfc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
  • Loading branch information
alcroito authored and Qt Cherry-pick Bot committed Feb 7, 2024
1 parent 7ccd63f commit 2cf327b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/corelib/Qt6CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 2cf327b

Please sign in to comment.