Skip to content

Commit 6f9075d

Browse files
author
Micha Kalfon
committed
Compile internal SQLite library with -ffunction-sections
When building with SQLITECPP_INTERNAL_SQLITE=ON the SQLite amalgamation source is used for generating the library. Using one big source file means all the library code will be put in a single section. When building statically linked executables the entire section will be linked even if a small portion of the library is actually used. This commit addresses this issue by setting the -ffunction-sections compiler option when building the library. As each function is placed in a section of its own the linker, when passed the --gc-sections, will throw away unused sections (functions) and reduce the executable size.
1 parent 4e3d36a commit 6f9075d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sqlite3/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ endif (SQLITE_ENABLE_JSON1)
2929

3030
if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
3131
set_target_properties(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC")
32+
33+
# Put each function in its own section to allow the linker garbage
34+
# collection to remove unused section and produced a smaller
35+
# statically-lined executables.
36+
target_compile_options(sqlite3 PRIVATE "-ffunction-sections")
3237
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
3338

3439
if (UNIX AND CMAKE_COMPILER_IS_GNUCXX)

0 commit comments

Comments
 (0)