Skip to content

Commit

Permalink
build: Enhance Ccache performance across worktrees and build trees
Browse files Browse the repository at this point in the history
To maximize performance, it is essential to follow the recommendations
in the Productivity Notes: set the `base_dir` Ccache configuration
option or use the `CCACHE_BASEDIR` environment variable.
  • Loading branch information
hebasto committed Jan 16, 2025
1 parent 98939ce commit 4d3f360
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmake/ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit/.

if(NOT MSVC)
# The <LANG>_COMPILER_LAUNCHER target property, used to integrate
# Ccache, is supported only by the Makefiles and Ninja generators.
if(CMAKE_GENERATOR MATCHES "Makefiles|Ninja")
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
execute_process(
Expand All @@ -17,8 +19,11 @@ if(NOT MSVC)
)
set(WITH_CCACHE ON)
elseif(WITH_CCACHE)
list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
foreach(lang IN ITEMS C CXX OBJCXX)
set(CMAKE_${lang}_COMPILER_LAUNCHER
${CMAKE_COMMAND} -E env CCACHE_NOHASHDIR=1 ${CCACHE_EXECUTABLE}
)
endforeach()
endif()
else()
set(WITH_CCACHE OFF)
Expand Down

0 comments on commit 4d3f360

Please sign in to comment.