diff --git a/CMakeLists.txt b/CMakeLists.txt index feef2e1a678..582d76e79c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)