Skip to content

Commit

Permalink
Enable link-time optimizations
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 27, 2025
1 parent 3158465 commit c7ce20c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ add_custom_target(
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/version.c
COMMENT "Generating version.c using gen_version.cmake")

# Add link-time optimization (LTO)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
# -flto=<NUM_CORES> means that we use the number of available cores for LTO
#
# -fuse-linker-plugin: Use the linker plugin for LTO. This generally
# improves the LTO performance
#
# -fno-fat-lto-objects: Do not generate fat LTO objects. This means the
# generated object files are smaller but linking without LTO is not possible
#
# -fwhole-program: Assume that the current compilation unit is the whole
# program. This allows the compiler to perform more aggressive optimizations
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto=auto -fuse-linker-plugin -fno-fat-lto-objects -fwhole-program")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto=auto -fuse-linker-plugin -fno-fat-lto-objects -fwhole-program")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto=auto -fuse-linker-plugin -fno-fat-lto-objects -fwhole-program")
endif()

# Build the FTL binary

add_library(core OBJECT ${sources})
target_compile_options(core PRIVATE ${EXTRAWARN})
target_compile_definitions(core PRIVATE DNSMASQ_VERSION=\"${DNSMASQ_VERSION}\")
Expand Down

0 comments on commit c7ce20c

Please sign in to comment.