From 325e29e111b40a417a3118f813262352dfbcc28f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 26 Oct 2023 19:28:20 +0200 Subject: [PATCH] meson: move platform specific code into own meson files --- meson.build | 88 ++------------------------ osdep/darwin/meson.build | 131 ++++++++++++++++++++++++--------------- osdep/meson.build | 20 +++++- osdep/unix/meson.build | 7 +++ osdep/uwp/meson.build | 1 + osdep/win32/meson.build | 32 ++++++++++ test/meson.build | 39 ++---------- 7 files changed, 148 insertions(+), 170 deletions(-) create mode 100644 osdep/unix/meson.build create mode 100644 osdep/uwp/meson.build create mode 100644 osdep/win32/meson.build diff --git a/meson.build b/meson.build index 7471a471b5480..7fe8a95fff1b7 100644 --- a/meson.build +++ b/meson.build @@ -246,7 +246,6 @@ sources = files( ## osdep 'osdep/io.c', - 'osdep/darwin/semaphore.c', 'osdep/subprocess.c', 'osdep/threads.c', 'osdep/timer.c', @@ -395,42 +394,17 @@ cocoa = dependency('appleframeworks', modules: ['Cocoa', 'IOKit', 'QuartzCore'], features += {'cocoa': cocoa.found()} if features['cocoa'] dependencies += cocoa - sources += files('osdep/darwin/utils.c', - 'osdep/darwin/language.c', - 'osdep/darwin/application.m', - 'osdep/darwin/events.m', - 'osdep/darwin/menubar.m', - 'osdep/darwin/main-fn.c', - 'osdep/darwin/path.m', - 'video/out/cocoa_common.m', + sources += files('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 - path_source = files('osdep/unix/path.c') - subprocess_source = files('osdep/unix/subprocess.c') sources += files('input/ipc-unix.c', - 'osdep/unix/poll_wrapper.c', - 'osdep/unix/terminal.c', 'sub/filter_regex.c') endif -if posix and not features['cocoa'] - sources += files('osdep/unix/main-fn.c', - 'osdep/unix/language.c') -endif - -if darwin - path_source = files('osdep/darwin/path.c') - timer_source = files('osdep/darwin/timer.c') -endif - -if posix and not darwin - timer_source = files('osdep/unix/timer.c') -endif - features += {'ppoll': cc.has_function('ppoll', args: '-D_GNU_SOURCE', prefix: '#include ')} @@ -479,16 +453,9 @@ uwp = cc.find_library('windowsapp', required: uwp_opt) features += {'uwp': uwp.found()} if features['uwp'] dependencies += uwp - path_source = files('osdep/uwp/path.c') - subprocess_source = [] endif features += {'win32-executable': win32 and get_option('cplayer')} -if win32 - timer_source = files('osdep/win32/timer.c') - sources += files('osdep/win32/keyboard.c', - 'osdep/win32/utils.c') -endif features += {'win32-desktop': win32 and not uwp.found()} if features['win32-desktop'] @@ -501,30 +468,21 @@ if features['win32-desktop'] cc.find_library('version'), cc.find_library('winmm')] dependencies += win32_desktop_libs - path_source = files('osdep/win32/path.c') - subprocess_source = files('osdep/win32/subprocess.c') sources += files('input/ipc-win.c', - 'osdep/win32/language.c', - 'osdep/win32/main-fn.c', - 'osdep/win32/terminal.c', 'video/out/w32_common.c', 'video/out/win32/displayconfig.c', 'video/out/win32/droptarget.c') endif if not posix and not features['win32-desktop'] - subprocess_source = files('osdep/subprocess-dummy.c') sources += files('input/ipc-dummy.c') endif features += {'glob-posix': cc.has_function('glob', prefix: '#include ')} features += {'glob-win32': win32 and not features['glob-posix']} -if features['glob-win32'] - sources += files('osdep/win32/glob.c') -endif -features += {'glob': features['glob-posix']} +features += {'glob': features['glob-posix'] or features['glob-win32']} features += {'vt.h': cc.has_header_symbol('sys/vt.h', 'VT_GETMODE')} @@ -559,8 +517,6 @@ vector = get_option('vector').require( ) features += {'vector': vector.allowed()} -sources += path_source + subprocess_source + timer_source - # various file generations tools_directory = join_paths(source_root, 'TOOLS') @@ -1529,13 +1485,7 @@ features += {'swift': swift.allowed()} swift_sources = [] if features['cocoa'] and features['swift'] - swift_sources += files('osdep/darwin/libmpv_helper.swift', - 'osdep/darwin/log_helper.swift', - 'osdep/darwin/mpv_helper.swift', - 'osdep/darwin/precise_timer.swift', - 'osdep/darwin/swift_compat.swift', - 'osdep/darwin/swift_extensions.swift', - 'video/out/mac/common.swift', + swift_sources += files('video/out/mac/common.swift', 'video/out/mac/title_bar.swift', 'video/out/mac/view.swift', 'video/out/mac/window.swift') @@ -1561,23 +1511,12 @@ macos_media_player = get_option('macos-media-player').require( error_message: 'Either the macos sdk version is not at least 10.12.2 or swift was not found!', ) features += {'macos-media-player': macos_media_player.allowed()} -if features['macos-media-player'] - swift_sources += files('osdep/darwin/remote_command_center.swift') -endif - -if features['swift'] and swift_sources.length() > 0 - subdir('osdep') -endif macos_touchbar = get_option('macos-touchbar').require( features['cocoa'] and cc.has_header('AppKit/NSTouchBar.h'), error_message: 'Either cocoa could not be found or AppKit/NSTouchBar.h could not be found!', ) features += {'macos-touchbar': macos_touchbar.allowed()} -if features['macos-touchbar'] - sources += files('osdep/darwin/touchbar.m') -endif - # manpages manpage = 'DOCS/man/mpv.rst' @@ -1687,28 +1626,9 @@ message('List of enabled features: ' + feature_str) features += {'cplayer': get_option('cplayer')} features += {'libmpv-' + get_option('default_library'): get_option('libmpv')} +subdir('osdep') # build targets -if win32 - windows = import('windows') - res_flags = ['--codepage=65001'] - - # Unintuitively, this compile operates out of the osdep subdirectory. - # Hence, these includes are needed. - res_includes = [source_root, build_root] - - resources = ['etc/mpv-icon-8bit-16x16.png', - 'etc/mpv-icon-8bit-32x32.png', - 'etc/mpv-icon-8bit-64x64.png', - 'etc/mpv-icon-8bit-128x128.png', - 'etc/mpv-icon.ico', - 'osdep/win32/mpv.exe.manifest'] - - sources += windows.compile_resources('osdep/win32/mpv.rc', args: res_flags, depend_files: resources, - depends: version_h, include_directories: res_includes) -endif - - client_h_define = cc.get_define('MPV_CLIENT_API_VERSION', prefix: '#include "libmpv/client.h"', include_directories: include_directories('.')) major = client_h_define.split('|')[0].split('<<')[0].strip('() ') diff --git a/osdep/darwin/meson.build b/osdep/darwin/meson.build index e7f8c843ca5a5..b95f4e8e1a86e 100644 --- a/osdep/darwin/meson.build +++ b/osdep/darwin/meson.build @@ -1,59 +1,90 @@ -# custom swift targets -bridge = join_paths(source_root, 'osdep/darwin/swift_bridge.h') -header = join_paths(build_root, 'osdep/darwin/swift.h') -module = join_paths(build_root, 'osdep/darwin/swift.swiftmodule') -target = join_paths(build_root, 'osdep/darwin/swift.o') +sources += files('path.c', + 'semaphore.c', + 'timer.c') -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'] +if features['cocoa'] + sources += files('utils.c', + 'language.c', + 'application.m', + 'events.m', + 'menubar.m', + 'main-fn.c', + 'path.m') endif -if get_option('debug') - swift_flags += '-g' +if features['macos-touchbar'] + sources += files('touchbar.m') endif -if get_option('optimization') != '0' - swift_flags += '-O' -endif +if features['swift'] and swift_sources.length() > 0 + swift_sources += files('libmpv_helper.swift', + 'log_helper.swift', + 'mpv_helper.swift', + 'precise_timer.swift', + 'swift_compat.swift', + 'swift_extensions.swift') -if macos_10_11_features.allowed() - swift_flags += ['-D', 'HAVE_MACOS_10_11_FEATURES'] -endif + if features['macos-media-player'] + swift_sources += files('remote_command_center.swift') + endif -if macos_10_14_features.allowed() - swift_flags += ['-D', 'HAVE_MACOS_10_14_FEATURES'] -endif + # custom swift targets + bridge = join_paths(source_root, 'osdep/darwin/swift_bridge.h') + header = join_paths(build_root, 'osdep/darwin/swift.h') + module = join_paths(build_root, 'osdep/darwin/swift.swiftmodule') + target = join_paths(build_root, 'osdep/darwin/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', 'swift', + '-emit-module-path', '@OUTPUT0@', '-import-objc-header', bridge, + '-emit-objc-header-path', '@OUTPUT1@', '-o', '@OUTPUT2@', + '@INPUT@', '-I.', '-I' + source_root, + '-I' + libplacebo.get_variable('includedir', + default_value: source_root / 'subprojects' / 'libplacebo' / 'src' / 'include')] + + swift_targets = custom_target('swift_targets', + input: swift_sources, + output: ['swift.swiftmodule', 'swift.h', '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) -extra_flags = get_option('swift-flags').split() -swift_flags += extra_flags - -swift_compile = [swift_prog, swift_flags, '-module-name', 'swift', - '-emit-module-path', '@OUTPUT0@', '-import-objc-header', bridge, - '-emit-objc-header-path', '@OUTPUT1@', '-o', '@OUTPUT2@', - '@INPUT@', '-I.', '-I' + source_root, - '-I' + libplacebo.get_variable('includedir', - default_value: source_root / 'subprojects' / 'libplacebo' / 'src' / 'include')] - -swift_targets = custom_target('swift_targets', - input: swift_sources, - output: ['swift.swiftmodule', 'swift.h', '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'] + # 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']) endif -add_project_link_arguments(swift_link_flags, language: ['c', 'objc']) diff --git a/osdep/meson.build b/osdep/meson.build index ab6768264e15b..0bd5b63d4e122 100644 --- a/osdep/meson.build +++ b/osdep/meson.build @@ -1 +1,19 @@ -subdir('darwin') +if posix and not darwin + subdir('unix') +endif + +if darwin + subdir('darwin') +endif + +if features['win32-desktop'] + subdir('win32') +endif + +if features['uwp'] + subdir('uwp') +endif + +if not posix and not features['win32-desktop'] + sources += files('subprocess-dummy.c') +endif diff --git a/osdep/unix/meson.build b/osdep/unix/meson.build new file mode 100644 index 0000000000000..059d8854a08ce --- /dev/null +++ b/osdep/unix/meson.build @@ -0,0 +1,7 @@ +sources += files('language.c', + 'main-fn.c', + 'path.c', + 'poll_wrapper.c', + 'subprocess.c', + 'terminal.c', + 'timer.c') diff --git a/osdep/uwp/meson.build b/osdep/uwp/meson.build new file mode 100644 index 0000000000000..87a24d86aad3c --- /dev/null +++ b/osdep/uwp/meson.build @@ -0,0 +1 @@ +sources += files('path.c') diff --git a/osdep/win32/meson.build b/osdep/win32/meson.build new file mode 100644 index 0000000000000..ae77691a5dbf7 --- /dev/null +++ b/osdep/win32/meson.build @@ -0,0 +1,32 @@ +sources += files('keyboard.c', + 'path.c', + 'timer.c', + 'utils.c') + +if features['win32-desktop'] + sources += files('language.c', + 'main-fn.c', + 'subprocess.c', + 'terminal.c') +endif + +if features['glob-win32'] + sources += files('glob.c') +endif + +windows = import('windows') +res_flags = ['--codepage=65001'] + +# Unintuitively, this compile operates out of the osdep subdirectory. +# Hence, these includes are needed. +res_includes = [source_root, build_root] + +resources = [source_root / 'etc/mpv-icon-8bit-16x16.png', + source_root / 'etc/mpv-icon-8bit-32x32.png', + source_root / 'etc/mpv-icon-8bit-64x64.png', + source_root / 'etc/mpv-icon-8bit-128x128.png', + source_root / 'etc/mpv-icon.ico', + 'mpv.exe.manifest'] + +sources += windows.compile_resources('mpv.rc', args: res_flags, depend_files: resources, + depends: version_h, include_directories: res_includes) diff --git a/test/meson.build b/test/meson.build index 474858d68973f..3ce68b5a862d1 100644 --- a/test/meson.build +++ b/test/meson.build @@ -8,49 +8,19 @@ refdir = join_paths(source_root, 'test', 'ref') # are required in order to run a diff command when comparing # different files. Stuff will probably break if core things are # carelessly moved around. -test_utils_args = [] -test_utils_files = [ - 'audio/chmap.c', - 'audio/format.c', - 'common/common.c', - 'misc/bstr.c', - 'misc/dispatch.c', - 'misc/json.c', - 'misc/node.c', - 'misc/random.c', - 'misc/thread_tools.c', - 'options/m_config_core.c', - 'options/m_config_frontend.c', - 'options/m_option.c', - 'options/path.c', - 'osdep/io.c', - 'osdep/subprocess.c', - 'osdep/timer.c', - timer_source, - path_source, - subprocess_source, - 'ta/ta.c', - 'ta/ta_talloc.c', - 'ta/ta_utils.c' -] - test_utils_deps = [libavutil, libm] # The zimg code requires using threads. -if features['win32-internal-pthreads'] - test_utils_args += '-DWIN32_TESTS' - test_utils_files += ['osdep/win32/pthread.c'] -else +if not features['win32-internal-pthreads'] test_utils_deps += pthreads endif if features['win32-desktop'] test_utils_deps += cc.find_library('winmm') endif -test_utils_objects = libmpv.extract_objects(test_utils_files) +test_utils_objects = libmpv.extract_all_objects(recursive: true) test_utils = static_library('test-utils', 'test_utils.c', include_directories: incdir, - c_args: test_utils_args, objects: test_utils_objects, - dependencies: test_utils_deps) + objects: test_utils_objects, dependencies: test_utils_deps) # For getting imgfmts and stuff. img_utils_files = [ @@ -99,9 +69,8 @@ test('linked-list', linked_list) timer = executable('timer', files('timer.c'), include_directories: incdir, link_with: test_utils) test('timer', timer) -paths_objects = libmpv.extract_objects('options/path.c', path_source) paths = executable('paths', 'paths.c', include_directories: incdir, - objects: paths_objects, link_with: test_utils) + objects: libmpv.extract_objects(), link_with: test_utils) test('paths', paths) if get_option('libmpv')