User header section in JuceHeader.h


#1

Hi Jules,

could you include a user header section in JuceHeader.h that won’t be changed when rerunning the Jucer, e.g. something like:

//[Userheaders]
//[/Userheaders]

#include "AppConfig.h"
#include "juce_amalgamated.h"

namespace ProjectInfo
[...]

At the moment I use a “superheader” that I include instead of JuceHeader.h because windows.h (needed for juce_pluginHostType.h) has to be included before juce.h (in the superheader I only include windows.h and JuceHeader.h). Otherwise I get compilation errors depending of the order of compiling the source.
Maybe it might be useful to also have a post-Juce header section.

If this is a really bad idea and there is a better alternative to this (and the “superheader”) please tell me.

Chris


#2

Surely the way to do this is just to have your own “super-header” file that includes JuceHeader.h ?

It’d be silly/wasteful/dangerous to add your own headers to JuceHeaders.h, because that file is used by other jucer-generated files, which certainly won’t benefit from having a load of random 3rd party code included while they get compiled.


#3

I had a feeling that this might not be the best solution. I think I tried including windows.h where I thought it was needed (which is in quite a lot of places since I use juce_pluginHostType.h nested in classes, e.g. a class using an object from another class using an object from juce_pluginHostType.h, but had still problems while compiling and this way it seems to work.
Is there any better way than the latter done thoroughly?

Thanks,
Chris


#4

Sorry, I don’t understand the problem…


#5

Chris,

Make your own header file. In it, include the juce headers, as you may see in the generated code. In old jucer generated code you can switch out the generated header for yours (it won’t be replaced). In any other .h files, include your header file.

In your header file, add files that all your code might need. You can also put externs to global variables if needed, and common definitions you may need. Once you’ve worked out the order once, you’re good to go.

Bruce


#6

Hi Bruce,

so you have an extra header that you include above JuceHeader.h? This seems to be a much cleaner approach than what I do.

@jules:
I use a component that needs windows.h which has to be included before juce. The component is then used in PluginEditor.

component.h:
  #include "windows.h"
  #include "juce.h"

PluginEditor.h:
  #include "../JuceLibraryCode/JuceHeader.h"
  #include "../JuceLibraryCode/JucePluginCharacteristics.h"
  #include "PluginProcessor.h"
  #include "component.h"

PluginProcessor.h:
  #include "../JuceLibraryCode/JuceHeader.h"
  #include "../JuceLibraryCode/JucePluginCharacteristics.h"

component.cpp wil compile fine, but when compiling PluginEditor.cpp or PluginProcessor.cpp (or building the project) it will fail cause juce is included before windows.h.

Therefore I need something like this (maybe I could include component.h before the other headers but I don’t like that):

component.h:
  #include "windows.h"
  #include "juce.h" 

PluginEditor.h:
  #include "windows.h"
  #include "../JuceLibraryCode/JuceHeader.h"
  #include "../JuceLibraryCode/JucePluginCharacteristics.h"
  #include "PluginProcessor.h"
  #include "component.h"

PluginProcessor.h:
  #include "windows.h"
  #include "../JuceLibraryCode/JuceHeader.h"
  #include "../JuceLibraryCode/JucePluginCharacteristics.h"

And since this are all appearences off JuceHeader.h I simply made a SuperHeader.h that I include instead of JuceHeader:

SuperHeader.h:
  #include "windows.h"
  #include "../JuceLibraryCode/JuceHeader.h"

So instead of making my own header, I thought about the possibility to directly put this in the JuceHeader.h.
Though I think I will go for Bruce’s approach which has the advantage not having to mess with the jucer-generated header which I suppose is far better programming style. :slight_smile:

Chris


#7

That’s what I was trying to suggest earlier, but I guess I didn’t make myself very clear!


#8

I was translating for you Jules!