Skip to content

Commit db92784

Browse files
committed
try to reduce target size
1 parent 1a58d82 commit db92784

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cmake_modules/BaseFunctions.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ endfunction()
193193
function(dsn_setup_compiler_flags)
194194
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
195195
add_definitions(-DDSN_BUILD_TYPE=Debug)
196-
add_definitions(-g)
197196
else()
198-
add_definitions(-g)
199197
add_definitions(-O2)
200198
add_definitions(-DDSN_BUILD_TYPE=Release)
201199
endif()
200+
# Reduce the target size when build on GitHub Actions.
201+
if("$ENV{GITHUB_ACTION}" STREQUAL "")
202+
add_definitions(-g)
203+
else()
204+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables -flto")
205+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-Bsymbolic -Wl,--gc-sections")
206+
endif()
202207
cmake_host_system_information(RESULT BUILD_HOSTNAME QUERY HOSTNAME)
203208
add_definitions(-DDSN_BUILD_HOSTNAME=${BUILD_HOSTNAME})
204209

0 commit comments

Comments
 (0)