From c7ce20c57bdcea4fca16c38b504e5de6f92e78dc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 27 Feb 2025 06:03:14 +0100 Subject: [PATCH] Enable link-time optimizations Signed-off-by: DL6ER --- src/CMakeLists.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0215eb691..7ab5a0115 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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= 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}\")