How can I get the full benefit of precompiled headers while using ccache?

时间:2016-02-03 03:56:25

标签: precompiled-headers ccache

My project sometimes benefits from ccache, so I have long been using ccache. I'm now adding precompiled headers. Some sources suggest that the two are incompatible and that one must choose between them. But I find in ccache's documentation that it does support PCH on some level: https://ccache.samba.org/manual.html#_precompiled_headers

Indeed, when I try using ccache to build a .o file while using Clang's -include-pch option, I see that ccache is succeeding at caching the .o. The first compilation attempt takes 1.5 s, and a second takes only 0.05 s (because ccache has done its job).

The trouble is that if I run this same compilation command with clang++ instead of with /usr/lib/ccache/clang++, it takes 0.5 s... unless I leave off the -include-pch part, in which case it takes about 1.5 s. It seems that ccache may be causing my PCH to be ignored, or something.

I've followed the instructions (from the link above). As specified there, my ccache.conf looks like this:

sloppiness=pch_defines,time_macros

And I've tried every reasonable combination of #include, -include, -include-pch, and -fpch-preprocess I could think of. Compilation always takes 1.5 s and then 0.05 s, when it should take 0.5 s, and then 0.05 s.

Is it possible to make this work, or do I have to choose between ccache and PCH after all?

0 个答案:

没有答案
相关问题