From 47d6530ddfe1d1aff8b10208ca9b6e4aac083ed7 Mon Sep 17 00:00:00 2001 From: Kai Buschulte Date: Tue, 16 Aug 2022 06:30:45 +0000 Subject: [PATCH] Enable CMake LTO/IPO support (WITH_LTO option) Makefiles already support an option to enable link time optimizations. This is now also possible in CMake by using the WITH_LTO option. It's turned on by default if the compiler supports these flags. Note: LTO is part of the inter-procedural optimization (IPO). Signed-off-by: Kai Buschulte --- CMakeLists.txt | 11 +++++++++++ ChangeLog.txt | 1 + 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9568ae52..1e38a1a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,17 @@ if(WITH_CJSON) endif() endif() +option(WITH_LTO "Build with link time optimizations (IPO) / interprocedural optimization (IPO) enabled." ON) +if(WITH_LTO) + include(CheckIPOSupported) + check_ipo_supported(RESULT is_ipo_supported OUTPUT output) + if(is_ipo_supported) + set_property(TARGET common-options PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + message(WARNING "LTO/IPO is not supported: ${output}") + endif() +endif() + # ======================================== # Include projects # ======================================== diff --git a/ChangeLog.txt b/ChangeLog.txt index bea8562f..a69645ae 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -158,6 +158,7 @@ Clients: Build: - Increased CMake minimal required version to 3.14, which is required for the preinstalled SQLite3 find module. +- Add an CMake option `WITH_LTO` to enable/disable link time optimization. 2.0.14 - 2021-11-17