From 73f4fc1cd9970a04b5b123d8c3001e3f938a4898 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 12 Jul 2024 10:00:29 +0100 Subject: [PATCH] Make use of link time optimisation (#121) Signed-off-by: Juan Cruz Viotti --- DEPENDENCIES | 2 +- vendor/noa/cmake/noa/defaults.cmake | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/DEPENDENCIES b/DEPENDENCIES index d162f3e6..3914a117 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,4 +1,4 @@ vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4 -noa https://github.com/sourcemeta/noa 2bc3138b80e575786bec418c91fc2058c6836993 +noa https://github.com/sourcemeta/noa 7e26abce7a4e31e86a16ef2851702a56773ca527 jsontoolkit https://github.com/sourcemeta/jsontoolkit 0ee1179c37f989ca06a44f73e1aa3e7d71674f15 hydra https://github.com/sourcemeta/hydra 3c53d3fdef79e9ba603d48470a508cc45472a0dc diff --git a/vendor/noa/cmake/noa/defaults.cmake b/vendor/noa/cmake/noa/defaults.cmake index 21a50b3c..0709ee22 100644 --- a/vendor/noa/cmake/noa/defaults.cmake +++ b/vendor/noa/cmake/noa/defaults.cmake @@ -69,3 +69,26 @@ if(WIN32) # For DLL files set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" CACHE STRING "") endif() + +# Enable IPO/LTO to help the compiler optimize across modules. +# Only do so in release, given these optimizations can significantly +# increase build times. +# See: https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html +if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT BUILD_SHARED_LIBS) + include(CheckIPOSupported) + check_ipo_supported(RESULT ipo_supported OUTPUT ipo_supported_error) + if(ipo_supported) + # TODO: Make IPO/LTO work on Linux + LLVM + if(APPLE OR NOT NOA_COMPILER_LLVM) + message(STATUS "Enabling IPO") + cmake_policy(SET CMP0069 NEW) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) + else() + message(WARNING "Avoiding IPO on this configuration") + endif() + else() + message(WARNING "IPO not supported: ${ipo_supported_error}") + endif() + unset(ipo_supported) + unset(ipo_supported_error) +endif()