Changes to support amalgamation


#1

In order to respect a “one include line per file” rule (needed for a proper amalgamation), these changes are needed:

juce_core.cpp BEFORE

#if JUCE_MAC || JUCE_IOS
 #include "native/juce_osx_ObjCHelpers.h"
 #include "native/juce_mac_ObjCSuffix.h"
 #include "native/juce_posix_NamedPipe.cpp"
 #include "native/juce_posix_SharedCode.h"
 #include "native/juce_mac_Files.mm"
 #include "native/juce_mac_Network.mm"
 #include "native/juce_mac_Strings.mm"
 #include "native/juce_mac_SystemStats.mm"
 #include "native/juce_mac_Threads.mm"

//==============================================================================
#elif JUCE_WINDOWS
 #include "native/juce_win32_ComSmartPtr.h"
 #include "native/juce_win32_Files.cpp"
 #include "native/juce_win32_Network.cpp"
 #include "native/juce_win32_Registry.cpp"
 #include "native/juce_win32_SystemStats.cpp"
 #include "native/juce_win32_Threads.cpp"

//==============================================================================
#elif JUCE_LINUX
 #include "native/juce_posix_SharedCode.h"
 #include "native/juce_posix_NamedPipe.cpp"
 #include "native/juce_linux_Files.cpp"
 #include "native/juce_linux_Network.cpp"
 #include "native/juce_linux_SystemStats.cpp"
 #include "native/juce_linux_Threads.cpp"

//==============================================================================
#elif JUCE_ANDROID
 #include "native/juce_android_JNIHelpers.h"
 #include "native/juce_posix_SharedCode.h"
 #include "native/juce_posix_NamedPipe.cpp"
 #include "native/juce_android_Files.cpp"
 #include "native/juce_android_Misc.cpp"
 #include "native/juce_android_Network.cpp"
 #include "native/juce_android_SystemStats.cpp"
 #include "native/juce_android_Threads.cpp"

#endif

juce_core.cpp AFTER

//==============================================================================
#if JUCE_MAC || JUCE_IOS
 #include "native/juce_osx_ObjCHelpers.h"
 #include "native/juce_mac_ObjCSuffix.h"

#elif JUCE_ANDROID
 #include "native/juce_android_JNIHelpers.h"

#endif

#if (JUCE_MAC || JUCE_IOS) || JUCE_LINUX || JUCE_ANDROID
 #include "native/juce_posix_SharedCode.h"
 #include "native/juce_posix_NamedPipe.cpp"

#endif

//==============================================================================
#if JUCE_MAC || JUCE_IOS
 #include "native/juce_mac_Files.mm"
 #include "native/juce_mac_Network.mm"
 #include "native/juce_mac_Strings.mm"
 #include "native/juce_mac_SystemStats.mm"
 #include "native/juce_mac_Threads.mm"

//==============================================================================
#elif JUCE_WINDOWS
 #include "native/juce_win32_ComSmartPtr.h"
 #include "native/juce_win32_Files.cpp"
 #include "native/juce_win32_Network.cpp"
 #include "native/juce_win32_Registry.cpp"
 #include "native/juce_win32_SystemStats.cpp"
 #include "native/juce_win32_Threads.cpp"

//==============================================================================
#elif JUCE_LINUX
 #include "native/juce_linux_Files.cpp"
 #include "native/juce_linux_Network.cpp"
 #include "native/juce_linux_SystemStats.cpp"
 #include "native/juce_linux_Threads.cpp"

//==============================================================================
#elif JUCE_ANDROID
 #include "native/juce_android_Files.cpp"
 #include "native/juce_android_Misc.cpp"
 #include "native/juce_android_Network.cpp"
 #include "native/juce_android_SystemStats.cpp"
 #include "native/juce_android_Threads.cpp"

#endif

Jules do you see any better way of doing this?


#2

Module .cpp files #ifdef at the very beginning should look like this:

juce_core.cpp (example)

#if defined (__JUCE_CORE_JUCEHEADER__) && !defined (JUCE_AMALGAMATED_INCLUDE)
...

This goes for all the module .cpp files (juce_audio_basics.cpp, juce_audio_devices.cpp, etc…)


#3

Thanks Vinnie. Your first request is no problem, but am unclear about why you want all the module headers to have that JUCE_AMALGAMATED_INCLUDE test? Surely you’ll be setting that value to 1, so that would mean that none of these files would be processed at all…?


#4

No actually its right, because those #ifdefs are meant for sanity checking not multiple-inclusion supression:

#if defined(__JUCE_CORE_JUCEHEADER__) && !defined (JUCE_AMALGAMATED_INCLUDE)
 /* When you add this cpp file to your project, you mustn't include it in a file where you've
    already included any other headers - just put it inside a file on its own, possibly with your config
    flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix
    header files that the compiler may be using.
 */
 #error "Incorrect use of JUCE cpp file"
#endif

#5

But I’m not going to add this:

#if defined(__JUCE_CORE_JUCEHEADER__) && !defined (JUCE_AMALGAMATED_INCLUDE) /* When you add this cpp file to your project, you mustn't include it in a file where you've already included any other headers - just put it inside a file on its own, possibly with your config flags preceding it, but don't include anything else. That also includes avoiding any automatic prefix header files that the compiler may be using. */ #error "Incorrect use of JUCE cpp file" #endif

…because that would break all the normal builds.

And if I just add this:

…then that won’t help you at all, will it?

I must be missing your point!


#6

LOL!!! Yes indeed. These images should clear things up:

BEFORE
[attachment=1]JuceBefore.png[/attachment]

AFTER
[attachment=0]JuceAfter.png[/attachment]


#7

Sorry, I think I must have been looking at the header file or something, I completely misunderstood…!

Ta, will add those changes!


#8

Almost there, but not quite. The tip has

#if defined (__JUCE_DATA_STRUCTURES_JUCEHEADER__) && ! JUCE_AMALGAMATED_INCLUDE

Where it should read:

#if defined (__JUCE_DATA_STRUCTURES_JUCEHEADER__) && ! defined(JUCE_AMALGAMATED_INCLUDE)

Not sure how this compiled for you. Unlike the AppConfig.h switches, which are always defined [0,1], “JUCE_AMALGAMATED_INCLUDE” is either defined or undefined depending on whether the amalgamation is being built.


#9

It compiles just fine in all my compilers.

I always prefer to use macros as explicit boolean values, rather than just considering “being defined” to mean “true”.


#10

[quote=“jules”]It compiles just fine in all my compilers.

I always prefer to use macros as explicit boolean values, rather than just considering “being defined” to mean “true”.[/quote]

That’s not how you did it before. But if it compiles, where do you #define it to 0? I couldn’t find the line


#11

I don’t #define it to 0 anywhere. There’s no need to. Is it really failing to compile for you, or are you just assuming that it’ll fail?


#12

Yes, I was getting a compile error but it was because I was defining the macro without a particular value. I picked up the latest tip, fixed my macro definition, rebuilt the amalgamation and now it compiles without modification. Hooray!

How do you feel about this amalgamated form of Juce?


#13

As long as you can use it without me needing to make too many changes to accommodate it, then fine!


#14

Well it works now so those should be the only changes, until an include line breaks it. Can we make this official? Is it possible to incorporate this into the distribution?


#15

Is this code for generating an amalgamation from juce v2 in any publicly accessible repository? I’m trying to convert a VisualStudio project that was set-up to use juce v1 with amalgamations to use juce v2 with the modules, and it’s turning out to be a big pain in the ass. And I think it would be easier to use amalgamations for this.


#16

Yes. The amalgamation tool, the templates used to produce the Juce amalgamation (and FreeType), the Juce and FreeType amalgamations, and the 1.52 Juce amalgamation used to compile the tool are here:

http://code.google.com/p/amalgamate/source/browse/#svn%2Ftrunk

Amalgamate.cpp has usage instructions in a comment at the bottom of the file.

Let me know how this works for you - it is still a work in progress.