A notable exception to this is where an interface library is created to define a commonly used set of precompile headers in one place and then other targets link to that interface library privately. In this case, the interface library exists specifically to propagate the precompile headers to its consumers and the consumer is effectively still in control, since it decides whether to link to the interface library or not.
But how can I make it work? I tried the following:
Thank you for taking time to help with this problem.
Can you benchmark where the difference(s) are?
Comparing the build logs of the old and new approaches it seems the build time doubled. This appears to be due to precompiled headers being rebuilt for each target rather than being reused: just 1 mention of cmake_pch.hxx.pch with the old approach and 42 with the new.
There’s no guarantee that PCH is faster than any other strategy.
And yet the “old” approach was faster. My intent is to pre-compile a bunch of Qt headers once which are then reused by other targets in the project. In general, considering the two excerpts in my original post, is it expected for them to result in identical behavior?
Perhaps the doc intends to say that an INTERFACE library does not propagate precompiled headers (and in fact it precompiles nothing), but rather it propagates headers marked for precompilation which are then precompiled by each material target, independently? Thus the doc excerpt should be read as:
A notable exception to this is where an interface library is created to define a commonly used set of precompile headers to precompile in one place and then other targets link to that interface library privately. In this case, the interface library exists specifically to propagate the precompile headers to precompile to its consumers, independently from each other, and the consumer is effectively still in control, since it decides whether to link to the interface library or not.
The first signature will pass the list of precompile headers into PRECOMPILE_HEADERS or INTERFACE_PRECOMPILE_HEADERS properties.
But only the REUSE_FROM signature of target_precompile_headers will get the targets to reuse the PCH. This sets the PRECOMPILE_HEADERS_REUSE_FROM property.
What you want is a INTERFACE_PRECOMPILE_HEADERS_REUSE_FROM property, but this doesn’t exist. You would have to live with the static library approach.
If you have multiple interface libraries which you use and they all have precompile headers, they will all sum up in the target.
Whilst with pch artifacts, you can have only one, at least on MSVC, if I remember correctly. MSVC also requires that you copy the artifact. I think it would be fine for clang and gcc.