summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Masoud Abdol <[email protected]>2023-05-05 16:22:42 +0200
committerAmir Masoud Abdol <[email protected]>2023-06-09 09:40:25 +0000
commitf11418877aaa0cecccfa50f34979891d6d82db66 (patch)
treee3e15ccb00de6c353676ae223a8160ff43953a9a
parent424d02489608621350c3c423155fbdf4268ad1a6 (diff)
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_<LANG>_FLAGS, as a result, our release Android build always contains debug symbols. In this patch, I basically move the `-g` flag from CMAKE_<LANG>_FLAGS to CMAKE_<LANG>_FLAGS_DEBUG, and CMAKE_<LANG>_FLAGS_RELWITHDEBINFO. Fixes: QTBUG-111901 Change-Id: I31eadb07d9172c923e8beaf0ac6c6e34fe1ebefb Reviewed-by: Joerg Bornemann <[email protected]> (cherry picked from commit 9d8a04cd1fd0a0c4ec891a9497512e4bbbaead9d) Reviewed-by: Alexandru Croitor <[email protected]>
-rw-r--r--cmake/QtFlagHandlingHelpers.cmake20
1 files changed, 20 insertions, 0 deletions
diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake
index a8a57393c65..875b1a3cc7b 100644
--- a/cmake/QtFlagHandlingHelpers.cmake
+++ b/cmake/QtFlagHandlingHelpers.cmake
@@ -1000,6 +1000,26 @@ function(qt_internal_set_up_config_optimizations_like_in_qmake)
IN_CACHE)
endif()
+ # Legacy Android toolchain file adds the `-g` flag to CMAKE_<LANG>_FLAGS, as a
+ # result, our release build ends up containing debug symbols. To avoid that, we
+ # remove the flag from CMAKE_<LANGL>_FLAGS and add
+ # it to CMAKE_<LANG>_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")