ccache C/C++ 高速编译工具

发布时间: 更新时间: 总字数:624 阅读时间:2m 作者:IP:上海 网址

ccache C/C++ 高速编译工具

安装

bash
apt install ccache

help

ccache --help ...

使用

text
# 查看配置
ccache --show-config
CCACHE_DIR=/path-to-ccache ccache --show-config

# 修改配置
ccache --set-config KEY=VALUE
ccache --set-config debug=true
ccache --set-config debug_dir=/tmp/ccache

# 查看缓存统计
ccache --show-stats

ccache -sv

ccache -s
ccache -cCzs

# 清空统计信息
ccache -z

配置说明:

  • cache_dir 配置缓存路径,参考
  • 使用 nfs 时,要能创建软连接
  • 查看是否命中缓存,可以通过对比日志中的 Command line 是否匹配
    • export CCACHE_DEBUG=true
    • export CCACHE_DEBUGDIR=/tmp/ccache

与 CMakeLists.txt 集成

构建时,若发现安装了 ccache,自动设置 CMAKE_CXX_COMPILER_LAUNCHER

text
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
  set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
endif()

类似的工具

参考

  1. https://ccache.dev/
  2. https://github.com/ccache/ccache