# Changes to support amalgamation

**URL:** <https://forum.juce.com/t/changes-to-support-amalgamation/8196>\
**Category:** General JUCE discussion\
**Created:** [February 23, 2012, 11:33pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196 "2012-02-23T23:33:26Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 23, 2012, 11:33pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/1 "2012-02-23T23:33:26Z")

</div>

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

juce\_core.cpp BEFORE

```auto
#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

```auto
//==============================================================================
#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?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 23, 2012, 11:42pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/2 "2012-02-23T23:42:52Z")

</div>

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

juce\_core.cpp (example)

```auto
#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…)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 24, 2012, 9:39am UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/3 "2012-02-24T09:39:52Z")

</div>

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…?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 24, 2012, 4:01pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/4 "2012-02-24T16:01:47Z")

</div>

> [@jules](#):
>
> 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…?

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

```auto
#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
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 24, 2012, 5:43pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/5 "2012-02-24T17:43:56Z")

</div>

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:

```auto
#if defined ( __JUCE_CORE_JUCEHEADER__ ) && !defined (JUCE_AMALGAMATED_INCLUDE)
```

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

I must be missing your point!

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 24, 2012, 5:57pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/6 "2012-02-24T17:57:32Z")

</div>

> [@jules](#):
>
> I must be missing your point!

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

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

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 24, 2012, 6:04pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/7 "2012-02-24T18:04:06Z")

</div>

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

Ta, will add those changes!

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 25, 2012, 11:10pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/8 "2012-02-25T23:10:46Z")

</div>

> [@jules](#):
>
> Ta, will add those changes!

Almost there, but not quite. The tip has

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

Where it should read:

```auto
#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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 26, 2012, 10:09am UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/9 "2012-02-26T10:09:16Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 26, 2012, 3:03pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/10 "2012-02-26T15:03:45Z")

</div>

[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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 26, 2012, 3:14pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/11 "2012-02-26T15:14:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 26, 2012, 4:08pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/12 "2012-02-26T16:08:32Z")

</div>

> [@jules](#):
>
> Is it really failing to compile for you, or are you just assuming that it’ll fail?

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 26, 2012, 4:28pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/13 "2012-02-26T16:28:18Z")

</div>

> [@](#):
>
> How do you feel about this amalgamated form of Juce?

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

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 26, 2012, 4:30pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/14 "2012-02-26T16:30:47Z")

</div>

> [@jules](#):
>
> As long as you can use it without me needing to make too many changes to accommodate it, then fine!

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?

---

<div class="post-metadata">

**Author:** ![symfonysid](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@symfonysid](https://forum.juce.com/u/symfonysid)\
**Post date:** [March 2, 2012, 8:13pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/15 "2012-03-02T20:13:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [March 2, 2012, 9:46pm UTC](https://forum.juce.com/t/changes-to-support-amalgamation/8196/16 "2012-03-02T21:46:54Z")

</div>

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](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.
