Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/juce-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ module needs from it only exists from JUCE 8.0.4. The module detects it: link it
and the transitions run on `juce::Animator`, leave it out and they run on the
module's own equivalent. Nothing to configure either way.

The header is safe to include from a translation unit with a file-scope
`using namespace juce;`, in either include order. Getting there costs one thing
worth knowing about: it renames the two system-header names that would otherwise
be ambiguous with JUCE's, Carbon's `Point` and GDI's `Rectangle()`, so neither is
reachable under its own name once you include the module header. Define
`MOONBASE_DISABLE_SYSTEM_NAME_SHIM` if you need them.

## Configure + show it

```cpp
Expand Down
18 changes: 18 additions & 0 deletions include/moonbase/detail/crypto/apple_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@
#include <string_view>
#include <vector>

// MacTypes.h's global `Point` is ambiguous with juce::Point in a TU with a
// file-scope `using namespace juce;`, and MacTypes.h itself then stops parsing.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Point")
#pragma push_macro("Component")
#undef Point
#undef Component
#define Point MoonbaseCarbonDummyPointName
#define Component MoonbaseCarbonDummyCompName
#endif

#include <CommonCrypto/CommonDigest.h>
#include <Security/Security.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Point
#undef Component
#pragma pop_macro("Component")
#pragma pop_macro("Point")
#endif

#include "moonbase/detail/crypto/der.hpp"
#include "moonbase/errors.hpp"

Expand Down
13 changes: 13 additions & 0 deletions include/moonbase/detail/crypto/windows_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// wingdi.h's global `Rectangle()` is ambiguous with juce::Rectangle in a TU with
// a file-scope `using namespace juce;`.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#include <bcrypt.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif

#include "moonbase/detail/crypto/der.hpp"
#include "moonbase/errors.hpp"

Expand Down
12 changes: 12 additions & 0 deletions include/moonbase/legacy_fingerprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
// wingdi.h's global `Rectangle()`, see detail/crypto/windows_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif
#else
#include <unistd.h>
#endif
Expand Down
29 changes: 29 additions & 0 deletions include/moonbase/moonbase_device_id_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
// wingdi.h's global `Rectangle()`, see detail/crypto/windows_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -68,9 +80,26 @@
|| (defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST)) \
&& !defined(MOONBASE_FINGERPRINT_NO_IOKIT)
#define MOONBASE_FINGERPRINT_USE_IOKIT 1
// MacTypes.h's global `Point`, see detail/crypto/apple_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Point")
#pragma push_macro("Component")
#undef Point
#undef Component
#define Point MoonbaseCarbonDummyPointName
#define Component MoonbaseCarbonDummyCompName
#endif

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOKitKeys.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Point
#undef Component
#pragma pop_macro("Component")
#pragma pop_macro("Point")
#endif
#endif
#endif

Expand Down
5 changes: 5 additions & 0 deletions modules/moonbase_licensing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ needs from it only exists from JUCE 8.0.4. The module detects it: link it and th
transitions run on `juce::Animator`, leave it out and they run on the module's own
equivalent, with the same curves.

The header is safe to include from a translation unit with a file-scope
`using namespace juce;`, in either include order. See
[the JUCE module guide](../../docs/juce-module.md) for the one caveat that comes with
that.

## Configure and use

Only three fields are required; in a plugin the product and manufacturer names default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@
#include <string_view>
#include <vector>

// MacTypes.h's global `Point` is ambiguous with juce::Point in a TU with a
// file-scope `using namespace juce;`, and MacTypes.h itself then stops parsing.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Point")
#pragma push_macro("Component")
#undef Point
#undef Component
#define Point MoonbaseCarbonDummyPointName
#define Component MoonbaseCarbonDummyCompName
#endif

#include <CommonCrypto/CommonDigest.h>
#include <Security/Security.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Point
#undef Component
#pragma pop_macro("Component")
#pragma pop_macro("Point")
#endif

#include "moonbase/detail/crypto/der.hpp"
#include "moonbase/errors.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
// wingdi.h's global `Rectangle()` is ambiguous with juce::Rectangle in a TU with
// a file-scope `using namespace juce;`.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#include <bcrypt.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif

#include "moonbase/detail/crypto/der.hpp"
#include "moonbase/errors.hpp"

Expand Down
12 changes: 12 additions & 0 deletions modules/moonbase_licensing/moonbase/legacy_fingerprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
// wingdi.h's global `Rectangle()`, see detail/crypto/windows_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif
#else
#include <unistd.h>
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
// wingdi.h's global `Rectangle()`, see detail/crypto/windows_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Rectangle")
#undef Rectangle
#define Rectangle MoonbaseGdiDummyRectangleName
#endif

#include <windows.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Rectangle
#pragma pop_macro("Rectangle")
#endif
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -68,9 +80,26 @@
|| (defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST)) \
&& !defined(MOONBASE_FINGERPRINT_NO_IOKIT)
#define MOONBASE_FINGERPRINT_USE_IOKIT 1
// MacTypes.h's global `Point`, see detail/crypto/apple_backend.hpp.
#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#pragma push_macro("Point")
#pragma push_macro("Component")
#undef Point
#undef Component
#define Point MoonbaseCarbonDummyPointName
#define Component MoonbaseCarbonDummyCompName
#endif

#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOKitKeys.h>

#ifndef MOONBASE_DISABLE_SYSTEM_NAME_SHIM
#undef Point
#undef Component
#pragma pop_macro("Component")
#pragma pop_macro("Point")
#endif
#endif
#endif

Expand Down
5 changes: 4 additions & 1 deletion tests/juce/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ endif()
juce_add_console_app(MoonbaseJuceTests
PRODUCT_NAME "Moonbase JUCE Tests")

target_sources(MoonbaseJuceTests PRIVATE controller_tests.cpp)
target_sources(MoonbaseJuceTests PRIVATE
controller_tests.cpp
# Compile-only guard, see the file header.
global_using_namespace_juce.cpp)

target_compile_features(MoonbaseJuceTests PRIVATE cxx_std_17)

Expand Down
41 changes: 41 additions & 0 deletions tests/juce/global_using_namespace_juce.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// The module header must be includable from a TU with a file-scope
// `using namespace juce;`, the way HISE is written. No other TU in this repo has
// one, so without this the system-header name collisions (MacTypes.h's `Point`,
// wingdi.h's `Rectangle()`) are invisible to CI. The compile is the assertion.

#include <juce_gui_basics/juce_gui_basics.h>

using namespace juce;

#include <moonbase_licensing/moonbase_licensing.h>

#include <doctest/doctest.h>

namespace
{
// Unqualified on purpose: anything the system headers leak shows up here.
Point<float> makePoint() { return { 3.0f, 4.0f }; }
Rectangle<int> makeRectangle() { return { 0, 0, 640, 480 }; }

[[maybe_unused]] Component* component = nullptr;
[[maybe_unused]] Timer* timer = nullptr;
} // namespace

TEST_CASE("the module header survives a global using namespace juce")
{
CHECK(makePoint().getDistanceFromOrigin() == doctest::Approx(5.0f));
CHECK(makeRectangle().getWidth() == 640);

String text { "moonbase" };
MemoryBlock block { text.toRawUTF8(), text.getNumBytesAsUTF8() };
CHECK(block.getSize() == 8);

Range<int> range { 2, 7 };
CHECK(range.getLength() == 5);

Colour colour = Colours::white;
CHECK(colour.isOpaque());

moonbase::juce_integration::ActivationConfig config;
CHECK(config.resolvedDeviceIdResolver() != nullptr);
}
Loading