From 5b28d4479770141327063a0437ff47fd5a75a8b9 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 1 May 2021 01:09:58 +0200 Subject: [PATCH] Define a static library for the Wine hosts This means we only have to compile everything two times, instead of four times. We sadly still need to compile lots of files at least three times. (once for native, once for 64-bit Wine, and once for 32-bit Wine) --- CHANGELOG.md | 1 + meson.build | 399 +++++++++++++++++++++++++++------------------------ 2 files changed, 216 insertions(+), 184 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb51132..b81d6e22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Versioning](https://semver.org/spec/v2.0.0.html). proxying the proxy when that's not possible. This only affects Ardour and Mixbus. This greatly improves compatibility with _FabFilter_ plugins in those DAWs. +- The build has been slightly slimmed down using static libraries. ### Removed diff --git a/meson.build b/meson.build index 634001a7..6108cb2c 100644 --- a/meson.build +++ b/meson.build @@ -119,6 +119,173 @@ if wine_version.returncode() == 0 and \ 'https://github.com/robbert-vdh/yabridge/issues/63#issuecomment-757369645') endif +# +# Dependencies +# + +# Statically link against Boost.Filesystem, otherwise it would become impossible +# to distribute a prebuilt version of yabridge +boost_dep = dependency('boost', version : '>=1.66', static : with_static_boost) +boost_filesystem_dep = dependency( + 'boost', + version : '>=1.66', + modules : ['filesystem'], + static : with_static_boost, +) +# TODO: Meson doesn't have a way to define version ranges, does it? Like +# `^>=5.2.0`, `>=5.2.0 && <6.0.0` or `5.2.*`. +bitsery_dep = dependency('bitsery', version : '>=5.2.0', fallback : ['bitsery', 'bitsery_dep']) +function2_dep = dependency('function2', version : '>=4.1.0', fallback : ['function2', 'function2_dep']) +threads_dep = dependency('threads') +tomlplusplus_dep = dependency('tomlplusplus', version : '>=2.1.0', fallback : ['tomlplusplus', 'tomlplusplus_dep']) +# The built in threads dependency does not know how to handle winegcc +wine_threads_dep = declare_dependency(link_args : '-lpthread') +xcb_dep = dependency('xcb') + +dl_dep = declare_dependency(link_args : '-ldl') + +wine_ole32_dep = declare_dependency(link_args : '-lole32') +# The SDK includes a comment pragma that would link to this on MSVC +wine_shell32_dep = declare_dependency(link_args : '-lshell32') +wine_uuid_dep = declare_dependency(link_args : '-luuid') + +include_dir = include_directories('src/include') + +# +# VST3 SDK +# +# Meson does not allow mixing native and non native dependencies from +# subprojects. The only workaround is to only define the necessary variables +# there, and to then assemble the dependencies here ourselves. +# + +if with_vst3 + vst3 = subproject('vst3', version : '3.7.2') + 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'), + native : true, + cpp_args : vst3_compiler_options + ['-Wno-cpp'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_pluginterfaces_native = static_library( + 'pluginterfaces_native', + vst3.get_variable('pluginterfaces_sources'), + native : true, + cpp_args : vst3_compiler_options, + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_native = static_library( + 'sdk_native', + vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_sources'), + native : true, + link_with : [vst3_base_native, vst3_pluginterfaces_native], + cpp_args : vst3_compiler_options + ['-Wno-multichar'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_native_dep = declare_dependency( + link_with : vst3_sdk_native, + include_directories : vst3_include_dir, + compile_args : vst3_compiler_options, + ) + + # 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 = [ + # Some stuff from `windows.h` results in conflicting definitions + '-DNOMINMAX', + '-DWINE_NOWINSOCK', + ] + vst3_base_wine_64bit = static_library( + 'vst3_base_wine_64bit', + vst3.get_variable('base_sources'), + native : false, + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options + [ '-Wno-cpp'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_pluginterfaces_wine_64bit = static_library( + 'vst3_pluginterfaces_wine_64bit', + vst3.get_variable('pluginterfaces_sources'), + native : false, + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options, + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_hosting_wine_64bit = static_library( + 'vst3_sdk_hosting_wine_64bit', + vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_hosting_sources'), + native : false, + link_with : [vst3_base_wine_64bit, vst3_pluginterfaces_wine_64bit], + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options + ['-Wno-multichar'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_hosting_wine_64bit_dep = declare_dependency( + link_with : vst3_sdk_hosting_wine_64bit, + include_directories : vst3_include_dir, + # This does mean that we now have a lot of defines in our code, but the + # alternative would be patching every location in the SDK where they include + # `windows.h` + compile_args : vst3_compiler_options + vst3_wine_compiler_options, + ) + + # And another time for the 32-bit version + if with_bitbridge + vst3_base_wine_32bit = static_library( + 'vst3_base_wine_32bit', + vst3.get_variable('base_sources'), + native : false, + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options + ['-Wno-cpp'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_pluginterfaces_wine_32bit = static_library( + 'vst3_pluginterfaces_wine_32bit', + vst3.get_variable('pluginterfaces_sources'), + native : false, + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options, + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_hosting_wine_32bit = static_library( + 'vst3_sdk_hosting_wine_32bit', + vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_hosting_sources'), + native : false, + link_with : [vst3_base_wine_32bit, vst3_pluginterfaces_wine_32bit], + cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options + ['-Wno-multichar'], + include_directories : vst3_include_dir, + override_options : ['warning_level=0'], + ) + vst3_sdk_hosting_wine_32bit_dep = declare_dependency( + link_with : vst3_sdk_hosting_wine_32bit, + include_directories : vst3_include_dir, + # This does mean that we now have a lot of defines in our code, but the + # alternative would be patching every location in the SDK where they include + # `windows.h` + compile_args : vst3_compiler_options + vst3_wine_compiler_options, + ) + endif +endif + # # Source files # @@ -216,7 +383,7 @@ vst3_plugin_sources = [ version_header, ] -host_sources = [ +host_common_sources = [ 'src/common/communication/vst2.cpp', 'src/common/serialization/vst2.cpp', 'src/common/configuration.cpp', @@ -233,7 +400,7 @@ host_sources = [ ] if with_vst3 - host_sources += [ + host_common_sources += [ 'src/common/logging/vst3.cpp', 'src/common/serialization/vst3/component-handler/component-handler.cpp', 'src/common/serialization/vst3/component-handler/component-handler-2.cpp', @@ -299,179 +466,15 @@ if with_vst3 ] endif -individual_host_sources = host_sources + ['src/wine-host/individual-host.cpp'] -group_host_sources = host_sources + [ +# We'll link these against a static library `host_common_sources` +individual_host_sources = ['src/wine-host/individual-host.cpp'] +group_host_sources = [ 'src/wine-host/bridges/group.cpp', 'src/wine-host/group-host.cpp', ] # -# Dependencies -# - -# Statically link against Boost.Filesystem, otherwise it would become impossible -# to distribute a prebuilt version of yabridge -boost_dep = dependency('boost', version : '>=1.66', static : with_static_boost) -boost_filesystem_dep = dependency( - 'boost', - version : '>=1.66', - modules : ['filesystem'], - static : with_static_boost, -) -# TODO: Meson doesn't have a way to define version ranges, does it? Like -# `^>=5.2.0`, `>=5.2.0 && <6.0.0` or `5.2.*`. -bitsery_dep = dependency('bitsery', version : '>=5.2.0', fallback : ['bitsery', 'bitsery_dep']) -function2_dep = dependency('function2', version : '>=4.1.0', fallback : ['function2', 'function2_dep']) -threads_dep = dependency('threads') -tomlplusplus_dep = dependency('tomlplusplus', version : '>=2.1.0', fallback : ['tomlplusplus', 'tomlplusplus_dep']) -# The built in threads dependency does not know how to handle winegcc -wine_threads_dep = declare_dependency(link_args : '-lpthread') -xcb_dep = dependency('xcb') - -wine_ole32_dep = declare_dependency(link_args : '-lole32') -# The SDK includes a comment pragma that would link to this on MSVC -wine_shell32_dep = declare_dependency(link_args : '-lshell32') -wine_uuid_dep = declare_dependency(link_args : '-luuid') - -include_dir = include_directories('src/include') - -# -# VST3 SDK -# -# Meson does not allow mixing native and non native dependencies from -# subprojects. The only workaround is to only define the necessary variables -# there, and to then assemble the dependencies here ourselves. -# - -if with_vst3 - vst3 = subproject('vst3', version : '3.7.2') - 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'), - cpp_args : vst3_compiler_options + ['-Wno-cpp'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : true, - ) - vst3_pluginterfaces_native = static_library( - 'pluginterfaces_native', - vst3.get_variable('pluginterfaces_sources'), - cpp_args : vst3_compiler_options, - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : true, - ) - vst3_sdk_native = static_library( - 'sdk_native', - vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_sources'), - link_with : [vst3_base_native, vst3_pluginterfaces_native], - cpp_args : vst3_compiler_options + ['-Wno-multichar'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : true, - ) - vst3_sdk_native_dep = declare_dependency( - link_with : vst3_sdk_native, - include_directories : vst3_include_dir, - compile_args : vst3_compiler_options, - ) - - # 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 = [ - # Some stuff from `windows.h` results in conflicting definitions - '-DNOMINMAX', - '-DWINE_NOWINSOCK', - ] - vst3_base_wine_64bit = static_library( - 'vst3_base_wine_64bit', - vst3.get_variable('base_sources'), - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options + [ '-Wno-cpp'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_pluginterfaces_wine_64bit = static_library( - 'vst3_pluginterfaces_wine_64bit', - vst3.get_variable('pluginterfaces_sources'), - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options, - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_sdk_hosting_wine_64bit = static_library( - 'vst3_sdk_hosting_wine_64bit', - vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_hosting_sources'), - link_with : [vst3_base_wine_64bit, vst3_pluginterfaces_wine_64bit], - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_64bit_compiler_options + ['-Wno-multichar'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_sdk_hosting_wine_64bit_dep = declare_dependency( - link_with : vst3_sdk_hosting_wine_64bit, - include_directories : vst3_include_dir, - # This does mean that we now have a lot of defines in our code, but the - # alternative would be patching every location in the SDK where they include - # `windows.h` - compile_args : vst3_compiler_options + vst3_wine_compiler_options, - ) - - # And another time for the 32-bit version - if with_bitbridge - vst3_base_wine_32bit = static_library( - 'vst3_base_wine_32bit', - vst3.get_variable('base_sources'), - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options + ['-Wno-cpp'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_pluginterfaces_wine_32bit = static_library( - 'vst3_pluginterfaces_wine_32bit', - vst3.get_variable('pluginterfaces_sources'), - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options, - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_sdk_hosting_wine_32bit = static_library( - 'vst3_sdk_hosting_wine_32bit', - vst3.get_variable('sdk_common_sources') + vst3.get_variable('sdk_hosting_sources'), - link_with : [vst3_base_wine_32bit, vst3_pluginterfaces_wine_32bit], - cpp_args : vst3_compiler_options + vst3_wine_compiler_options + wine_32bit_compiler_options + ['-Wno-multichar'], - include_directories : vst3_include_dir, - override_options : ['warning_level=0'], - native : false, - ) - vst3_sdk_hosting_wine_32bit_dep = declare_dependency( - link_with : vst3_sdk_hosting_wine_32bit, - include_directories : vst3_include_dir, - # This does mean that we now have a lot of defines in our code, but the - # alternative would be patching every location in the SDK where they include - # `windows.h` - compile_args : vst3_compiler_options + vst3_wine_compiler_options, - ) - endif -endif - -# -# Targets +# Libraries # # The application consists of a plugin (`libyabridge-{vst2,vst3}.so`) that calls # a Winelib application (`yabridge-{host,group}{,-32}.exe`) that can host @@ -488,11 +491,11 @@ shared_library( boost_dep, boost_filesystem_dep, bitsery_dep, + dl_dep, threads_dep, tomlplusplus_dep, ], cpp_args : compiler_options, - link_args : ['-ldl'] ) if with_vst3 @@ -507,16 +510,20 @@ if with_vst3 boost_dep, boost_filesystem_dep, bitsery_dep, + dl_dep, function2_dep, threads_dep, tomlplusplus_dep, vst3_sdk_native_dep, ], cpp_args : compiler_options, - link_args : ['-ldl'], ) endif +# +# Hosts +# + host_64bit_deps = [ boost_dep, boost_filesystem_dep, @@ -535,6 +542,22 @@ if with_vst3 ] endif +host_common_64bit = static_library( + 'host_common_64bit', + host_common_sources, + native : false, + include_directories : include_dir, + dependencies : host_64bit_deps, + cpp_args : compiler_options + wine_64bit_compiler_options, + link_args : ['-m64'], +) +host_common_64bit_dep = declare_dependency( + link_with : host_common_64bit, + include_directories : include_dir, + dependencies : host_64bit_deps, + compile_args : compiler_options + wine_64bit_compiler_options, +) + if with_bitbridge message('Bitbridge enabled, configuring a 32-bit host application') @@ -580,15 +603,29 @@ if with_bitbridge wine_uuid_dep, ] endif + + host_common_32bit = static_library( + 'host_common_32bit', + host_common_sources, + native : false, + include_directories : include_dir, + dependencies : host_32bit_deps, + cpp_args : compiler_options + wine_32bit_compiler_options, + link_args : ['-m32'], + ) + host_common_32bit_dep = declare_dependency( + link_with : host_common_32bit, + include_directories : include_dir, + dependencies : host_32bit_deps, + compile_args : compiler_options + wine_32bit_compiler_options, + ) endif executable( individual_host_name_64bit, individual_host_sources, native : false, - include_directories : include_dir, - dependencies : host_64bit_deps, - cpp_args : compiler_options + wine_64bit_compiler_options, + dependencies : host_common_64bit_dep, link_args : ['-m64'], ) @@ -596,9 +633,7 @@ executable( group_host_name_64bit, group_host_sources, native : false, - include_directories : include_dir, - dependencies : host_64bit_deps, - cpp_args : compiler_options + wine_64bit_compiler_options, + dependencies : host_common_64bit_dep, link_args : ['-m64'], ) @@ -607,9 +642,7 @@ if with_bitbridge individual_host_name_32bit, individual_host_sources, native : false, - include_directories : include_dir, - dependencies : host_32bit_deps, - cpp_args : compiler_options + wine_32bit_compiler_options, + dependencies : host_common_32bit_dep, link_args : ['-m32'], ) @@ -617,9 +650,7 @@ if with_bitbridge group_host_name_32bit, group_host_sources, native : false, - include_directories : include_dir, - dependencies : host_32bit_deps, - cpp_args : compiler_options + wine_32bit_compiler_options, + dependencies : host_common_32bit_dep, link_args : ['-m32'], ) endif