From f3302d3890bad714048364388332b373a6074064 Mon Sep 17 00:00:00 2001 From: liuneng1994 Date: Thu, 28 Nov 2024 17:18:44 +0800 Subject: [PATCH] add option ENABLE_SEPARATE_SYMBOLS --- cpp-ch/local-engine/CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cpp-ch/local-engine/CMakeLists.txt b/cpp-ch/local-engine/CMakeLists.txt index 4392b55008bf..4b1c64363646 100644 --- a/cpp-ch/local-engine/CMakeLists.txt +++ b/cpp-ch/local-engine/CMakeLists.txt @@ -174,6 +174,26 @@ else() set(LOCALENGINE_SHARED_LIB_NAME "libch.so") endif() +option(ENABLE_SEPARATE_SYMBOLS "support separate debug symbols from so" OFF) +if(ENABLE_SEPARATE_SYMBOLS) + set(SYMBOL_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/debug_symbols) + file(MAKE_DIRECTORY ${SYMBOL_OUTPUT_DIRECTORY}) + function(separate_symbols target) + add_custom_command( + TARGET ${target} + POST_BUILD + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug $ + ${SYMBOL_OUTPUT_DIRECTORY}/$.debug + COMMAND ${CMAKE_OBJCOPY} --strip-debug $ + COMMAND + ${CMAKE_OBJCOPY} + --add-gnu-debuglink=${SYMBOL_OUTPUT_DIRECTORY}/$.debug + $ + COMMENT "Separating debug symbols for target: ${target}") + endfunction() + separate_symbols(${LOCALENGINE_SHARED_LIB}) +endif() + add_custom_command( OUTPUT ${LOCALENGINE_SHARED_LIB_NAME} COMMAND ${CMAKE_COMMAND} -E rename $