Skip to content

Commit 1e675ff

Browse files
perf: add Release build flags for binary size reduction
Add -fvisibility=hidden, -ffunction-sections, -fdata-sections, -Wl,--gc-sections, -Wl,--strip-all, -Wl,--hash-style=gnu, -Wl,--build-id=none to Release builds. Debug builds unchanged. Release size-optimized binary: 523KB.
1 parent 5a7cc6a commit 1e675ff

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

cmake/compile/CompilerFlag.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ else()
5353
)
5454
endif()
5555

56+
# Size-reduction flags for Release builds
57+
target_compile_options(cfbox_compiler_flags INTERFACE
58+
$<$<CONFIG:Release>:-fvisibility=hidden>
59+
$<$<CONFIG:Release>:-fvisibility-inlines-hidden>
60+
$<$<CONFIG:Release>:-ffunction-sections>
61+
$<$<CONFIG:Release>:-fdata-sections>
62+
)
63+
target_link_options(cfbox_compiler_flags INTERFACE
64+
$<$<CONFIG:Release>:-Wl,--gc-sections>
65+
$<$<CONFIG:Release>:-Wl,--strip-all>
66+
$<$<CONFIG:Release>:-Wl,--hash-style=gnu>
67+
$<$<CONFIG:Release>:-Wl,--build-id=none>
68+
)
69+
5670
# ── Static linking ────────────────────────────────────────────
5771
if(CFBOX_STATIC_LINK)
5872
target_link_options(cfbox_compiler_flags INTERFACE -static)

0 commit comments

Comments
 (0)