From db9278422ccc333ef18fd810e774679fcde24ddb Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Fri, 2 Aug 2024 00:40:44 +0800 Subject: [PATCH] try to reduce target size --- cmake_modules/BaseFunctions.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake_modules/BaseFunctions.cmake b/cmake_modules/BaseFunctions.cmake index 942f307fed..7b20c56413 100644 --- a/cmake_modules/BaseFunctions.cmake +++ b/cmake_modules/BaseFunctions.cmake @@ -193,12 +193,17 @@ endfunction() function(dsn_setup_compiler_flags) if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(-DDSN_BUILD_TYPE=Debug) - add_definitions(-g) else() - add_definitions(-g) add_definitions(-O2) add_definitions(-DDSN_BUILD_TYPE=Release) endif() + # Reduce the target size when build on GitHub Actions. + if("$ENV{GITHUB_ACTION}" STREQUAL "") + add_definitions(-g) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables -flto") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections") + endif() cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME) add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME})