Skip to content

Commit

Permalink
build: add meson build support
Browse files Browse the repository at this point in the history
Adds support for the meson build system as well as a bit of
documentation. Compatibility with the existing waf build is
maintained.
  • Loading branch information
Dudemanguy committed Nov 14, 2021
1 parent f610fe1 commit ff32286
Show file tree
Hide file tree
Showing 19 changed files with 2,240 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@

/old_build
/Makefile

/subprojects
70 changes: 70 additions & 0 deletions DOCS/build-system-differences.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion common/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions generated/etc/meson.build
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions generated/meson.build
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions generated/osdep/meson.build
Original file line number Diff line number Diff line change
@@ -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'])
6 changes: 6 additions & 0 deletions generated/player/javascript/meson.build
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions generated/player/lua/meson.build
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions generated/sub/meson.build
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions generated/wayland/meson.build
Original file line number Diff line number Diff line change
@@ -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: '@[email protected]',
command: [wayland['scanner'], 'private-code', '@INPUT@', '@OUTPUT@'],
)
wl_protocols_headers += custom_target(xml.underscorify() + '_h',
input: xml,
output: '@[email protected]',
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']
Loading

0 comments on commit ff32286

Please sign in to comment.