From 63032b52c19228040a459ec90c624b10ac565b91 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sun, 2 Mar 2025 06:41:38 +0100 Subject: [PATCH] cmake: use -flto=auto compiler flag when supported Use -flto=auto compiler flag when supported, this silence this GCC warning: > lto-wrapper: warning: using serial compilation of # LTRANS jobs This also greatly speeds-up the linkage time as it enables LTO multithreading in GCC (either by using Make jobserver if detected, either by detecting CPU cores). --- cmake/DaemonFlags.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index d36b6e17fa..f588719a1a 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -420,9 +420,13 @@ else() # Saigo NaCl compiler doesn't support LTO, the flag is accepted but linking fails # with “unable to pass LLVM bit-code files to linker” error. if (USE_LTO AND NOT NACL) - try_c_cxx_flag(LTO "-flto") + try_c_cxx_flag(LTO_AUTO "-flto=auto") - if (FLAG_LTO) + if (NOT FLAG_LTO_AUTO) + try_c_cxx_flag(LTO "-flto") + endif() + + if (FLAG_LTO_AUTO OR FLAG_LTO) # Pass all compile flags to the linker. set_linker_flag("${CMAKE_CXX_FLAGS}")