Background
I have a large Makefile
project I'm working on which I'd like to tidy up a bit. It builds several dozen sub-projects, each of which contains roughly 100 .cpp
and .h
files. I've set it up so that it's able to build debug
and release
builds for multiple operating systems (Linux, OSX/Mac, QNX, etc) and for multiple architectures (x86/i386
, x64/amd64
, armhf
, arm64/aarch64
) in parallel. This is because it's a massive project, and the only way to make it build quickly is in parallel with multiple tool chains.
I have a master rule that all projects obey that stores the intermediate objects (ie: .o
files) in temporary directories when building. So, building test.c
for Linux, arm64, release mode; would build the object file in the following sub-directory in the present working directory:
.tmp/Linux/arm64/release
Issues
This feature works without issue in my builds, but with this setup, I can't seem to properly use pre-compiled headers (ie: .GCH
files) with GCC. With my setup, I have a stdafx.h
/stdafx.cpp
pair. Using GCC, I can create a stdafx.h.gch
file easily enough. However, the project only seems to use it (which accelerates the build) if the file is in the same path as the source files. If the precompiled header is inn the intermediate object path (ie: .tmp/Linux/arm64/release
) it doesn't get detected or used. Even if I explicitly add the include path to the intermediate objects path which would contain the gch
file, it fails. Including the full path to the file name itself results in it being treated as an invalid linker script, and is ignored.
So, my first workaround was to make a rule to force all OS/arch builds to wait on initial pre-compiled header generation, rather than build a gch
on a per-OS/arch basis. However, if I build the gch
with release mode settings and attempt to make
a debug build, I get the following warning:
warning: stdafx.h.gch: created with -gnone, but used with -gdwarf-2
First, I don't know if that has severe consequences for my build, and second, different operating systems might pass different compile time define flags for the gch
generation, so this isn't a "one size fits all" use case, as far as I can see.
Question
How can I work around this so that the precompiled header is in a location other than the $PWD
and it can be detected by GCC? I'm currently using gcc v5.3.1.
Thank you.