Skip to content

Commit 35717f2

Browse files
author
Nigel Stewart
committed
build: opt-in FLB_SMALL for optimising for binary size (~50% reduction)
Signed-off-by: Nigel Stewart <[email protected]>
1 parent 35ed1a2 commit 35717f2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/library")
4545
# Build Options
4646
option(FLB_ALL "Enable all features" No)
4747
option(FLB_DEBUG "Build with debug symbols" No)
48+
option(FLB_SMALL "Optimise for small size" No)
4849
option(FLB_COVERAGE "Build with code-coverage" No)
4950
option(FLB_JEMALLOC "Build with Jemalloc support" No)
5051
option(FLB_REGEX "Build with Regex support" Yes)
@@ -223,6 +224,10 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
223224
endif()
224225
endif()
225226

227+
if(FLB_SMALL)
228+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -g0 -s -fno-stack-protector -fomit-frame-pointer -DNDEBUG")
229+
endif()
230+
226231
if(FLB_COVERAGE)
227232
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage")
228233
set(CMAKE_BUILD_TYPE "Debug")

cmake/onigmo.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ endif()
1919

2020
# Onigmo (UNIX)
2121
# =============
22+
if(FLB_SMALL)
23+
ExternalProject_Add(onigmo
24+
BUILD_IN_SOURCE TRUE
25+
EXCLUDE_FROM_ALL TRUE
26+
SOURCE_DIR ${ONIGMO_SRC}
27+
INSTALL_DIR ${ONIGMO_DEST}
28+
CONFIGURE_COMMAND ./configure ${AUTOCONF_HOST_OPT} --with-pic --disable-shared --enable-static --prefix=${ONIGMO_DEST}
29+
CFLAGS=-std=gnu99\ -Wall\ -pipe\ -Os\ -g0\ -s\ -fno-stack-protector\ -fomit-frame-pointer\ -DNDEBUG
30+
BUILD_COMMAND $(MAKE)
31+
INSTALL_COMMAND $(MAKE) install)
32+
else()
2233
ExternalProject_Add(onigmo
2334
BUILD_IN_SOURCE TRUE
2435
EXCLUDE_FROM_ALL TRUE
@@ -28,6 +39,7 @@ ExternalProject_Add(onigmo
2839
CFLAGS=-std=gnu99\ -Wall\ -pipe\ -g3\ -O3\ -funroll-loops
2940
BUILD_COMMAND $(MAKE)
3041
INSTALL_COMMAND $(MAKE) install)
42+
endif()
3143

3244
# Onigmo (Windows)
3345
# ================

0 commit comments

Comments
 (0)