Skip to content

Commit

Permalink
cmake: ccache refactorings
Browse files Browse the repository at this point in the history
add support for customize cache directory and cache size,
add ccache support for LLVM
  • Loading branch information
Andarwinux authored and shinchiro committed Mar 26, 2024
1 parent 3225bbe commit a06b491
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ set(LLVM_ENABLE_LTO "OFF" CACHE STRING "OFF, ON, Thin and Full")
option(CLANG_PACKAGES_LTO "Build each package with ThinLTO." OFF)
option(ENABLE_CCACHE "Enable ccache" OFF)
if(ENABLE_CCACHE)
set(CCACHE_MAXSIZE "500M" CACHE STRING "Size of ccache")
set(CCACHE_DIR "${MINGW_INSTALL_PREFIX}/ccache" CACHE STRING "Directory to keep ccached data")
find_program(CCACHE_EXISTS ccache NO_CACHE)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ccache_conf.in ${MINGW_INSTALL_PREFIX}/ccache/ccache.conf @ONLY)
if(NOT CCACHE_EXISTS)
set(ENABLE_CCACHE OFF)
endif()
endif()
option(LLVM_CCACHE_BUILD "Enable ccache" OFF)
if(LLVM_CCACHE_BUILD)
set(LLVM_CCACHE_MAXSIZE "500M" CACHE STRING "Size of ccache")
set(LLVM_CCACHE_DIR "${CMAKE_INSTALL_PREFIX}/llvm-ccache" CACHE STRING "Directory to keep ccached data")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/toolchain.cmake @ONLY)
set(TOOLCHAIN_FILE ${CMAKE_CURRENT_BINARY_DIR}/toolchain.cmake)
set(CLANG_FLAGS "" CACHE STRING "These flags will be added to the end of the clang args")
Expand Down
4 changes: 2 additions & 2 deletions ccache_conf.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cache_dir = "@MINGW_INSTALL_PREFIX@/ccache"
max_size = 500M
cache_dir = "@CCACHE_DIR@"
max_size = @CCACHE_MAXSIZE@
sloppiness = locale,time_macros
compiler_check = none
3 changes: 3 additions & 0 deletions cmake/toolchain_check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ elseif(COMPILER_TOOLCHAIN STREQUAL "clang")
set(llvm_libcxx "llvm-libcxx")
set(cfguard "--enable-cfguard")
set(opt "-O3")
if(LLVM_ENABLE_CCACHE)
set(llvm_ccache "-DLLVM_CCACHE_BUILD=ON -DLLVM_CCACHE_DIR=${LLVM_CCACHE_DIR} -DLLVM_CCACHE_MAXSIZE=${LLVM_CCACHE_MAXSIZE}")
endif()
endif()

if(TARGET_CPU STREQUAL "x86_64")
Expand Down
1 change: 1 addition & 0 deletions toolchain/llvm/llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ExternalProject_Add(llvm
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++
${llvm_ccache}
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
-DLLVM_TARGETS_TO_BUILD='X86,NVPTX'
Expand Down

0 comments on commit a06b491

Please sign in to comment.