Using Precompiled Headers


#1

Projects made by the Projucer doesn’t seem to use precompiled headers, which mean the build times will be much higher than necc especially for big projects. There are some topics on the concept but I haven’t found any real hands-on guide, so I thought it’s time to make one. Here we go…

Right click your project in the Solution Explorer
Select Properties, then c/c++ ->Precompiled Headers
Select Use for Precompiled Header
Set Precompiled Header file to JuceHeader.h.
Go to Advanced a few lines below in the c/c++ section
Set Forced Include File to JuceHeader.h. This is neccessary because every file using precompiled headers must include “JuceHeader.h” at the very top (o/w you’ll have to this manually in all your cpp files)

OK & Close the Properties Pages

Now create a new file and add to the solution, call it JuceHeader.cpp
It should contain just one row

#include JuceHeader.h”

Right click it in the Solution Explorer and set Precompiled Headers Option to “Create” and Precompiled Header File to JuceHeader.h

Every file in your project will now use precompiled headers which won’t work, you’ll get #error “Incorrect use of JUCE cpp file” from every juce library file. You might circumvent this, but i just found it easier to just omit these files from using precompiled headers. After all, you don’t change those a lot, do you?

Locate Juce Library Code in the Solution explorer and select all files you have there (should be named juce_audio_basics.cpp, juce_audio_devices.cpp etc, each containing just two includes)

In my project i have local copy of the juce library files. If your project links directly to the files in the juce git, the method to exclude the juce files from using prec headers might be slightly different than below.

Anyway right click your selection of juce files, select Properties, go to the Precompiled Headers section and set the Precompiled Header to

Not Using Precompiled Headers.

Ok, Close & Rebuild. Now the the build time should have fallen dramatically (procentually more the more files your project contains). In my case it drops from just over 6 minutes to 2 minutes on a 4 core atom tablet (yes, I’ve got an even faster PC where the same project went from 47 s to 22)

Any comments are welcomed…


#2

Unfortunately, your method gets overwritten the moment you decide to do another export from Projucer. I’ve hacked an older version of the Projucer to support precompiled headers; I may see if this work can be improved to run on Juce 5.


#3

Quite possible. I never use the Projucer other than for project creation.


#4

Done, please see this thread.