BR: CMake builds should not add `using namespace juce;` by default

CMake builds should not add using namespace juce; by default. The Projucer no longer adds this by default, neither should cmake. If you want this, which you shouldn’t, it should be opt in.

I know this isn’t really a bug, since it’s documented to work this way, but I still think it’s wrong to default on.

Where is the CMake build adding it?

I don’t get it in my code and I don’t think I did something special to not be using the juce namespace.

I need to add DONT_SET_USING_JUCE_NAMESPACE=1 to my cmake file or it gets added from:

#if ! DONT_SET_USING_JUCE_NAMESPACE
 // If your code uses a lot of JUCE classes, then this will obviously save you
 // a lot of typing, but can be disabled by setting DONT_SET_USING_JUCE_NAMESPACE.
 using namespace juce;
#endif

in JuceHeader.h

I assume this was originally done to match the behaviour of a Projucer project. Although the Projucer no longer adds this it feels a little less safe to change it for CMake as it will impact existing projects and not just new projects. I’ll pass it by the team, maybe one for JUCE 8.

The best way to control what symbols get pulled into your build is to not use JuceHeader and just directly include the module headers you need.

2 Likes