Merge pull request #1338 from mpilman/features/stripped-binaries

Strip debug symbols with `make packages`
This commit is contained in:
Alvin Moore 2019-04-02 15:03:37 -07:00 committed by GitHub
commit b3450af8a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View File

@ -34,6 +34,7 @@ if(OPEN_FOR_IDE)
add_library(fdb_c OBJECT ${FDB_C_SRCS} ${asm_file})
else()
add_library(fdb_c SHARED ${FDB_C_SRCS} ${asm_file})
strip_debug_symbols(fdb_c)
endif()
add_dependencies(fdb_c fdb_c_generated fdb_c_options)
target_link_libraries(fdb_c PUBLIC fdbclient)
@ -54,6 +55,8 @@ if(NOT WIN32)
else()
add_executable(fdb_c_performance_test test/performance_test.c test/test.h)
add_executable(fdb_c_ryw_benchmark test/ryw_benchmark.c test/test.h)
strip_debug_symbols(fdb_c_performance_test)
strip_debug_symbols(fdb_c_ryw_benchmark)
endif()
target_link_libraries(fdb_c_performance_test PRIVATE fdb_c)
target_link_libraries(fdb_c_ryw_benchmark PRIVATE fdb_c)

View File

@ -9,6 +9,7 @@ define_property(TARGET PROPERTY COVERAGE_FILTERS
expression in this list will be ignored when the coverage.target.xml file is \
generated. This property is set through the add_flow_target function.")
function(generate_coverage_xml)
if(NOT (${ARGC} EQUAL "1"))
message(FATAL_ERROR "generate_coverage_xml expects one argument")
@ -86,6 +87,55 @@ function(assert_no_version_h target)
add_dependencies(${target} ${target_name})
endfunction()
add_custom_target(strip_targets)
add_dependencies(packages strip_targets)
function(strip_debug_symbols target)
if (WIN32)
return()
endif()
get_target_property(target_type ${target} TYPE)
if(target_type STREQUAL "EXECUTABLE")
set(path ${CMAKE_BINARY_DIR}/packages/bin)
set(is_exec ON)
else()
set(path ${CMAKE_BINARY_DIR}/packages/lib)
endif()
file(MAKE_DIRECTORY "${path}")
set(strip_command strip)
set(out_name ${target})
if(APPLE)
if(NOT is_exec)
set(out_name "lib${target}.dylib")
list(APPEND strip_command -S -x)
endif()
else()
if(is_exec)
list(APPEND strip_command --strip-debug --strip-unneeded)
else()
set(out_name "lib${target}.so")
list(APPEND strip_command --strip-all)
endif()
endif()
set(out_file "${path}/${out_name}")
list(APPEND strip_command -o "${out_file}")
add_custom_command(OUTPUT "${out_file}"
COMMAND ${strip_command} $<TARGET_FILE:${target}>
COMMENT "Stripping symbols from ${target}")
set(out_files "${out_file}")
if(is_exec AND NOT APPLE)
add_custom_command(OUTPUT "${out_file}.debug"
COMMAND objcopy --only-keep-debug $<TARGET_FILE:${target}> "${out_file}.debug" &&
objcopy --add-gnu-debuglink="${out_file}.debug" ${out_file}
DEPENDS "${out_file}"
COMMENT "Copy debug symbols to ${out_name}.debug")
list(APPEND out_files "${out_file}.debug")
endif()
add_custom_target(strip_${target} DEPENDS ${out_files})
add_dependencies(strip_${target} ${target})
add_dependencies(strip_targets strip_${target})
endfunction()
function(add_flow_target)
set(options EXECUTABLE STATIC_LIBRARY
DYNAMIC_LIBRARY)
@ -135,6 +185,7 @@ function(add_flow_target)
endif()
endforeach()
if(AFT_EXECUTABLE)
set(strip_target ON)
set(target_type exec)
add_executable(${AFT_NAME} ${sources})
endif()
@ -148,6 +199,7 @@ function(add_flow_target)
if(target_type)
message(FATAL_ERROR "add_flow_target can only be of one type")
endif()
set(strip_target ON)
add_library(${AFT_NAME} DYNAMIC ${sources})
endif()
@ -158,6 +210,9 @@ function(add_flow_target)
add_dependencies(${AFT_NAME} ${AFT_NAME}_actors)
assert_no_version_h(${AFT_NAME}_actors)
generate_coverage_xml(${AFT_NAME})
if(strip_target)
strip_debug_symbols(${AFT_NAME})
endif()
endif()
target_include_directories(${AFT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
endfunction()