Understanding JUCE modules - where are the include files?

I’m rather new to JUCE and I’m trying to understand the magic of how the cross-platform approach works.

While digging through the files, I found a number of files that don’t have any #include directives e.g. juce_opengl/opengl/juce_OpenGLContext.h. The class uses a number of definitions of other JUCE classes and I’m wondering where they’re coming from.

I also can’t find any precompiled header file in my Xcode project.

Can anyone enlighten me?

All the JUCE modules have a header file of the same name in the top level of the directory. That’s where all the important including is done.

See this:

Thanks for your reply! I did read this file already but it doesn’t explain to me why e.g. the juce_OpenGLContext.h knows all the types it uses. The class definition uses many other classes without including their header files.

The module header includes the juce_OpenGLContext.h file which explains why including the module header is sufficient if I want to use any of the OpenGL classes.

Take this snippet (I removed the comments for better readability):

namespace juce
{
class OpenGLTexture;

class JUCE_API  OpenGLContext
{
public:
    OpenGLContext();

    /** Destructor. */
    ~OpenGLContext();

    void setRenderer (OpenGLRenderer*) noexcept;
    ...

Where does the OpenGLRenderer definition come from?

To use JUCE modules you only ever include the main header file, so you can rely upon the order of includes done there. By the time we include opengl/juce_OpenGLContext.h we’ve already included other OpenGL headers.

You can think of inclusion as having the contents of #included files pasted into the file they are included in. So by the time we reach juce_OpenGLContext.h all the definitions are available in the same compilation unit.

Ok, I get it now… I was so confused that I completely forgot that #include doesn’t do anything “magic” but copying the included file’s content at the #include destination.

That now also explains why the JUCE modules are only referenced and not added to the target.

Thanks for your explanation!