6

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dimba
  • 26,717
  • 34
  • 141
  • 196
  • Are the absolute paths affecting GCC switches or making it into the postprocessed source? `ccache` normally only considers switches and hashed postprocessed source; the absolute paths should not matter. (`CCACHE_UNIFY` is an exception.) – ephemient Jan 05 '10 at 20:18
  • `-I/home/nicolas/src/foo/lib` is a valid gcc switch, and having another identical compile but in your directory, with `-I/home/ephemient/src/foo/lib`, would cause a cache miss; it won't match the cache entry created by my compile. I believe that's what he meant. – Nicolás Jan 05 '10 at 20:21
  • 1
    No, `ccache` explicitly ignores `-I` and other pathy flags that should only affect the preprocessor, so the common cases (like that) are fine. – ephemient Jan 05 '10 at 22:03
  • Hmm... I think if there are -I switched with absolute paths the preprocessed output would have those full paths in #line directives. Making ccache ignore that would cause compiler warnings to refer to paths in other developers' directories... – Nicolás Jan 05 '10 at 22:36
  • Hmm, I hadn't thought of that -- indeed, there will be a difference in the output when a file is actually found. Well, maybe `CCACHE_UNIFY` mode would help, as it tries to ignore trivial differences like that, at the cost of having output show wrong paths sometimes. – ephemient Jan 05 '10 at 22:48

2 Answers2

7

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.

Joel Rosdahl
  • 846
  • 9
  • 12
3

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.

Nicolás
  • 7,423
  • 33
  • 35