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}