Skip to content

Commit 414fbb4

Browse files
committed
cmake: Configure the ThinLTO cache directory when using ELF lld or gold.
Differential Revision: https://reviews.llvm.org/D30522 llvm-svn: 296730
1 parent a528e74 commit 414fbb4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,20 @@ if(uppercase_LLVM_ENABLE_LTO STREQUAL "THIN")
715715
if(NOT LINKER_IS_LLD_LINK)
716716
append("-flto=thin" CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
717717
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()
723732
elseif(uppercase_LLVM_ENABLE_LTO STREQUAL "FULL")
724733
append("-flto=full" CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
725734
if(NOT LINKER_IS_LLD_LINK)

0 commit comments

Comments
 (0)