Skip to content

Commit

Permalink
Enable LTO when CMake-building the MinSizeRel build type
Browse files Browse the repository at this point in the history
Enabling Link Time Optimizations is the most straightforward way
to get the minimal binary size these days (together with the
`-Os` compiler option, of course) because it ensures unused
functions from static libraries are not included in executables
linked with them.

Ticket: MEN-7819
Changelog: None
  • Loading branch information
vpodzime committed Dec 18, 2024
1 parent 90f98e4 commit dd93a95
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel")
endif()

if(${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-flto")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-flto")
endif()

if(${LIBNTECH_SEQUENCE})
list(APPEND LIBNTECH_SOURCES
"${LIBUTILS_DIR}/sequence.c" # main source
Expand Down

0 comments on commit dd93a95

Please sign in to comment.