deplinenoise/tundra — pull request #238 by benharper123 (2014-11-30 16:33:17+00:00)
Title: Support GCC & Clang precompiled headers

The MSVC Precompiled Header switches allow one very little room for how to
go about using them, but GCC/Clang are much more flexible. It is not
immediately obvious exactly how to use precompiled headers with GCC just
by reading the documentation, because there are some subtle issues
regarding how one names the .pch files, and how one includes them, such as
with or "pch.h".
I believe I have found a solution that should work for most project
setups, so that they work equally well on MSVC, GCC, and Clang.

These rules need to be obeyed in order
for precompiled headers to work:
1. The directory where your precompiled header file lives must be in the
Includes list of your project.
2. You must always include the file using the same path, and with quotes,
not angle brackets.
For example, the following does not work:
- #include
And neither does this:
- #include "../pch.h"

I have extended the pch example so that the pch.h file takes long enough
to compile that one can see the time difference with the naked eye.

I struggled for quite a long time until I discovered this:
The path that you send the compiler via the -include flag can be the
complete path to the location of the .gch file. One's first attempt is
naturally to try "-include pch.h". This fails in several subtle ways, one
of which is a GCC (4.8.2) segfault. What we now do instead is to use
something like
-include t2-output/.../pch.h
So long as there is a pch.h.gch file in there, then the compiler will
correctly inject that as the precompiled header, and you won't be subject
to path relativity issues. This seems obvious in hindsight, but it took a
long time to discover.