build: add meson build support

Adds support for the meson build system as well as a bit of
documentation. Compatibility with the existing waf build is
maintained.
This commit is contained in:
Dudemanguy 2021-11-07 13:28:16 -06:00
parent f610fe16c0
commit ff322864f2
19 changed files with 2240 additions and 5 deletions

2
.gitignore vendored
View File

@ -36,3 +36,5 @@
/old_build
/Makefile
/subprojects

View File

@ -0,0 +1,70 @@
# Differences Between Meson and Waf
mpv currently supports two different build systems: waf and meson. In general,
option names between both build systems are mostly the same. In most cases,
``--enable-foo`` in waf becomes ``-Dfoo=enabled`` in meson. Likewise,
``--disable-foo`` becomes ``-Dfoo=disabled``. For the rest of this document,
Waf options will be noted as ``--foo`` while meson options are noted as
``foo``.
## Universal Options
Meson has several [universal options](https://mesonbuild.com/Builtin-options.html#universal-options)
that you get for free. In some cases, these overlapped with custom waf options.
* ``--libmpv-static`` and ``--libmpv-shared`` were combined into one option:
``libmpv``. Use ``default_library`` to control if you want to build static or
shared libraries.
* Waf had a boolean ``--optimize`` option. In meson, this is a universal option,
``optimization``, which can take several different values. In mpv's meson
build, the default is ``2``.
* Instead of ``--debug-build``, meson simply calls it ``debug``. It is enabled
by default.
## Changed Options
* The legacy lua names (``52``, ``52deb``, etc.) for ``--lua`` are not
supported in the meson build. Instead, pass the generic pkg-config values
such as ``lua52``, ``lua5.2``, etc.
* ``--lgpl`` was changed to ``gpl``. If ``gpl`` is false, the build is LGPL2.1+.
### Boolean Options
The following options are all booleans that accept ``true`` or ``false``
instead of ``enabled`` or ``disabled``.
* ``build-date``
* ``cplayer``
* ``gpl``
* ``libmpv``
* ``ta-leak-report``
* ``tests``
## Removed Options
There are options removed with no equivalent in the meson build.
* ``--asm`` was removed since it doesn't do anything.
* ``--android`` was removed since meson knows if the machine is android.
* ``--clang-compilation-database`` was removed. Meson can do this on its own
by invoking ninja (``ninja -t compdb``).
* ``--tvos`` was removed since it doesn't do anything.
* ``--static-build`` was removed. Use ``default_library``.
* ``--swift-static`` was removed. The swift library always dynamically links.
## Renamed Options
These are some other options that were renamed.
* ``--gl-wayland`` was renamed to ``egl-wayland``.
* ``--swift`` was renamed to ``swift-build``.
## Other
* The meson build supports passing the ``SOURCE_DATE_EPOCH`` environment variable
during the compilation step for those who want reproducibility without having to
disable the build date.
* The ``Configuration`` line shown by ``mpv -v`` does not show everything passed on
cli since meson does not have any easy way to access a user's argv. Instead, it
simply shows whatever the value of ``prefix`` is regardless if it was specified
or not.

View File

@ -73,11 +73,27 @@ Changes to the default key bindings are indicated in
Compiling with full features requires development files for several
external libraries. Below is a list of some important requirements.
external libraries. One of the two build systems supported by mpv is required:
[meson](https://mesonbuild.com/index.html) or [waf](https://waf.io/). Meson
can be obtained from your distro or PyPI. Waf can be downloaded by using the
`./bootstrap.py` script. It will get the lastest version of waf that was tested
with mpv. Some documentation about the differences between the build systems are
located in [build-system-differences][build-system-differences].
The mpv build system uses [waf](https://waf.io/), but we don't store it in the
repository. The `./bootstrap.py` script will download the latest version
of waf that was tested with the build system.
### Meson
After creating your build directory (e.g. `meson build`), you can view a list
of all the build options via `meson configure build`. You could also just simply
look at the `meson_options.txt` file. Logs are stored in `meson-logs` within
your build directory.
Example:
meson build
meson compile -C build
meson install -C build
### Waf
For a list of the available build options use `./waf configure --help`. If
you think you have support for some feature installed but configure fails to
@ -214,3 +230,4 @@ Most activity happens on the IRC channel and the github issue tracker.
[api-changes]: https://github.com/mpv-player/mpv/blob/master/DOCS/client-api-changes.rst
[restore-old-bindings]: https://github.com/mpv-player/mpv/blob/master/etc/restore-old-bindings.conf
[contribute.md]: https://github.com/mpv-player/mpv/blob/master/DOCS/contribute.md
[build-system-differences]: https://github.com/mpv-player/mpv/blob/master/DOCS/build-system-differences.md

View File

@ -69,7 +69,8 @@ struct stat_entry {
// Overflows only after I'm dead.
static int64_t get_thread_cpu_time_ns(pthread_t thread)
{
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(_POSIX_THREAD_CPUTIME)
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(_POSIX_THREAD_CPUTIME) && \
!HAVE_WIN32_INTERNAL_PTHREADS
clockid_t id;
struct timespec tv;
if (pthread_getcpuclockid(thread, &id) == 0 &&

View File

@ -0,0 +1,8 @@
input = join_paths(source_root, 'TOOLS', 'osxbundle',
'mpv.app', 'Contents', 'Resources', 'icon.icns')
osxbundle = custom_target('osxbundle',
input: input,
output: 'icon.icns.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += osxbundle

20
generated/etc/meson.build Normal file
View File

@ -0,0 +1,20 @@
icons = ['16', '32', '64', '128']
foreach size: icons
name = 'mpv-icon-8bit-'+size+'x'+size+'.png'
icon = custom_target(name,
input: join_paths(source_root, 'etc', name),
output: name + '.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += icon
endforeach
etc_files = ['input.conf', 'builtin.conf']
foreach file: etc_files
etc_file = custom_target(file,
input: join_paths(source_root, 'etc', file),
output: file + '.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += etc_file
endforeach

27
generated/meson.build Normal file
View File

@ -0,0 +1,27 @@
ebml_defs = custom_target('ebml_defs',
output: 'ebml_defs.inc',
command: [matroska, '--generate-definitions', '@OUTPUT@'],
)
ebml_types = custom_target('ebml_types',
output: 'ebml_types.h',
command: [matroska, '--generate-header', '@OUTPUT@'],
)
version_h = custom_target('version.h',
output: 'version.h',
command: [version_py, '@OUTPUT@'],
build_always_stale: true,
)
sources += [ebml_defs, ebml_types, version_h]
# Meson doesn't allow having multiple build targets with the same name in the same file.
# Just generate the com in here for windows builds.
if win32 and get_option('cplayer')
features += 'win32-executable'
wrapper_flags = ['-municode', '-Wl,--subsystem,console']
wrapper_sources= '../osdep/win32-console-wrapper.c'
executable('mpv', wrapper_sources, c_args: wrapper_flags, link_args: wrapper_flags,
name_suffix: 'com', install: true)
endif

View File

@ -0,0 +1,57 @@
# custom swift targets
bridge = join_paths(source_root, 'osdep/macOS_swift_bridge.h')
header = join_paths(build_root, 'osdep/macOS_swift.h')
module = join_paths(build_root, 'osdep/macOS_swift.swiftmodule')
target = join_paths(build_root, 'osdep/macOS_swift.o')
swift_flags = ['-frontend', '-c', '-sdk', macos_sdk_path,
'-enable-objc-interop', '-emit-objc-header', '-parse-as-library']
if swift_ver.version_compare('>=6.0')
swift_flags += ['-swift-version', '5']
endif
if get_option('debug')
swift_flags += '-g'
endif
if get_option('optimization') != '0'
swift_flags += '-O'
endif
if macos_10_11_features.allowed()
swift_flags += ['-D', 'HAVE_MACOS_10_11_FEATURES']
endif
if macos_10_14_features.allowed()
swift_flags += ['-D', 'HAVE_MACOS_10_14_FEATURES']
endif
extra_flags = get_option('swift-flags').split()
swift_flags += extra_flags
swift_compile = [swift_prog, swift_flags, '-module-name', 'macOS_swift',
'-emit-module-path', '@OUTPUT0@', '-import-objc-header', bridge,
'-emit-objc-header-path', '@OUTPUT1@', '-o', '@OUTPUT2@',
'@INPUT@', '-I.', '-I' + source_root]
swift_targets = custom_target('swift_targets',
input: swift_sources,
output: ['macOS_swift.swiftmodule', 'macOS_swift.h', 'macOS_swift.o'],
command: swift_compile,
)
sources += swift_targets
swift_lib_dir_py = find_program(join_paths(tools_directory, 'macos-swift-lib-directory.py'))
swift_lib_dir = run_command(swift_lib_dir_py, swift_prog.full_path(), check: true).stdout()
message('Detected Swift library directory: ' + swift_lib_dir)
# linker flags
swift_link_flags = ['-L' + swift_lib_dir, '-Xlinker', '-rpath',
'-Xlinker', swift_lib_dir, '-rdynamic', '-Xlinker',
'-add_ast_path', '-Xlinker', module]
if swift_ver.version_compare('>=5.0')
swift_link_flags += ['-Xlinker', '-rpath', '-Xlinker',
'/usr/lib/swift', '-L/usr/lib/swift']
endif
add_project_link_arguments(swift_link_flags, language: ['c', 'objc'])

View File

@ -0,0 +1,6 @@
defaults_js = custom_target('defaults.js',
input: join_paths(source_root, 'player', 'javascript', 'defaults.js'),
output: 'defaults.js.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += defaults_js

View File

@ -0,0 +1,10 @@
lua_files = ['defaults.lua', 'assdraw.lua', 'options.lua', 'osc.lua',
'ytdl_hook.lua', 'stats.lua', 'console.lua', 'auto_profiles.lua']
foreach file: lua_files
lua_file = custom_target(file,
input: join_paths(source_root, 'player', 'lua', file),
output: file + '.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += lua_file
endforeach

View File

@ -0,0 +1,6 @@
osd_font = custom_target('osd_font.otf',
input: join_paths(source_root, 'sub', 'osd_font.otf'),
output: 'osd_font.otf.inc',
command: [file2string, '@INPUT@', '@OUTPUT@'],
)
sources += osd_font

View File

@ -0,0 +1,32 @@
wl_protocol_dir = wayland['deps'][2].get_variable(pkgconfig: 'pkgdatadir')
protocols = [[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
[wl_protocol_dir, 'stable/presentation-time/presentation-time.xml'],
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
[wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml']]
wl_protocols_source = []
wl_protocols_headers = []
foreach p: protocols
xml = join_paths(p)
wl_protocols_source += custom_target(xml.underscorify() + '_c',
input: xml,
output: '@BASENAME@.c',
command: [wayland['scanner'], 'private-code', '@INPUT@', '@OUTPUT@'],
)
wl_protocols_headers += custom_target(xml.underscorify() + '_h',
input: xml,
output: '@BASENAME@.h',
command: [wayland['scanner'], 'client-header', '@INPUT@', '@OUTPUT@'],
)
endforeach
lib_client_protocols = static_library('protocols',
wl_protocols_source + wl_protocols_headers,
dependencies: wayland['deps'][0])
client_protocols = declare_dependency(link_with: lib_client_protocols,
sources: wl_protocols_headers)
dependencies += [client_protocols, wayland['deps']]
sources += ['video/out/wayland_common.c']

1840
meson.build Normal file

File diff suppressed because it is too large Load Diff

117
meson_options.txt Normal file
View File

@ -0,0 +1,117 @@
# booleans
option('gpl', type: 'boolean', value: true, description: 'GPL (version 2 or later) build')
option('cplayer', type: 'boolean', value: true, description: 'mpv CLI player')
option('libmpv', type: 'boolean', value: false, description: 'libmpv library')
option('build-date', type: 'boolean', value: true, description: 'whether to include binary compile time')
option('tests', type: 'boolean', value: false, description: 'unit tests (development only)')
# Reminder: normally always built, but enabled by MPV_LEAK_REPORT.
# Building it can be disabled only by defining NDEBUG through CFLAGS.
option('ta-leak-report', type: 'boolean', value: false, description: 'enable ta leak report by default (development only)')
# misc features
option('cdda', type: 'feature', value: 'disabled', description: 'cdda support (libcdio)')
option('cplugins', type: 'feature', value: 'auto', description: 'C plugins')
option('dvbin', type: 'feature', value: 'disabled', description: 'DVB input module')
option('dvdnav', type: 'feature', value: 'auto', description: 'dvdnav support')
option('iconv', type: 'feature', value: 'auto', description: 'iconv')
option('javascript', type: 'feature', value: 'auto', description: 'Javascript (MuJS backend)')
option('lcms2', type: 'feature', value: 'auto', description: 'LCMS2 support')
option('libarchive', type: 'feature', value: 'auto', description: 'libarchive wrapper for reading zip files and more')
option('libavdevice', type: 'feature', value: 'auto', description: 'libavdevice')
option('libbluray', type: 'feature', value: 'auto', description: 'Bluray support')
option('lua',
type: 'combo',
choices: ['lua52', 'lua5.2', 'lua-5.2', 'luajit', 'lua51',
'lua5.1', 'lua-5.1', 'auto', 'enabled', 'disabled'],
value: 'auto',
description: 'Lua'
)
option('pthread-debug', type: 'feature', value: 'disabled', description: 'pthread runtime debugging wrappers')
option('rubberband', type: 'feature', value: 'auto', description: 'librubberband support')
option('sdl2', type: 'feature', value: 'disabled', description: 'SDL2')
option('sdl2-gamepad', type: 'feature', value: 'auto', description: 'SDL2 gamepad input')
option('stdatomic', type: 'feature', value: 'auto', description: 'C11 stdatomic.h')
option('uchardet', type: 'feature', value: 'auto', description: 'uchardet support')
option('uwp', type: 'feature', value: 'disabled', description: 'Universal Windows Platform')
option('vapoursynth', type: 'feature', value: 'auto', description: 'VapourSynth filter bridge')
option('vector', type: 'feature', value: 'auto', description: 'GCC vector instructions')
option('win32-internal-pthreads', type: 'feature', value: 'auto', description: 'internal pthread wrapper for win32 (Vista+)')
option('zimg', type: 'feature', value: 'auto', description: 'libzimg support (high quality software scaler)')
option('zlib', type: 'feature', value: 'auto', description: 'zlib')
# audio output features
option('alsa', type: 'feature', value: 'auto', description: 'ALSA audio output')
option('audiounit', type: 'feature', value: 'auto', description: 'AudioUnit output for iOS')
option('coreaudio', type: 'feature', value: 'auto', description: 'CoreAudio audio output')
option('jack', type: 'feature', value: 'auto', description: 'JACK audio output')
option('openal', type: 'feature', value: 'disabled', description: 'OpenAL audio output')
option('opensles', type: 'feature', value: 'auto', description: 'OpenSL ES audio output')
option('oss-audio', type: 'feature', value: 'auto', description: 'OSSv4 audio output')
option('pulse', type: 'feature', value: 'auto', description: 'PulseAudio audio output')
option('sdl2-audio', type: 'feature', value: 'auto', description: 'SDL2 audio output')
option('wasapi', type: 'feature', value: 'auto', description: 'WASAPI audio output')
# video output features
option('caca', type: 'feature', value: 'auto', description: 'CACA')
option('cocoa', type: 'feature', value: 'auto', description: 'Cocoa')
option('d3d11', type: 'feature', value: 'auto', description: 'Direct3D 11 video output')
option('direct3d', type: 'feature', value: 'auto', description: 'Direct3D support')
option('drm', type: 'feature', value: 'auto', description: 'DRM')
option('egl', type: 'feature', value: 'auto', description: 'EGL 1.4')
option('egl-android', type: 'feature', value: 'auto', description: 'Android EGL support')
option('egl-angle', type: 'feature', value: 'auto', description: 'OpenGL ANGLE headers')
option('egl-angle-lib', type: 'feature', value: 'auto', description: 'OpenGL Win32 ANGLE library')
option('egl-angle-win32', type: 'feature', value: 'auto', description: 'OpenGL Win32 ANGLE Backend')
option('egl-drm', type: 'feature', value: 'auto', description: 'OpenGL DRM EGL Backend')
option('egl-wayland', type: 'feature', value: 'auto', description: 'OpenGL Wayland Backend')
option('egl-x11', type: 'feature', value: 'auto', description: 'OpenGL X11 EGL Backend')
option('gbm', type: 'feature', value: 'auto', description: 'GBM')
option('gl', type: 'feature', value: 'enabled', description: 'OpenGL context support')
option('gl-cocoa', type: 'feature', value: 'auto', description: 'gl-cocoa')
option('gl-dxinterop', type: 'feature', value: 'auto', description: 'OpenGL/DirectX Interop Backend')
option('gl-win32', type: 'feature', value: 'auto', description: 'OpenGL Win32 Backend')
option('gl-x11', type: 'feature', value: 'disabled', description: 'OpenGL X11/GLX (deprecated/legacy)')
option('jpeg', type: 'feature', value: 'auto', description: 'JPEG support')
option('libplacebo', type: 'feature', value: 'auto', description: 'libplacebo support')
option('rpi', type: 'feature', value: 'disabled', description: 'Raspberry Pi support')
option('sdl2-video', type: 'feature', value: 'auto', description: 'SDL2 video output')
option('shaderc', type: 'feature', value: 'auto', description: 'libshaderc SPIR-V compiler')
option('sixel', type: 'feature', value:'auto', description: 'Sixel')
option('spirv-cross', type: 'feature', value: 'auto', description: 'SPIRV-Cross SPIR-V shader converter')
option('plain-gl', type: 'feature', value: 'auto', description: 'OpenGL without platform-specific code (e.g. for libmpv)')
option('vdpau', type: 'feature', value: 'auto', description: 'VDPAU acceleration')
option('vdpau-gl-x11', type: 'feature', value: 'auto', description: 'VDPAU with OpenGl/X11')
option('vaapi', type: 'feature', value: 'auto', description: 'VAAPI acceleration')
option('vaapi-drm', type: 'feature', value: 'auto', description: 'VAAPI (DRM/EGL support)')
option('vaapi-wayland', type: 'feature', value: 'auto', description: 'VAAPI (Wayland support)')
option('vaapi-x11', type: 'feature', value: 'auto', description: 'VAAPI (X11 support)')
option('vaapi-x-egl', type: 'feature', value: 'auto', description: 'VAAPI EGL on X11')
option('vulkan', type: 'feature', value: 'auto', description: 'Vulkan context support')
option('wayland', type: 'feature', value: 'auto', description: 'Wayland')
option('x11', type: 'feature', value: 'auto', description: 'X11')
option('xv', type: 'feature', value: 'auto', description: 'Xv video output')
# hwaccel features
option('cuda-hwaccel', type: 'feature', value: 'auto', description: 'CUDA acceleration')
option('cuda-interop', type: 'feature', value: 'auto', description: 'CUDA with graphics interop')
option('d3d-hwaccel', type: 'feature', value: 'auto', description: 'D3D11VA hwaccel')
option('d3d9-hwaccel', type: 'feature', value: 'auto', description: 'DXVA2 hwaccel')
option('gl-dxinterop-d3d9', type: 'feature', value: 'auto', description: 'OpenGL/DirectX Interop Backend DXVA2 interop')
option('ios-gl', type: 'feature', value: 'auto', description: 'iOS OpenGL ES hardware decoding interop support')
option('rpi-mmal', type: 'feature', value: 'auto', description: 'Raspberry Pi MMAL hwaccel')
option('videotoolbox-gl', type: 'feature', value: 'auto', description: 'Videotoolbox with OpenGL')
# macOS features
option('macos-10-11-features', type: 'feature', value: 'auto', description: 'macOS 10.11 SDK Features')
option('macos-10-12-2-features', type: 'feature', value: 'auto', description: 'macOS 10.12.2 SDK Features')
option('macos-10-14-features', type: 'feature', value: 'auto', description: 'macOS 10.14 SDK Features')
option('macos-cocoa-cb', type: 'feature', value: 'auto', description: 'macOS libmpv backend')
option('macos-media-player', type: 'feature', value: 'auto', description: 'macOS Media Player support')
option('macos-touchbar', type: 'feature', value: 'auto', description: 'macOS Touch Bar support')
option('swift-build', type: 'feature', value: 'auto', description: 'macOS Swift build tools')
option('swift-flags', type: 'string', description: 'Optional Swift compiler flags')
# manpages
option('html-build', type: 'feature', value: 'disabled', description: 'html manual generation')
option('manpage-build', type: 'feature', value: 'auto', description: 'manpage generation')
option('pdf-build', type: 'feature', value: 'disabled', description: 'pdf manual generation')

View File

@ -21,6 +21,7 @@
#include <errno.h>
#include <sys/time.h>
#include <assert.h>
#include <windows.h>
#include "osdep/timer.h" // mp_{start,end}_hires_timers

View File

@ -0,0 +1,6 @@
#include <pthread.h>
#include <pthread_np.h>
int main(int argc, char **argv) {
pthread_set_name_np(pthread_self(), "ducks");
return 0;
}

View File

@ -0,0 +1,6 @@
#define _GNU_SOURCE
#include <pthread.h>
int main(int argc, char **argv) {
pthread_setname_np(pthread_self(), "ducks");
return 0;
}

View File

@ -0,0 +1,5 @@
#include <pthread.h>
int main(int argc, char **argv) {
pthread_setname_np("ducks");
return 0;
}

View File

@ -0,0 +1,4 @@
int main(int argc, char **argv) {
float v __attribute__((vector_size(32)));
return 0;
}