@@ -715,11 +715,20 @@ if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
715
715
if (NOT LINKER_IS_LLD_LINK )
716
716
append ("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS )
717
717
endif ()
718
- # On darwin, enable the lto cache. This improves initial build time a little
719
- # since we re-link a lot of the same objects, and significantly improves
720
- # incremental build time.
721
- append_if (APPLE "-Wl,-cache_path_lto,${PROJECT_BINARY_DIR} /lto.cache"
722
- CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS )
718
+ # If the linker supports it, enable the lto cache. This improves initial build
719
+ # time a little since we re-link a lot of the same objects, and significantly
720
+ # improves incremental build time.
721
+ # FIXME: We should move all this logic into the clang driver.
722
+ if (APPLE )
723
+ append ("-Wl,-cache_path_lto,${PROJECT_BINARY_DIR} /lto.cache"
724
+ CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS )
725
+ elseif (UNIX AND LLVM_USE_LINKER STREQUAL "lld" )
726
+ append ("-Wl,--thinlto-cache-dir=${PROJECT_BINARY_DIR} /lto.cache"
727
+ CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS )
728
+ elseif (LLVM_USE_LINKER STREQUAL "gold" )
729
+ append ("-Wl,--plugin-opt,cache-dir=${PROJECT_BINARY_DIR} /lto.cache"
730
+ CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS )
731
+ endif ()
723
732
elseif (uppercase_LLVM_ENABLE_LTO STREQUAL "FULL" )
724
733
append ("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS )
725
734
if (NOT LINKER_IS_LLD_LINK )
0 commit comments