High-level #define for Mac vs. Windows, or VS vs. Xcode?

I have a compile options file included in my AppConfig.h User area, i.e.

//==============================================================================
// [BEGIN_USER_CODE_SECTION]

// (You can add your own code in this section, and the Projucer will not overwrite it)

#include “MyJuceOptions.h"

// [END_USER_CODE_SECTION]

So "MyJuceOptions.h"apparently gets referenced before all of the Juce #defines, so you cannot use #if JUCE_WINDOWS inside it, for example.

I now need to do something differently inside that file depending on Windows vs. Mac.

Any #define I can use in there, at that point? Is there something that tells me I am inside Visual Studio vs. Xcode? Or something else that I can use to differentiate Windows vs. Mac? I hate to try to make another high-level file to specify platform, or make different options files for different platforms…

Do your defines really need to be global to the entire project, including JUCE modules? If not, one simple approach might be:

  • Create a new module which depends on juce_core
  • In the module header, include <juce_core/juce_core.h> to bring in the TargetPlatform defines
  • Add your own defines after the include
  • Add this module to your Projucer project

Your new defines will now be visible in all of your code which includes the JuceHeader.h. They won’t necessarily be visible in all JUCE modules, but that’s probably fine.

If that’s not a suitable approach, and you really do need to make global changes to JUCE code depending on platform, you could add CUSTOM_MAC=1, CUSTOM_WIN=1, CUSTOM_LINUX=1 defines to the Extra Preprocessor Definitions fields in each of the Xcode/VS/Makefile exporter options in the Projucer, and then check against those in your AppConfig block.

1 Like

I don’t see how that would work, since my “MyJuceOptions.h” file doesn’t include that, and putting that in there might cause other problems… However,

Thanks for that idea. Because, while investigating this, I looked into the Visual Studio Project’s Preprocessor Definitions, and there’s a bunch of stuff in there already that the Projucer has configured, and one of them is “_WINDOWS” - so just using #if _WINDOWS does exactly what I need. Thanks!

Leaving this here for future reference: https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html

2 Likes