From b64c67d2ad000d929416fa0bfe5575859761c581 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sun, 29 Nov 2020 18:38:02 +0100 Subject: [PATCH] Patch VST3 SDK base to allow winelib compilation --- meson.build | 34 +++++++++++++++++++++++++++ subprojects/vst3.wrap | 2 +- tools/patch-vst3-sdk.sh | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 tools/patch-vst3-sdk.sh diff --git a/meson.build b/meson.build index fc40675f..017cbdc5 100644 --- a/meson.build +++ b/meson.build @@ -77,6 +77,8 @@ if with_vst3 vst3 = subproject('vst3', version : '3.7.1') vst3_compiler_options = vst3.get_variable('compiler_options') vst3_include_dir = vst3.get_variable('include_dir') + + # We'll create a dependency for the plugin SDK for our native VST3 plugin vst3_base_native = static_library( 'base_native', vst3.get_variable('base_sources'), @@ -106,6 +108,38 @@ if with_vst3 link_with : vst3_sdk_native, include_directories : vst3_include_dir, ) + + # And another dependency for the host SDK for our Wine host applications + # We need to do some minor hacking to get this to compile with winegcc. Most + # notably some attributes are named differently, and the SDK uses 'Windows.h' + # instead of 'windows.h' like how the file is actually called. + # message(vst3_include_dir) + vst3_sdk_base_dir = vst3.get_variable('sdk_base_dir') + patch_result = run_command('tools/patch-vst3-sdk.sh', vst3_sdk_base_dir) + if patch_result.returncode() == 0 + message(patch_result.stdout()) + else + error('Error while trying to patch the VST3 SDK:\n' + patch_result.stderr()) + endif + + vst3_wine_compiler_options = [ + # Removes some MSVC-isms for us + '-D__MINGW32__', + # We don't need all of this stuff from `Windows.h`, and it only causes more + # issues + '-DNOMINMAX', + '-DNOSERVICE', + '-DNOMCX', + '-DWIN32_LEAN_AND_MEAN', + ] + vst3_base_wine = static_library( + 'base_wine', + vst3.get_variable('base_sources'), + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + [ '-Wno-cpp'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + native : false, + ) else message('VST3 support has been disabled') endif diff --git a/subprojects/vst3.wrap b/subprojects/vst3.wrap index 395c2ce8..19b3e6a6 100644 --- a/subprojects/vst3.wrap +++ b/subprojects/vst3.wrap @@ -2,6 +2,6 @@ url = https://github.com/robbert-vdh/vst3sdk.git # This is VST3 SDK v3.7.1_build_50 with the documentation and VSTGUI submodules # removed -revision = d6d6ae0d33ada0c07a508b0e079d962464fa93cd +revision = e2fbb41f28a4b311f2fc7d28e9b4330eec1802b6 clone-recursive = true depth = 1 diff --git a/tools/patch-vst3-sdk.sh b/tools/patch-vst3-sdk.sh new file mode 100755 index 00000000..02a77f49 --- /dev/null +++ b/tools/patch-vst3-sdk.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# Patch the VST3 SDK and replace all MSVC-isms so it can be compiled with +# winegcc. We do it this way instead of modifying the SDK directly so we don't +# have to fork multiple repositories and keep them up to date. +# If anyone knows a better way to get the SDK to compile with Win32 supports +# under winegcc without having to modify it then please let me know, because I'd +# rather not have to do this. +# +# Usage: +# patch-vst3-sdk.sh + +set -euo pipefail + +sdk_directory=$1 +if [[ -z $sdk_directory ]]; then + echo "Usage:" + echo "patch-vst3-sdk.sh " + exit 1 +fi + +# Make sure all imports use the correct casing +find "$sdk_directory" -type f \( -iname '*.h' -or -iname '*.cpp' \) -print0 | + xargs -0 sed -i 's/^#include $/#include /' + +# Use the string manipulation functions from the C standard library +sed -i 's/\bSMTG_OS_WINDOWS\b/0/g;s/\bSMTG_OS_LINUX\b/1/g' "$sdk_directory/base/source/fstring.cpp" +sed -i 's/\bSMTG_OS_WINDOWS\b/0/g;s/\bSMTG_OS_LINUX\b/1/g' "$sdk_directory/pluginterfaces/base/fstrdefs.h" + +# We'll need some careful replacements in the Linux definitions in `fstring.cpp` +# to use `wchar_t` instead of `char16_t`. +sed -i "s/^using ConverterFacet = std::codecvt_utf8_utf16;$/#ifdef __WINE__\\ + using ConverterFacet = std::codecvt_utf8_utf16;\\ +#else\\ + \0\\ +#endif/" "$sdk_directory/base/source/fstring.cpp" +sed -i "s/^using Converter = std::wstring_convert;$/#ifdef __WINE__\\ + using Converter = std::wstring_convert;\\ +#else\\ + \0\\ +#endif/" "$sdk_directory/base/source/fstring.cpp" + +# `Windows.h` expects `wchar_t`, and the above defines will cause us to use +# `char16_t` for string literals. This replacement targets a very specific line, +# so if the SDK gets updated, this fails, and we're getting a ton of `wchar_t` +# related compile errors, that's why. The previous sed call will have replaced +# `SMTG_OS_WINDOWS` with a 0 here. +sed -i 's/^ #if 0$/ #if __WINE__/' "$sdk_directory/pluginterfaces/base/fstrdefs.h" + +# Meson requires this program to output something, or else it will error out +# when trying to encode the empty output +echo "Successfully patched '$sdk_directory' for winegcc compatibility"