Add ability to pass arguments to CMAKE_STRIP
Starting with binutils version 2.34 the strip utility gained a --keep-section
feature.
With MinGW 11.2.0 we noticed that cmake --install --strip
was removing the .gnu_debuglink
sections that are used by gdb to load separate debug information files.
See https://bugreports.qt.io/browse/QTBUG-101653 for how this affects Qt.
I came up with a patch which is a bit hacky:
diff --git a/cmake/QtSeparateDebugInfo.cmake b/cmake/QtSeparateDebugInfo.cmake
index 00ac4519fe..80421d62a6 100644
--- a/cmake/QtSeparateDebugInfo.cmake
+++ b/cmake/QtSeparateDebugInfo.cmake
@@ -4,6 +4,21 @@ if(CMAKE_VERSION VERSION_LESS 3.17.0)
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})
endif()
+# cmake --install --strip will remove the .gnu_debuglink section
+# and break separate debug info feature for MinGW 11.2.0
+if ((UNIX OR MINGW) AND NOT APPLE AND NOT CMAKE_STRIP MATCHES ".*gnu_debuglink.*")
+ execute_process(
+ COMMAND ${CMAKE_STRIP} --keep-section=.gnu_debuglink non-existing-file
+ OUTPUT_VARIABLE strip_probe_output
+ ERROR_VARIABLE strip_probe_output)
+
+ if (NOT strip_probe_output MATCHES ".*unknown option -- keep-section=\.gnu_debuglink.*")
+ # CMAKE_STRIP is used in install scripts as argument to execute_process, the quotes are there
+ # to separate the --keep-section argument from the COMMAND containing the path to strip executable
+ set(CMAKE_STRIP "${CMAKE_STRIP}\" --keep-section=.gnu_debuglink \"" CACHE FILEPATH "" FORCE)
+ endif()
+endif()
+
# Enable separate debug information for the given target
function(qt_enable_separate_debug_info target installDestination)
set(flags QT_EXECUTABLE)
It would be better if CMake would allow passing options to the CMAKE_STRIP
invocation.