From a5a64671c7e347bd2c792fe2f3a841a032656827 Mon Sep 17 00:00:00 2001 From: Amir Masoud Abdol Date: Fri, 5 May 2023 16:22:42 +0200 Subject: [PATCH] Remove debug symbols from Android's release build Android's toolchain file, ie., android-legacy.toolchain.cmake assumes that the default build is a Debug build, and it adds the `-g` flag to CMAKE__FLAGS, as a result, our release Android build always contains debug symbols. In this patch, I basically move the `-g` flag from CMAKE__FLAGS to CMAKE__FLAGS_DEBUG, and CMAKE__FLAGS_RELWITHDEBINFO. Fixes: QTBUG-111901 Change-Id: I31eadb07d9172c923e8beaf0ac6c6e34fe1ebefb Reviewed-by: Joerg Bornemann (cherry picked from commit 9d8a04cd1fd0a0c4ec891a9497512e4bbbaead9d) Reviewed-by: Alexandru Croitor --- cmake/QtFlagHandlingHelpers.cmake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 3674abc94c6..140c57053e4 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -993,6 +993,26 @@ function(qt_internal_set_up_config_optimizations_like_in_qmake) IN_CACHE) endif() + # Legacy Android toolchain file adds the `-g` flag to CMAKE__FLAGS, as a + # result, our release build ends up containing debug symbols. To avoid that, we + # remove the flag from CMAKE__FLAGS and add + # it to CMAKE__FLAGS_DEBUG. + # + # Note: + # The new `android.toolchain.cmake` file does not have this problem, but + # it has other issues, eg., https://github.com/android/ndk/issues/1693, so we + # cannot force it. While we do load the new toolchain, it automatically falls + # back to the legacy toolchain, ie., `android-legacy.toolchain.cmake` which + # has the problem described above. + # + # Todo: + # When the new toolchain is fixed, and it doesn't fall back to the legacy + # anymore by default, then we should be able to remove this workaround. + if(ANDROID AND ANDROID_COMPILER_FLAGS MATCHES "(^| )-g") + qt_internal_remove_compiler_flags("-g") + qt_internal_add_compiler_flags(FLAGS "-g" CONFIGS DEBUG RELWITHDEBINFO) + endif() + # Update all relevant flags in the calling scope foreach(lang ${enabled_languages}) set(flag_var_name "CMAKE_${lang}_FLAGS")