diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -162,17 +162,32 @@ endif() endif() +# Build llvm with BuildCache if the package is present +set(LLVM_BUILDCACHE_BUILD OFF CACHE BOOL "Set to ON for a BuildCache enabled build") +if(LLVM_BUILDCACHE_BUILD) + find_program(BUILDCACHE_PROGRAM buildcache) + if(BUILDCACHE_PROGRAM) + set(LLVM_BUILDCACHE_DIR "" CACHE STRING "Directory to keep BuildCached data") + if (LLVM_BUILDCACHE_DIR) + set(BUILDCACHE_PROGRAM "BUILDCACHE_DIR=${LLVM_BUILDCACHE_DIR} ${BUILDCACHE_PROGRAM}") + endif() + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BUILDCACHE_PROGRAM}) + else() + message(FATAL_ERROR "Unable to find the program BuildCache. Set LLVM_BUILDCACHE_BUILD to OFF") + endif() +endif() + option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF) # Some features of the LLVM build may be disallowed when dependency debugging is -# enabled. In particular you cannot use ccache because we want to force compile -# operations to always happen. +# enabled. In particular you cannot use ccache or BuildCache because we want to +# force compile operations to always happen. if(LLVM_DEPENDENCY_DEBUGGING) if(NOT CMAKE_HOST_APPLE) message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.") endif() - if(LLVM_CCACHE_BUILD) - message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.") + if(LLVM_CCACHE_BUILD OR LLVM_BUILDCACHE_BUILD) + message(FATAL_ERROR "Cannot enable dependency debugging while using ccache or BuildCache.") endif() endif() diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst --- a/llvm/docs/CMake.rst +++ b/llvm/docs/CMake.rst @@ -646,6 +646,11 @@ options, which are passed to the CCACHE_MAXSIZE and CCACHE_DIR environment variables, respectively. +**LLVM_BUILDCACHE_BUILD**:BOOL + If enabled and the ``buildcache`` program is available, then LLVM will be + built using ``buildcache`` to speed up rebuilds of LLVM and its components. + Defaults to OFF. + **LLVM_FORCE_USE_OLD_TOOLCHAIN**:BOOL If enabled, the compiler and standard library versions won't be checked. LLVM may not compile at all, or might fail at runtime due to known bugs in these