diff options
author | Dudemanguy <random342@airmail.cc> | 2021-11-07 13:28:16 -0600 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2021-11-14 19:13:10 +0000 |
commit | ff322864f2878a35b277111e509da03fe6f888bd (patch) | |
tree | 44a99850fb0adffdd51cb0406ca24ecd5c917b2d | |
parent | f610fe16c0b1cb74d73d02dc55792d4ddc262ad2 (diff) | |
download | mpv-ff322864f2878a35b277111e509da03fe6f888bd.tar.bz2 mpv-ff322864f2878a35b277111e509da03fe6f888bd.tar.xz |
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.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | DOCS/build-system-differences.md | 70 | ||||
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | common/stats.c | 3 | ||||
-rw-r--r-- | generated/TOOLS/osxbundle/mpv.app/Contents/Resources/meson.build | 8 | ||||
-rw-r--r-- | generated/etc/meson.build | 20 | ||||
-rw-r--r-- | generated/meson.build | 27 | ||||
-rw-r--r-- | generated/osdep/meson.build | 57 | ||||
-rw-r--r-- | generated/player/javascript/meson.build | 6 | ||||
-rw-r--r-- | generated/player/lua/meson.build | 10 | ||||
-rw-r--r-- | generated/sub/meson.build | 6 | ||||
-rw-r--r-- | generated/wayland/meson.build | 32 | ||||
-rw-r--r-- | meson.build | 1840 | ||||
-rw-r--r-- | meson_options.txt | 117 | ||||
-rw-r--r-- | osdep/win32/pthread.c | 1 | ||||
-rw-r--r-- | waftools/fragments/bsd_thread_name.c | 6 | ||||
-rw-r--r-- | waftools/fragments/glibc_thread_name.c | 6 | ||||
-rw-r--r-- | waftools/fragments/osx_thread_name.c | 5 | ||||
-rw-r--r-- | waftools/fragments/vector.c | 4 |
19 files changed, 2240 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore index 81ef5cc7e1..29e15d9fd1 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ /old_build /Makefile + +/subprojects diff --git a/DOCS/build-system-differences.md b/DOCS/build-system-differences.md new file mode 100644 index 0000000000..7b1a5e5bfd --- /dev/null +++ b/DOCS/build-system-differences.md @@ -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. @@ -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 diff --git a/common/stats.c b/common/stats.c index ce50bdc0f3..4b4093834b 100644 --- a/common/stats.c +++ b/common/stats.c @@ -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 && diff --git a/generated/TOOLS/osxbundle/mpv.app/Contents/Resources/meson.build b/generated/TOOLS/osxbundle/mpv.app/Contents/Resources/meson.build new file mode 100644 index 0000000000..a271b4120f --- /dev/null +++ b/generated/TOOLS/osxbundle/mpv.app/Contents/Resources/meson.build @@ -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 diff --git a/generated/etc/meson.build b/generated/etc/meson.build new file mode 100644 index 0000000000..12fe732b43 --- /dev/null +++ b/generated/etc/meson.build @@ -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 diff --git a/generated/meson.build b/generated/meson.build new file mode 100644 index 0000000000..ab09d1afa8 --- /dev/null +++ b/generated/meson.build @@ -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 diff --git a/generated/osdep/meson.build b/generated/osdep/meson.build new file mode 100644 index 0000000000..a577a039e1 --- /dev/null +++ b/generated/osdep/meson.build @@ -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']) diff --git a/generated/player/javascript/meson.build b/generated/player/javascript/meson.build new file mode 100644 index 0000000000..bfff4b4e95 --- /dev/null +++ b/generated/player/javascript/meson.build @@ -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 diff --git a/generated/player/lua/meson.build b/generated/player/lua/meson.build new file mode 100644 index 0000000000..362c87cbb7 --- /dev/null +++ b/generated/player/lua/meson.build @@ -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 diff --git a/generated/sub/meson.build b/generated/sub/meson.build new file mode 100644 index 0000000000..867f218614 --- /dev/null +++ b/generated/sub/meson.build @@ -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 diff --git a/generated/wayland/meson.build b/generated/wayland/meson.build new file mode 100644 index 0000000000..19ed4bc023 --- /dev/null +++ b/generated/wayland/meson.build @@ -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'] diff --git a/meson.build b/meson.build new file mode 100644 index 0000000000..b44b161584 --- /dev/null +++ b/meson.build @@ -0,0 +1,1840 @@ +project('mpv', + 'c', + license: ['GPL2+', 'LGPL2.1+'], + version: files('./VERSION'), + meson_version: '>=0.60.0', + default_options: [ + 'buildtype=debugoptimized', + 'b_lundef=false', + 'c_std=c11', + 'warning_level=1', + ] +) + +build_root = meson.project_build_root() +source_root = meson.project_source_root() +python = find_program('python3') + +ffmpeg = { + 'name': 'ffmpeg', + 'deps': [dependency('libavutil', version: '>= 56.12.100'), + dependency('libavcodec', version: '>= 58.12.100'), + dependency('libavformat', version: '>= 58.9.100'), + dependency('libswscale', version: '>= 5.0.101'), + dependency('libavfilter', version: '>= 7.14.100'), + dependency('libswresample', version: '>= 3.0.100')], +} + +libass = dependency('libass', version: '>= 0.12.2') +pthreads = dependency('threads') + +dependencies = [ffmpeg['deps'], + libass, + pthreads] + +features = [ffmpeg['name'], libass.name(), pthreads.name()] + +# Builtin options we'd like to add to features. +if get_option('optimization') != '0' + features += 'optimize' +endif + +if get_option('debug') + features += 'debug' +endif + + +# generic sources +sources = files( + ## Audio + 'audio/aframe.c', + 'audio/chmap.c', + 'audio/chmap_sel.c', + 'audio/decode/ad_lavc.c', + 'audio/decode/ad_spdif.c', + 'audio/filter/af_drop.c', + 'audio/filter/af_format.c', + 'audio/filter/af_lavcac3enc.c', + 'audio/filter/af_scaletempo.c', + 'audio/filter/af_scaletempo2.c', + 'audio/filter/af_scaletempo2_internals.c', + 'audio/fmt-conversion.c', + 'audio/format.c', + 'audio/out/ao.c', + 'audio/out/ao_lavc.c', + 'audio/out/ao_null.c', + 'audio/out/ao_pcm.c', + 'audio/out/buffer.c', + + ## Core + 'common/av_common.c', + 'common/av_log.c', + 'common/codecs.c', + 'common/common.c', + 'common/encode_lavc.c', + 'common/msg.c', + 'common/playlist.c', + 'common/recorder.c', + 'common/stats.c', + 'common/tags.c', + 'common/version.c', + + ## Demuxers + 'demux/codec_tags.c', + 'demux/cue.c', + 'demux/cache.c', + 'demux/demux.c', + 'demux/demux_cue.c', + 'demux/demux_disc.c', + 'demux/demux_edl.c', + 'demux/demux_lavf.c', + 'demux/demux_mf.c', + 'demux/demux_mkv.c', + 'demux/demux_mkv_timeline.c', + 'demux/demux_null.c', + 'demux/demux_playlist.c', + 'demux/demux_raw.c', + 'demux/demux_timeline.c', + 'demux/ebml.c', + 'demux/packet.c', + 'demux/timeline.c', + + ## Filters + 'filters/f_async_queue.c', + 'filters/f_autoconvert.c', + 'filters/f_auto_filters.c', + 'filters/f_decoder_wrapper.c', + 'filters/f_demux_in.c', + 'filters/f_hwtransfer.c', + 'filters/f_lavfi.c', + 'filters/f_output_chain.c', + 'filters/f_swresample.c', + 'filters/f_swscale.c', + 'filters/f_utils.c', + 'filters/filter.c', + 'filters/frame.c', + 'filters/user_filters.c', + + ## Input + 'input/cmd.c', + 'input/event.c', + 'input/input.c', + 'input/ipc.c', + 'input/keycodes.c', + + ## Misc + 'misc/bstr.c', + 'misc/charset_conv.c', + 'misc/dispatch.c', + 'misc/json.c', + 'misc/natural_sort.c', + 'misc/node.c', + 'misc/rendezvous.c', + 'misc/thread_pool.c', + 'misc/thread_tools.c', + + ## Options + 'options/m_config_core.c', + 'options/m_config_frontend.c', + 'options/m_option.c', + 'options/m_property.c', + 'options/options.c', + 'options/parse_commandline.c', + 'options/parse_configfile.c', + 'options/path.c', + + ## Player + 'player/audio.c', + 'player/client.c', + 'player/command.c', + 'player/configfiles.c', + 'player/external_files.c', + 'player/loadfile.c', + 'player/main.c', + 'player/misc.c', + 'player/osd.c', + 'player/playloop.c', + 'player/screenshot.c', + 'player/scripting.c', + 'player/sub.c', + 'player/video.c', + + ## Streams + 'stream/cookies.c', + 'stream/stream.c', + 'stream/stream_avdevice.c', + 'stream/stream_cb.c', + 'stream/stream_concat.c', + 'stream/stream_edl.c', + 'stream/stream_file.c', + 'stream/stream_lavf.c', + 'stream/stream_memory.c', + 'stream/stream_mf.c', + 'stream/stream_null.c', + 'stream/stream_slice.c', + + ## Subtitles + 'sub/ass_mp.c', + 'sub/dec_sub.c', + 'sub/draw_bmp.c', + 'sub/filter_sdh.c', + 'sub/img_convert.c', + 'sub/lavc_conv.c', + 'sub/osd.c', + 'sub/osd_libass.c', + 'sub/sd_ass.c', + 'sub/sd_lavc.c', + + ## Video + 'video/csputils.c', + 'video/decode/vd_lavc.c', + 'video/filter/refqueue.c', + 'video/filter/vf_format.c', + 'video/filter/vf_sub.c', + 'video/fmt-conversion.c', + 'video/hwdec.c', + 'video/image_loader.c', + 'video/image_writer.c', + 'video/img_format.c', + 'video/mp_image.c', + 'video/mp_image_pool.c', + 'video/out/aspect.c', + 'video/out/bitmap_packer.c', + 'video/out/dither.c', + 'video/out/dr_helper.c', + 'video/out/filter_kernels.c', + 'video/out/gpu/context.c', + 'video/out/gpu/error_diffusion.c', + 'video/out/gpu/hwdec.c', + 'video/out/gpu/lcms.c', + 'video/out/gpu/libmpv_gpu.c', + 'video/out/gpu/osd.c', + 'video/out/gpu/ra.c', + 'video/out/gpu/shader_cache.c', + 'video/out/gpu/spirv.c', + 'video/out/gpu/user_shaders.c', + 'video/out/gpu/utils.c', + 'video/out/gpu/video.c', + 'video/out/gpu/video_shaders.c', + 'video/out/libmpv_sw.c', + 'video/out/vo.c', + 'video/out/vo_gpu.c', + 'video/out/vo_image.c', + 'video/out/vo_lavc.c', + 'video/out/vo_libmpv.c', + 'video/out/vo_null.c', + 'video/out/vo_tct.c', + 'video/out/win_state.c', + 'video/repack.c', + 'video/sws_utils.c', + + ## osdep + 'osdep/io.c', + 'osdep/semaphore_osx.c', + 'osdep/subprocess.c', + 'osdep/threads.c', + 'osdep/timer.c', + + ## tree_allocator + 'ta/ta.c', + 'ta/ta_talloc.c', + 'ta/ta_utils.c' +) + + +# compiler stuff +cc = meson.get_compiler('c') + +flags = ['-D_ISOC99_SOURCE', '-D_GNU_SOURCE', + '-D_FILE_OFFSET_BITS=64'] +link_flags = [] + +test_flags = ['-Werror=implicit-function-declaration', + '-Wno-error=deprecated-declarations', + '-Wno-error=unused-function', + '-Wempty-body', + '-Wdisabled-optimization', + '-Wstrict-prototypes', + '-Wno-format-zero-length', + '-Werror=format-security', + '-Wno-redundant-decls', + '-Wvla', + '-Wno-format-truncation', + '-Wimplicit-fallthrough', + '-fno-math-errno'] + +flags += cc.get_supported_arguments(test_flags) + +if cc.get_id() == 'gcc' + gcc_flags = ['-Wundef', '-Wmissing-prototypes', '-Wshadow', + '-Wno-switch', '-Wparentheses', '-Wpointer-arith', + '-Wno-pointer-sign', + # GCC bug 66425 + '-Wno-unused-result'] + flags += gcc_flags +endif + +if cc.get_id() == 'clang' + clang_flags = ['-Wno-logical-op-parentheses', + '-Wno-tautological-compare', + '-Wno-tautological-constant-out-of-range-compare'] + flags += clang_flags +endif + +darwin = host_machine.system() == 'darwin' +win32 = host_machine.system() == 'cygwin' or host_machine.system() == 'windows' +posix = false +if not win32 + posix = true + features += 'posix' +else + features += 'win32' +endif + +mswin_flags = ['-D_WIN32_WINNT=0x0602', '-DUNICODE', '-DCOBJMACROS', + '-DINITGUID', '-U__STRICT_ANSI__'] + +mswin_linkflags = ['-Wl,--major-os-version=6,--minor-os-version=0', + '-Wl,--major-subsystem-version=6,--minor-subsystem-version=0'] + +if host_machine.system() == 'windows' + flags += [mswin_flags, '-D__USE_MINGW_ANSI_STDIO=1'] + link_flags += [mswin_linkflags, '-mwindows'] +endif + +if host_machine.system() == 'cygwin' + features += 'cygwin' + flags += [mswin_flags, '-mwin32'] + link_flags += mswin_linkflags +endif + +noexecstack = false +if cc.has_link_argument('-Wl,-z,noexecstack') + link_flags += '-Wl,-z,noexecstack' + noexecstack = true +endif + +if cc.has_link_argument('-Wl,--nxcompat,--no-seh,--dynamicbase') + link_flags += '-Wl,--nxcompat,--no-seh,--dynamicbase' + noexecstack = true +endif + +if noexecstack + features += 'noexecstack' +endif + +if not get_option('build-date') + flags += '-DNO_BUILD_TIMESTAMPS' +else + features += 'build-date' +endif + +if get_option('ta-leak-report') + features += 'ta-leak-report' +endif + +libdl = cc.find_library('libdl', required: false) +if libdl.found() + dependencies += libdl + features += 'libdl' +endif + +cplugins = get_option('cplugins').require( + libdl.found() and not win32 and cc.has_link_argument('-rdynamic'), + error_message: 'cplugins not supported by the os or compiler!', +) +if cplugins.allowed() + features += 'cplugins' + link_flags += '-rdynamic' +endif + +if get_option('tests') + features += 'tests' + sources += files('test/champ.c', + 'test/gl_video.c', + 'test/img_format.c', + 'test/json.c', + 'test/linked_list.c', + 'test/paths.c', + 'test/scale_sws.c', + 'test/scale_test.c', + 'test/tests.c') +endif + +includedir = [] +win32_pthreads = get_option('win32-internal-pthreads').require( + win32 and not posix, + error_message: 'the os is not win32!', +) +if win32_pthreads.allowed() + features += 'win32-internal-pthreads' + flags += ['-isystem', '-I', '-DIN_WINPTHREAD'] + # Note: Adding this include causes POSIX_TIMERS to be defined for + # unclear reasons (some confusion with <pthread.h> probably). + # Hack around it by using HAVE_WIN32_INTERNAL_PTHREADS. + includedir += include_directories('osdep/win32/include') + sources += files('osdep/win32/pthread.c') +endif + +pthread_debug = get_option('pthread-debug').require( + win32_pthreads.disabled(), + error_message: 'win32-internal-pthreads was found!', +) +if pthread_debug.allowed() + features += 'pthread-debug' + flags += '-DMP_PTHREAD_DEBUG' +endif + +add_project_arguments(flags, language: 'c') +add_project_link_arguments(link_flags, language: ['c', 'objc']) + + +# osdep +cocoa = dependency('appleframeworks', modules: ['Cocoa', 'IOKit', 'QuartzCore'], + required: get_option('cocoa')) +if cocoa.found() + dependencies += cocoa + features += 'cocoa' + sources += files('osdep/macosx_application.m', + 'osdep/macosx_events.m', + 'osdep/macosx_menubar.m', + 'osdep/main-fn-cocoa.c', + 'osdep/path-macosx.m', + 'video/out/cocoa_common.m', + 'video/out/cocoa/events_view.m', + 'video/out/cocoa/video_view.m', + 'video/out/cocoa/window.m') +endif + +if posix + sources += files('input/ipc-unix.c', + 'osdep/path-unix.c', + 'osdep/polldev.c', + 'osdep/subprocess-posix.c', + 'osdep/terminal-unix.c', + 'sub/filter_regex.c') +endif + +if posix and not cocoa.found() + sources += files('osdep/main-fn-unix.c') +endif + +if darwin + sources += files('osdep/timer-darwin.c') +endif + +if posix and not darwin + sources += files('osdep/timer-linux.c') +endif + +cd_devices = { + 'windows': 'D:', + 'cygwin': 'D:', + 'darwin': '/dev/disk1', + 'freebsd': '/dev/cd0', + 'openbsd': '/dev/rcd0c', + 'linux': '/dev/sr0', +} +if host_machine.system() in cd_devices + cd_device = cd_devices[host_machine.system()] +else + cd_device = '/dev/cdrom' +endif + +dvd_devices = { + 'windows': 'D:', + 'cygwin': 'D:', + 'darwin': '/dev/diskN', + 'freebsd': '/dev/cd0', + 'openbsd': '/dev/rcd0c', + 'linux': '/dev/sr0', +} +if host_machine.system() in cd_devices + dvd_device = dvd_devices[host_machine.system()] +else + dvd_device = '/dev/dvd' +endif + +android = host_machine.system() == 'android' +if android + features += 'android' + sources += files('audio/out/ao_audiotrack.c', + 'video/out/android_common.c', + 'video/out/vo_mediacodec_embed.c') +endif + +uwp_opt = get_option('uwp').require( + not get_option('cplayer'), + error_message: 'cplayer is not false!', +) +uwp = cc.find_library('windowsapp', required: uwp_opt) +if uwp.found() + dependencies += uwp + features += 'uwp' + sources += files('osdep/path-uwp.c') +endif + +if win32 + sources += files('osdep/timer-win2.c', + 'osdep/w32_keyboard.c', + 'osdep/windows_utils.c') +endif + +win32_desktop = win32 and not uwp.found() +if win32_desktop + win32_desktop_libs = [cc.find_library('avrt'), + cc.find_library('dwmapi'), + cc.find_library('gdi32'), + cc.find_library('ole32'), + cc.find_library('uuid'), + cc.find_library('version'), + cc.find_library('winmm')] + dependencies += win32_desktop_libs + features += 'win32-desktop' + sources += files('input/ipc-win.c', + 'osdep/main-fn-win.c', + 'osdep/path-win.c', + 'osdep/subprocess-win.c', + 'osdep/terminal-win.c', + 'video/out/w32_common.c', + 'video/out/win32/displayconfig.c', + 'video/out/win32/droptarget.c') +endif + +if not posix and not win32_desktop + sources += files('input/ipc-dummy.c', + 'osdep/subprocess-dummy.c', + 'osdep/terminal-dummy.c') +endif + +glob_posix = cc.has_function('glob', prefix: '#include <glob.h>') +if glob_posix + features += 'glob_posix' +endif + +glob_win32 = win32 and not posix +if glob_win32 + features += 'glob_win32' + sources += files('osdep/glob-win.c') +endif + +glob = glob_posix or glob_win32 +if glob + features += 'glob' +endif + +vt_h = cc.has_header_symbol('sys/vt.h', 'VT_GETMODE') +if vt_h + features += 'vt.h' +endif + +consio_h = cc.has_header_symbol('sys/consio.h', 'VT_GETMODE') +if consio_h + features += 'consio.h' +endif + +fragments = join_paths(source_root, 'waftools', 'fragments') + +glibc_thread_name = cc.compiles(files(join_paths(fragments, 'glibc_thread_name.c')), + name: 'glibc-thread-name check') +if glibc_thread_name and posix + features += 'glibc-thread-name' +endif + +osx_thread_name = false +if not glibc_thread_name |