From 19215d5795973d5eb5cbb171d06335f184ac5c46 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Mon, 4 Nov 2024 08:32:10 +0300 Subject: [PATCH] thinlto with either GNUgold or LDD supported --- CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e8e74b..d1492e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,10 +175,18 @@ function(give_options_without_warnings target) $<$:-fstack-protector-all -fsanitize=undefined -fsanitize=address> $<$:-gsource-map>) - set(BUILD_SHARED_LIBRARY_FLAGS_RELEASE - -Wl,--gc-sections # TODO: is it even needed with LTO? - $<$:-Wl,-plugin-opt,cache-dir=${CMAKE_CURRENT_BINARY_DIR}/linker-cache/> - $<$:-Wl,-plugin-opt,cache-policy=prune_after=30m>) + if (CMAKE_C_COMPILER_LINKER_ID MATCHES GNUgold) + set(THINLTO_USAGE "-plugin-opt,") + endif() + if (CMAKE_C_COMPILER_LINKER_ID MATCHES LLD) + set(THINLTO_USAGE "--thinlto-") + endif() + + if (THINLTO_USAGE) + set(BUILD_SHARED_LIBRARY_FLAGS_RELEASE + $<$:-Wl,${THINLTO_USAGE}cache-dir=${CMAKE_CURRENT_BINARY_DIR}/linker-cache/> + $<$:-Wl,${THINLTO_USAGE}cache-policy=prune_after=30m>) + endif() target_compile_options(${target} PUBLIC ${BUILD_FLAGS}