From 4dc58c08e3bd2b568d8b930fa7e253cf966e5c41 Mon Sep 17 00:00:00 2001 From: Shishir Bhat Date: Fri, 18 Jun 2021 14:30:03 -0700 Subject: [PATCH] Make strip_symbols optional --- common/cmake/do-build-helpers.cmake | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/common/cmake/do-build-helpers.cmake b/common/cmake/do-build-helpers.cmake index de80e25c..617c3fc8 100644 --- a/common/cmake/do-build-helpers.cmake +++ b/common/cmake/do-build-helpers.cmake @@ -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 $) set(strip_destination_file ${strip_source_file}.dbg) add_custom_command( @@ -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()