CMake: Handle strip wrapper creation more robustly

Unsetting CMAKE_STRIP and including CMakeFindBinUtils to find it again
is not safe, because CMakeFindBinUtils has logic to search for
additional tool names depending on the currently processed language.

The currently processed language is set in _CMAKE_PROCESSING_LANGUAGE
only when CMake is doing it's language introspection via
CMakeCXXCompiler.cmake.

This resulted in the build system finding a regular host-OS strip,
rather than an android specific llvm-strip when doing an Android
build, which then silently failed to strip the Android libraries
and caused us to ship big binaries.

Improve the strip wrapper creation in a few ways:
- Save the original strip value on first configuration
- Restore it if needed, without using CMakeFindBinUtils
- Don't apply the strip wrapper creation logic to Android,
  we currently don't need it there
- Add some informational messages about which CMAKE_STRIP
  ends up being used even if log-level is not DEBUG
- Fix a typo

Amends 39f657032b

Pick-to: 6.2 6.3
Fixes: QTBUG-103356
Task-number: QTBUG-101653
Change-Id: I23d98180446d5bb7628e783668f46e4e546ed700
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2022-05-10 16:25:16 +02:00
parent 7f94aa23f5
commit ff0ee3d985

View File

@ -66,7 +66,7 @@ function(qt_internal_try_compile_binary_for_strip binary_out_var)
endfunction() endfunction()
# When using the MinGW 11.2.0 toolchain, cmake --install --strip as used by # When using the MinGW 11.2.0 toolchain, cmake --install --strip as used by
# qt-cmake-private-intstall.cmake, removes the .gnu_debuglink section in binaries and thus # qt-cmake-private-install.cmake, removes the .gnu_debuglink section in binaries and thus
# breaks the separate debug info feature. # breaks the separate debug info feature.
# #
# Generate a wrapper shell script that passes an option to keep the debug section. # Generate a wrapper shell script that passes an option to keep the debug section.
@ -86,17 +86,27 @@ function(qt_internal_generate_binary_strip_wrapper)
return() return()
endif() endif()
# To make reconfiguration more robust when QT_INTERNAL_STRIP_SUPPORTS_KEEP_SECTION is manually # Backup the original strip path on very first configuration call.
# removed, make sure to always find the original strip first, by first removing the cached var # The value might have been determined by CMake via CMakeDetermineCXXCompiler ->
# and then finding the binary again. # CMakeFindBinUtils -> find_program(), or it might have been set by a toolchain file.
unset(CMAKE_STRIP CACHE) if(NOT QT_INTERNAL_ORIGINAL_CMAKE_STRIP AND CMAKE_STRIP)
include(CMakeFindBinUtils) set(QT_INTERNAL_ORIGINAL_CMAKE_STRIP "${CMAKE_STRIP}" CACHE INTERNAL
"Original strip binary")
endif()
message(STATUS "CMAKE_STRIP (original): ${QT_INTERNAL_ORIGINAL_CMAKE_STRIP}")
# Target Linux and MinGW. # Target Linux and MinGW.
if((UNIX OR MINGW) if((UNIX OR MINGW)
AND NOT APPLE AND NOT APPLE
AND NOT ANDROID
AND CMAKE_STRIP) AND CMAKE_STRIP)
# To make reconfiguration more robust when QT_INTERNAL_STRIP_SUPPORTS_KEEP_SECTION is
# manually removed, make sure to always restore the original strip first, by
# re-assigning the original value.
set(CMAKE_STRIP "${QT_INTERNAL_ORIGINAL_CMAKE_STRIP}" CACHE STRING "")
# Getting path to a binary we can run strip on. # Getting path to a binary we can run strip on.
qt_internal_try_compile_binary_for_strip(valid_binary_path) qt_internal_try_compile_binary_for_strip(valid_binary_path)
@ -127,7 +137,7 @@ function(qt_internal_generate_binary_strip_wrapper)
message(DEBUG message(DEBUG
"qt_internal_generate_binary_strip_wrapper:\n" "qt_internal_generate_binary_strip_wrapper:\n"
"original strip: ${CMAKE_STRIP}\n" "original strip: ${QT_INTERNAL_ORIGINAL_CMAKE_STRIP}\n"
"strip probe output: ${strip_probe_output}\n" "strip probe output: ${strip_probe_output}\n"
"strip result: ${strip_result_var}\n" "strip result: ${strip_result_var}\n"
"keep section supported: ${keep_section_supported}\n" "keep section supported: ${keep_section_supported}\n"
@ -173,15 +183,15 @@ function(qt_internal_generate_binary_strip_wrapper)
set(wrapper_out "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}${wrapper_extension}") set(wrapper_out "${QT_BUILD_DIR}/${INSTALL_LIBEXECDIR}/${script_name}${wrapper_extension}")
set(original_strip "${CMAKE_STRIP}") # Used in the template file.
set(original_strip "${QT_INTERNAL_ORIGINAL_CMAKE_STRIP}")
configure_file("${wrapper_in}" "${wrapper_out}" @ONLY) configure_file("${wrapper_in}" "${wrapper_out}" @ONLY)
# Backup the original strip path for informational purposes.
set(QT_INTERNAL_ORIGINAL_STRIP "${original_strip}" CACHE INTERNAL "Original strip binary")
# Override the strip binary to be used by CMake install target. # Override the strip binary to be used by CMake install target.
set(CMAKE_STRIP "${wrapper_out}" CACHE INTERNAL "Custom Qt strip wrapper") set(CMAKE_STRIP "${wrapper_out}" CACHE INTERNAL "Custom Qt strip wrapper")
message(STATUS "CMAKE_STRIP (used by Qt): ${CMAKE_STRIP}")
endif() endif()
endfunction() endfunction()