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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With