4) darn pch : they are the cause of 99% of our builds being broken [in the sense of doesn't build], and this is once more related in this use case with pch (sdk.h)
They're the cause of making the build 12-15 times faster too, however. And honestly, I don't think it is really the fault of precompiled headers, rather we're probably just not using them right.
sdk.h,
sdk-common.h,
sdk-precomp.h #ifdef BLAH ... nobody understands what to use at what time, and what's valid at which time anyway
For example, if I understand your above code snippet right, then in non-PCH mode, all sources will include everything once, and then include a subset manually again, which isn't precisely the most efficient.
5) now every file is forced to work with the pch, no choice if you have a simple file that nearly needs anything from the sdk.h
Which should be perfectly alright, though. Using the whole precompiled SDK header is much more efficient than including 1-2 "small" headers such as
wxString that are not precompiled.
What I think would be the right thing is this:
- Rename CB_PRECOMP to something more understandable. Really, what does CB_PRECOMP mean? Does it say "use precompiled headers" or does it say "precompiled headers have already been parsed"? I bet half of the time, someone assumes the wrong thing. Something like USE_PRECOMP is less confusing, in my opinion.
- Have one file that includes pretty much everything. This file should be named in a way that makes clear nobody is to use it directly, such as sdk-internal.h. It might have an #error clause too, if some particular magic constant is not defined (when included directly).
- Have two properly named files which are for use with the SDK and with the application and plugins. I'm not sure about what the precisely best names would be, but it should be clear from the names that one is for the SDK and one is for the application and plugins.
One of these defines BUILDING_SDK and the other does not, that way we have DLLIMPORT and DLLEXPORT defined correctly, according to what the headers are used for. Then they define the secret constant to prevent the #error, and include sdk-internal.h. No additional magic, no ifs and whens. These two files are the ones that get precompiled in the build process. - Have every file do this:
#if USE_PRECOMP
#include "whatever-the-magical-precomp-name.h"
#else
.... 20 individual includes here
#endifThat should work correctly, and it should work with acceptable performance for the few people who don't use precompiled headers, too. It would be easy enough so nobody can do anything wrong, too. Plus, if someone is writing a plugin and is too lazy to figure out what he needs (that's me!), he can just skip the
#ifdef, and it will still work. If someone is afraid of precompiled headers, he can too just skip that line and include whatever he wants, it'll work.