From fd995f36e70a39c9fb5d8c01160027a3bce1cdd7 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Thu, 26 Mar 2020 12:21:20 +0300 Subject: [PATCH 1/2] Enable interprocedural optimization --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9426b868bc..a201dc54e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,19 @@ if(ENABLE_WARNINGS) endif() endif() +option(ENABLE_LTO "Enable interprocedural optimization for Release builds." ON) +if(ENABLE_LTO) + include(CheckIPOSupported) + check_ipo_supported(RESULT H3_IPO_SUPPORTED + OUTPUT H3_IPO_CHECK_OUTPUT + LANGUAGES C) + if(H3_IPO_SUPPORTED) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) + else() + message(STATUS "IPO/LTO is not supported: ${H3_IPO_CHECK_OUTPUT}") + endif() +endif() + if(NOT MSVC) # Compiler options are set only on non-Windows, since these options are not # correct for MSVC. From 105def38d27badf6e3cc4d3c5830d2f4d3a38c11 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Mon, 4 May 2026 10:42:48 +0400 Subject: [PATCH 2/2] Enable portable LTO static archives --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a201dc54e7..eccad7ec42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,6 +381,19 @@ function(add_h3_library name h3_alloc_prefix_override) target_compile_options(${name} PRIVATE ${H3_COMPILE_FLAGS}) target_link_libraries(${name} PRIVATE ${H3_LINK_FLAGS}) target_compile_features(${name} PUBLIC c_std_99) + if(ENABLE_LTO AND H3_IPO_SUPPORTED AND NOT BUILD_SHARED_LIBS) + if(MSVC OR CMAKE_C_COMPILER_ID MATCHES "Clang") + set_target_properties( + ${name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF) + endif() + endif() + if(ENABLE_LTO AND H3_IPO_SUPPORTED AND NOT BUILD_SHARED_LIBS AND NOT MSVC) + target_compile_options( + ${name} + PRIVATE + $<$,$>:-ffat-lto-objects> + ) + endif() find_library(M_LIB m) if(NOT(M_LIB))