Enable thinLTO

This commit is contained in:
Amos Bird 2020-04-29 21:43:42 +08:00
parent eee86c02da
commit 7f5467bb98
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4

View File

@ -222,6 +222,20 @@ if (COMPILER_CLANG)
# Display absolute paths in error messages. Otherwise KDevelop fails to navigate to correct file and opens a new file instead.
set(COMPILER_FLAGS "${COMPILER_FLAGS} -fdiagnostics-absolute-paths")
# We cannot afford to use LTO when compiling unitests, and it's not enough
# to only supply -fno-lto at the final linking stage. So we disable it
# completely.
if (NOT ENABLE_TESTS)
# Link time optimization
set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto=thin")
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto=thin")
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -flto=thin")
endif ()
# Always prefer llvm tools when using clang. For instance, we cannot use GNU ar when llvm LTO is enabled
set (CMAKE_AR "llvm-ar")
set (CMAKE_RANLIB "llvm-ranlib")
endif ()
option (ENABLE_LIBRARIES "Enable all libraries (Global default switch)" ON)