thinlto with either GNUgold or LDD supported

This commit is contained in:
veclavtalica 2024-11-04 08:32:10 +03:00
parent 1c97053675
commit 19215d5795

View File

@ -175,10 +175,18 @@ function(give_options_without_warnings target)
$<$<BOOL:${TWN_SANITIZE}>:-fstack-protector-all -fsanitize=undefined -fsanitize=address>
$<$<BOOL:${EMSCRIPTEN}>:-gsource-map>)
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,--gc-sections # TODO: is it even needed with LTO?
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:-Wl,-plugin-opt,cache-dir=${CMAKE_CURRENT_BINARY_DIR}/linker-cache/>
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:-Wl,-plugin-opt,cache-policy=prune_after=30m>)
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:-Wl,${THINLTO_USAGE}cache-dir=${CMAKE_CURRENT_BINARY_DIR}/linker-cache/>
$<$<STREQUAL:${CMAKE_C_COMPILER_ID},Clang>:-Wl,${THINLTO_USAGE}cache-policy=prune_after=30m>)
endif()
target_compile_options(${target} PUBLIC
${BUILD_FLAGS}