Skip to content

Commit

Permalink
MinGW: Improve compatibility
Browse files Browse the repository at this point in the history
With this patch applied, the DemoRunner should build under MinGW, and be
(nearly) feature-complete compared to the MSVC build.

Specifically, when building with MinGW:
- Adds support for accessibility
- Fixes build issues in the juce_video module
- Fixes a link issue in the VST3 wrapper when VST3_CAN_REPLACE_VST2 is
  defined
- Adds support for the new-style native FileChooser
- Tidies up some other low-severity warnings

Known issues:
- Direct2D rendering is still not supported when building with MinGW due
  to ABI compatibilities.
  • Loading branch information
reuk committed Jan 17, 2022
1 parent b65803e commit 640194c
Show file tree
Hide file tree
Showing 37 changed files with 1,285 additions and 480 deletions.
6 changes: 3 additions & 3 deletions extras/Build/CMake/JUCEHelperTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIA
$<$<CONFIG:Release>:$<IF:$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">,-GL,-flto>>)
target_link_libraries(juce_recommended_lto_flags INTERFACE
$<$<CONFIG:Release>:$<$<STREQUAL:"${CMAKE_CXX_COMPILER_ID}","MSVC">:-LTCG>>)
elseif((CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
elseif((NOT MINGW) AND ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")))
target_compile_options(juce_recommended_lto_flags INTERFACE $<$<CONFIG:Release>:-flto>)
target_link_libraries(juce_recommended_lto_flags INTERFACE $<$<CONFIG:Release>:-flto>)
endif()
6 changes: 4 additions & 2 deletions modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ JUCE_BEGIN_NO_SANITIZE ("vptr")

#if JUCE_VST3_CAN_REPLACE_VST2

#if ! JUCE_MSVC
#if ! JUCE_MSVC && ! defined (__cdecl)
#define __cdecl
#endif

Expand Down Expand Up @@ -3541,10 +3541,12 @@ DECLARE_CLASS_IID (JuceAudioProcessor, 0x0101ABAB, 0xABCDEF01, JucePlugin_Manufa
DEF_CLASS_IID (JuceAudioProcessor)

#if JUCE_VST3_CAN_REPLACE_VST2
// Defined in PluginUtilities.cpp
void getUUIDForVST2ID (bool, uint8[16]);

FUID getFUIDForVST2ID (bool forControllerUID)
{
TUID uuid;
extern JUCE_API void getUUIDForVST2ID (bool, uint8[16]);
getUUIDForVST2ID (forControllerUID, (uint8*) uuid);
return FUID (uuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
#define JucePlugin_Build_RTAS 0
#endif

#if ! (defined (_MSC_VER) || defined (__APPLE_CPP__) || defined (__APPLE_CC__) || defined (LINUX) || defined (__linux__))
#undef JucePlugin_Build_VST3
#define JucePlugin_Build_VST3 0
#endif

//==============================================================================
#if JucePlugin_Build_LV2 && ! defined (JucePlugin_LV2URI)
#error "You need to define the JucePlugin_LV2URI value!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace juce
#define VST3_REPLACEMENT_AVAILABLE 1

// NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
void getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
{
#if JUCE_MSVC
const auto juce_sprintf = [] (auto&& head, auto&&... tail) { sprintf_s (head, numElementsInArray (head), tail...); };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ struct VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0

tresult getInt (Steinberg::int64& result) const
{
if (kind != Kind::Int)
if (kind != Kind::tagInt)
return kResultFalse;

result = storage.storedInt;
Expand All @@ -590,7 +590,7 @@ struct VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0

tresult getFloat (double& result) const
{
if (kind != Kind::Float)
if (kind != Kind::tagFloat)
return kResultFalse;

result = storage.storedFloat;
Expand All @@ -599,7 +599,7 @@ struct VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0

tresult getString (Vst::TChar* data, Steinberg::uint32 numBytes) const
{
if (kind != Kind::String)
if (kind != Kind::tagString)
return kResultFalse;

std::memcpy (data,
Expand All @@ -610,7 +610,7 @@ struct VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0

tresult getBinary (const void*& data, Steinberg::uint32& numBytes) const
{
if (kind != Kind::Binary)
if (kind != Kind::tagBinary)
return kResultFalse;

data = storage.storedBinary.data();
Expand All @@ -619,34 +619,34 @@ struct VST3HostContext : public Vst::IComponentHandler, // From VST V3.0.0
}

private:
void constructFrom (Int x) noexcept { kind = Kind::Int; new (&storage.storedInt) Int (std::move (x)); }
void constructFrom (Float x) noexcept { kind = Kind::Float; new (&storage.storedFloat) Float (std::move (x)); }
void constructFrom (String x) noexcept { kind = Kind::String; new (&storage.storedString) String (std::move (x)); }
void constructFrom (Binary x) noexcept { kind = Kind::Binary; new (&storage.storedBinary) Binary (std::move (x)); }
void constructFrom (Int x) noexcept { kind = Kind::tagInt; new (&storage.storedInt) Int (std::move (x)); }
void constructFrom (Float x) noexcept { kind = Kind::tagFloat; new (&storage.storedFloat) Float (std::move (x)); }
void constructFrom (String x) noexcept { kind = Kind::tagString; new (&storage.storedString) String (std::move (x)); }
void constructFrom (Binary x) noexcept { kind = Kind::tagBinary; new (&storage.storedBinary) Binary (std::move (x)); }

void reset() noexcept
{
switch (kind)
{
case Kind::Int: break;
case Kind::Float: break;
case Kind::String: storage.storedString.~vector(); break;
case Kind::Binary: storage.storedBinary.~vector(); break;
case Kind::tagInt: break;
case Kind::tagFloat: break;
case Kind::tagString: storage.storedString.~vector(); break;
case Kind::tagBinary: storage.storedBinary.~vector(); break;
}
}

void moveFrom (Attribute&& other) noexcept
{
switch (other.kind)
{
case Kind::Int: constructFrom (std::move (other.storage.storedInt)); break;
case Kind::Float: constructFrom (std::move (other.storage.storedFloat)); break;
case Kind::String: constructFrom (std::move (other.storage.storedString)); break;
case Kind::Binary: constructFrom (std::move (other.storage.storedBinary)); break;
case Kind::tagInt: constructFrom (std::move (other.storage.storedInt)); break;
case Kind::tagFloat: constructFrom (std::move (other.storage.storedFloat)); break;
case Kind::tagString: constructFrom (std::move (other.storage.storedString)); break;
case Kind::tagBinary: constructFrom (std::move (other.storage.storedBinary)); break;
}
}

enum class Kind { Int, Float, String, Binary };
enum class Kind { tagInt, tagFloat, tagString, tagBinary };

union Storage
{
Expand Down
4 changes: 3 additions & 1 deletion modules/juce_core/native/juce_BasicNativeHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@
#define STRICT 1
#define WIN32_LEAN_AND_MEAN 1
#if JUCE_MINGW
#define _WIN32_WINNT 0x0600
#if ! defined (_WIN32_WINNT)
#define _WIN32_WINNT 0x0600
#endif
#else
#define _WIN32_WINNT 0x0602
#endif
Expand Down
2 changes: 0 additions & 2 deletions modules/juce_core/native/juce_win32_Threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ void CriticalSection::exit() const noexcept { LeaveCriticalSection ((CRI


//==============================================================================
void JUCE_API juce_threadEntryPoint (void*);

static unsigned int STDMETHODCALLTYPE threadEntryProc (void* userData)
{
if (juce_messageWindowHandle != nullptr)
Expand Down
2 changes: 1 addition & 1 deletion modules/juce_core/system/juce_PlatformDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace juce
#pragma intrinsic (__debugbreak)
#endif
#define JUCE_BREAK_IN_DEBUGGER { __debugbreak(); }
#elif JUCE_INTEL && (JUCE_GCC || JUCE_MAC || JUCE_CLANG)
#elif JUCE_INTEL && (JUCE_GCC || JUCE_CLANG || JUCE_MAC)
#if JUCE_NO_INLINE_ASM
#define JUCE_BREAK_IN_DEBUGGER { }
#else
Expand Down
6 changes: 1 addition & 5 deletions modules/juce_core/time/juce_Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ String Time::getTimeZone() const
{
String zone[2];

#if JUCE_WINDOWS
#if JUCE_MSVC || JUCE_CLANG
#if JUCE_WINDOWS && (JUCE_MSVC || JUCE_CLANG)
_tzset();

for (int i = 0; i < 2; ++i)
Expand All @@ -390,9 +389,6 @@ String Time::getTimeZone() const
_get_tzname (&length, name, sizeof (name) - 1, i);
zone[i] = name;
}
#else
#warning "Can't find a replacement for tzset on mingw - ideas welcome!"
#endif
#else
tzset();

Expand Down
8 changes: 8 additions & 0 deletions modules/juce_graphics/juce_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
#endif

#if JUCE_USE_DIRECTWRITE || JUCE_DIRECT2D
/* This is a workaround for broken-by-default function definitions
in the MinGW headers. If you're using a newer distribution of MinGW,
then your headers may substitute the broken definitions with working definitions
when this flag is enabled. Unfortunately, not all MinGW headers contain this
workaround, so Direct2D remains disabled by default when building with MinGW.
*/
#define WIDL_EXPLICIT_AGGREGATE_RETURNS 1

/* If you hit a compile error trying to include these files, you may need to update
your version of the Windows SDK to the latest one. The DirectWrite and Direct2D
headers are in the version 7 SDKs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ namespace DirectWriteTypeLayout

ComSmartPtr<IDWriteFont> dwFont;
auto hr = fontCollection.GetFontFromFontFace (glyphRun.fontFace, dwFont.resetAndGetPointerAddress());
ignoreUnused (hr);
jassert (dwFont != nullptr);

ComSmartPtr<IDWriteFontFamily> dwFontFamily;
Expand Down Expand Up @@ -289,6 +290,7 @@ namespace DirectWriteTypeLayout

ComSmartPtr<IDWriteFontFamily> fontFamily;
auto hr = fontCollection.GetFontFamily (fontIndex, fontFamily.resetAndGetPointerAddress());
ignoreUnused (hr);

ComSmartPtr<IDWriteFont> dwFont;
uint32 fontFacesCount = 0;
Expand Down Expand Up @@ -394,6 +396,7 @@ namespace DirectWriteTypeLayout

UINT32 actualLineCount = 0;
auto hr = dwTextLayout->GetLineMetrics (nullptr, 0, &actualLineCount);
ignoreUnused (hr);

layout.ensureStorageAllocated ((int) actualLineCount);

Expand All @@ -415,7 +418,7 @@ namespace DirectWriteTypeLayout
line.stringRange = Range<int> (lastLocation, lastLocation + (int) dwLineMetrics[i].length);
line.lineOrigin.y += yAdjustment;
yAdjustment += extraLineSpacing;
lastLocation += dwLineMetrics[i].length;
lastLocation += (int) dwLineMetrics[i].length;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace
uint32 index = 0;
BOOL exists = false;
auto hr = names->FindLocaleName (L"en-us", &index, &exists);
ignoreUnused (hr);

if (! exists)
index = 0;
Expand All @@ -54,7 +55,7 @@ namespace
jassert (family != nullptr);
ComSmartPtr<IDWriteLocalizedStrings> familyNames;
auto hr = family->GetFamilyNames (familyNames.resetAndGetPointerAddress());
jassert (SUCCEEDED (hr)); ignoreUnused (hr);
jassertquiet (SUCCEEDED (hr));
return getLocalisedName (familyNames);
}

Expand All @@ -63,7 +64,7 @@ namespace
jassert (font != nullptr);
ComSmartPtr<IDWriteLocalizedStrings> faceNames;
auto hr = font->GetFaceNames (faceNames.resetAndGetPointerAddress());
jassert (SUCCEEDED (hr)); ignoreUnused (hr);
jassertquiet (SUCCEEDED (hr));
return getLocalisedName (faceNames);
}

Expand Down Expand Up @@ -152,6 +153,7 @@ class WindowsDirectWriteTypeface : public Typeface

uint32 fontIndex = 0;
auto hr = fontCollection->FindFamilyName (font.getTypefaceName().toWideCharPointer(), &fontIndex, &fontFound);
ignoreUnused (hr);

if (! fontFound)
fontIndex = 0;
Expand Down
1 change: 1 addition & 0 deletions modules/juce_graphics/native/juce_win32_Fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ StringArray Font::findAllTypefaceStyles (const String& family)
BOOL fontFound = false;
uint32 fontIndex = 0;
auto hr = factories->systemFonts->FindFamilyName (family.toWideCharPointer(), &fontIndex, &fontFound);
ignoreUnused (hr);

if (! fontFound)
fontIndex = 0;
Expand Down
50 changes: 17 additions & 33 deletions modules/juce_gui_basics/juce_gui_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@
#include <vfw.h>
#include <commdlg.h>
#include <commctrl.h>

#if ! JUCE_MINGW
#include <UIAutomation.h>
#include <sapi.h>
#endif
#include <UIAutomation.h>
#include <sapi.h>

#if JUCE_WEB_BROWSER
#include <exdisp.h>
Expand Down Expand Up @@ -310,26 +307,13 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE
#include "native/juce_mac_MouseCursor.mm"

#elif JUCE_WINDOWS

#if ! JUCE_MINGW
#include "native/accessibility/juce_win32_WindowsUIAWrapper.h"
#include "native/accessibility/juce_win32_AccessibilityElement.h"
#include "native/accessibility/juce_win32_UIAHelpers.h"
#include "native/accessibility/juce_win32_UIAProviders.h"
#include "native/accessibility/juce_win32_AccessibilityElement.cpp"
#include "native/accessibility/juce_win32_Accessibility.cpp"
#else
namespace juce
{
namespace WindowsAccessibility
{
long getUiaRootObjectId() { return -1; }
bool handleWmGetObject (AccessibilityHandler*, WPARAM, LPARAM, LRESULT*) { return false; }
void revokeUIAMapEntriesForWindow (HWND) {}
}
}
#endif

#include "native/accessibility/juce_win32_ComInterfaces.h"
#include "native/accessibility/juce_win32_WindowsUIAWrapper.h"
#include "native/accessibility/juce_win32_AccessibilityElement.h"
#include "native/accessibility/juce_win32_UIAHelpers.h"
#include "native/accessibility/juce_win32_UIAProviders.h"
#include "native/accessibility/juce_win32_AccessibilityElement.cpp"
#include "native/accessibility/juce_win32_Accessibility.cpp"
#include "native/juce_win32_Windowing.cpp"
#include "native/juce_win32_DragAndDrop.cpp"
#include "native/juce_win32_FileChooser.cpp"
Expand Down Expand Up @@ -383,8 +367,8 @@ namespace juce
#if JUCE_WINDOWS
namespace juce
{
MIDL_INTERFACE ("a5cd92ff-29be-454c-8d04-d82879fb3f1b")
juce_IVirtualDesktopManager : public IUnknown

JUCE_COMCLASS (JuceIVirtualDesktopManager, "a5cd92ff-29be-454c-8d04-d82879fb3f1b") : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE IsWindowOnCurrentVirtualDesktop(
Expand All @@ -400,13 +384,13 @@ juce_IVirtualDesktopManager : public IUnknown
__RPC__in REFGUID desktopId) = 0;
};

JUCE_COMCLASS (juce_VirtualDesktopManager, "aa509086-5ca9-4c25-8f95-589d3c07b48a");
JUCE_COMCLASS (JuceVirtualDesktopManager, "aa509086-5ca9-4c25-8f95-589d3c07b48a");

} // namespace juce

#ifdef __CRT_UUID_DECL
__CRT_UUID_DECL (juce::juce_IVirtualDesktopManager, 0xa5cd92ff, 0x29be, 0x454c, 0x8d, 0x04, 0xd8, 0x28, 0x79, 0xfb, 0x3f, 0x1b)
__CRT_UUID_DECL (juce::juce_VirtualDesktopManager, 0xaa509086, 0x5ca9, 0x4c25, 0x8f, 0x95, 0x58, 0x9d, 0x3c, 0x07, 0xb4, 0x8a)
__CRT_UUID_DECL (juce::JuceIVirtualDesktopManager, 0xa5cd92ff, 0x29be, 0x454c, 0x8d, 0x04, 0xd8, 0x28, 0x79, 0xfb, 0x3f, 0x1b)
__CRT_UUID_DECL (juce::JuceVirtualDesktopManager, 0xaa509086, 0x5ca9, 0x4c25, 0x8f, 0x95, 0x58, 0x9d, 0x3c, 0x07, 0xb4, 0x8a)
#endif

bool juce::isWindowOnCurrentVirtualDesktop (void* x)
Expand All @@ -416,16 +400,16 @@ bool juce::isWindowOnCurrentVirtualDesktop (void* x)

static auto* desktopManager = []
{
juce_IVirtualDesktopManager* result = nullptr;
JuceIVirtualDesktopManager* result = nullptr;

JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wlanguage-extension-token")

if (SUCCEEDED (CoCreateInstance (__uuidof (juce_VirtualDesktopManager), nullptr, CLSCTX_ALL, IID_PPV_ARGS (&result))))
if (SUCCEEDED (CoCreateInstance (__uuidof (JuceVirtualDesktopManager), nullptr, CLSCTX_ALL, IID_PPV_ARGS (&result))))
return result;

JUCE_END_IGNORE_WARNINGS_GCC_LIKE

return static_cast<juce_IVirtualDesktopManager*> (nullptr);
return static_cast<JuceIVirtualDesktopManager*> (nullptr);
}();

BOOL current = false;
Expand Down
Loading

0 comments on commit 640194c

Please sign in to comment.