Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make ccache cache compilation when using absolute paths to the compiled files in different directories?

Tags:

gcc

cmake

ccache

I use CMake to create a makefiles. CMake creates GCC line containing absolute paths.

To speed up compilation I use ccache.

Building same code from different locations (e.g. several developers compile the same code, each under its home directory) causes ccache cache misses.

like image 824
dimba Avatar asked Jan 05 '10 19:01

dimba


2 Answers

As mentioned in a comment above, one problem is that any absolute paths in the preprocessor line directives are hashed by ccache, and if the compiler option -g is used, the compiler emits an absolute path to the source code file as well. Another similar problem is that if the path to the source code file is absolute on the command line, that path will be hashed if the code has an expansion of the __FILE__ macro.

The solution is to upgrade to ccache 3.0, which was released some days ago. It has optional support for rewriting absolute paths to relative paths in order to increase hit rate. See Compiling in different directories in the manual.

like image 160
Joel Rosdahl Avatar answered Nov 15 '22 07:11

Joel Rosdahl


Well, maybe stating the obvious: you'd have to either get cmake to produce relative paths, or modify ccache to consider cache entries as matching if the only difference is the absolute path.

I have modified my copy of ccache to ignore the -pipe option when calculating the hash (which is used to name the cache entries); since that option causes no difference on the compiler output, only on its speed. Maybe it wouldn't be so hard to make it strip the initial /home/*/ from paths when calculating the hash.

like image 45
Nicolás Avatar answered Nov 15 '22 07:11

Nicolás