Enclosed is a diff format patch for the current (as of this writing) Projucer that permits you to export Visual Studio projects that make use of precompiled headers.
A lot of people consider precompiled headers to be ugly. I don’t care about ugly. The performance benefit for precompiled headers during compilation of large projects is significant. I’m able to cut my compile times by a large percentage with precompiled headers produced by this patch.
Using precompiled headers on Visual Studio requires some setup.
To use this patch, create a precompilable hpp file, which #include’s the majority of large library headers for your project. I’ll call mine precompiled_header.hpp:
Now create a precompiled_header.cpp file and add it to your project. The base name of the file must match the base name of the precompiled header file. The precompiled_header.cpp file must contain exactly one line:
Now include this precompiled_header.cpp file in your project.
In the Exporters section of the Projucer, select the Visual Studio exporter for the version you’re using. Select the “Use precompiled headers” checkbox, and also type in the name of the precompiled header file – in this example, precompiled_header.hpp.
Save and export your project to Visual Studio solution file, open the solution file in Visual Studio, and hopefully you should enjoy much faster compile times. In particular, you will note that precompiled_header.cpp is compiled first, and then the rest of the .cpp files are compiled much more quickly, as though precompiled_header.hpp has been appended to the top of each .cpp file.
It should be straightforward to port this patch to JUCE’s other targets. I may take a crack at MacOS soon.
Precompiled headers are not a magic bullet for slow compilation. But used judiciously, precompiled headers can help save your sanity on big projects.
patch.diff.txt (9.7 KB)