如何在 CMake 中使用 CCache? [英] How to Use CCache with CMake?
问题描述
我想执行以下操作:如果 PATH 中存在 CCache,则使用ccache g++"进行编译,否则使用 g++.我尝试编写一个包含
I would like to do the following: If CCache is present in PATH, use "ccache g++" for compilation, else use g++. I tried writing a small my-cmake script containing
CC="ccache gcc" CXX="ccache g++" cmake $*
但它似乎不起作用(运行 make 仍然不使用 ccache;我使用 CMAKE_VERBOSE_MAKEFILE 进行了检查).
but it does not seem to work (running make still does not use ccache; I checked this using CMAKE_VERBOSE_MAKEFILE on).
更新:
根据 此链接,我尝试将脚本更改为>
As per this link I tried changing my script to
cmake -D CMAKE_CXX_COMPILER="ccache" -D CMAKE_CXX_COMPILER_ARG1="g++" -D CMAKE_C_COMPILER="ccache" -D CMAKE_C_COMPILER_ARG1="gcc" $*
但是 cmake 抱怨使用编译器 ccache 时测试失败(这是可以预期的).
but cmake bails out complaining that a test failed on using the compiler ccache (which can be expected).
推荐答案
我个人在我的 $PATH
中有 /usr/lib/ccache
.该目录包含大量符号链接,用于调用编译器的每个可能名称(如 gcc
和 gcc-4.3
),都指向 ccache.
I personally have /usr/lib/ccache
in my $PATH
. This directory contains loads of symlinks for every possible name the compiler could be called from (like gcc
and gcc-4.3
), all pointing to ccache.
我什至没有创建符号链接.当我在 Debian 上安装 ccache 时,该目录已预先填充.
And I didn't even create the symlinks. That directory comes pre-filled when I install ccache on Debian.
这篇关于如何在 CMake 中使用 CCache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!