Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions common/cmake/do-build-helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,17 @@ macro (add_do_version_lib target_name maj_min_patch_ver)
add_subdirectory(${do_project_root_SOURCE_DIR}/common ${CMAKE_CURRENT_BINARY_DIR}/common)
endmacro ()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# Ensure that objcopy is present
find_program(OBJCOPY objcopy)
if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
message(FATAL_ERROR "objcopy not found")
endif()
endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

# From https://github.com/dotnet/coreclr/pull/3872/files
# For minsizerel build, split unneeded symbols from target binary file and into a separate .dbg file.
# Reduces the installed size on disk of our binaries while still making symbols available for debugging.
function(strip_symbols targetName)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
string(TOLOWER ${CMAKE_BUILD_TYPE} MY_BUILD_TYPE)
string(TOLOWER ${CMAKE_BUILD_TYPE} MY_BUILD_TYPE)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND MY_BUILD_TYPE STREQUAL minsizerel)

if(MY_BUILD_TYPE STREQUAL minsizerel)
find_program(OBJCOPY objcopy)
if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
message(WARNING "objcopy not found. Binaries will not be stripped.")
else()
set(strip_source_file $<TARGET_FILE:${targetName}>)
set(strip_destination_file ${strip_source_file}.dbg)
add_custom_command(
Expand All @@ -131,7 +126,7 @@ function(strip_symbols targetName)
COMMAND ${OBJCOPY} --strip-unneeded ${strip_source_file}
COMMAND ${OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file}
COMMENT Stripping symbols from ${strip_source_file} into file ${strip_destination_file})
endif(MY_BUILD_TYPE STREQUAL minsizerel)
endif()

endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif()
endfunction()