From 6eac0a5f2c552728efca420b1129fae7d4fea773 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Sun, 11 Oct 2026 23:40:57 +0300 Subject: feat: backend selection (Wayland, X11, Cocoa) --- meson.build | 93 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 41 insertions(+), 52 deletions(-) (limited to 'meson.build') diff --git a/meson.build b/meson.build index e4396b2..e599acf 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,10 @@ project( 'yasl', 'c', + meson_version: '>=1.6.0', version: '0.1.0', default_options: [ - 'c_std=c11', + 'c_std=c23', 'warning_level=2', 'b_lto=false', ], @@ -15,60 +16,59 @@ system = host_machine.system() inc = include_directories('include', 'src') deps = [] -sources = files( - 'src/common/timing.c', - 'src/common/utf8.c', - 'src/common/loop.c', -) +sources = [] + +has_wayland = false +has_x11 = false +has_cocoa = system == 'darwin' if system == 'linux' - wl_client = dependency('wayland-client') - wl_cursor = dependency('wayland-cursor') - xkbcommon = dependency('xkbcommon') + wl_client = dependency('wayland-client', required: get_option('wayland')) + wl_cursor = dependency('wayland-cursor', required: get_option('wayland')) + xkbcommon = dependency('xkbcommon', required: get_option('wayland')) + has_wayland = wl_client.found() and wl_cursor.found() and xkbcommon.found() + x11 = dependency('x11', required: get_option('x11')) + x11_xkb = dependency('xkbcommon', required: get_option('x11')) + has_x11 = x11.found() and x11_xkb.found() + if has_x11 + deps += [x11, x11_xkb] + endif threads = dependency('threads') m_dep = cc.find_library('m', required: false) rt_dep = cc.find_library('rt', required: false) - deps += [wl_client, wl_cursor, xkbcommon, threads, m_dep, rt_dep] - - proto_src = files( - 'src/wayland/protocols/commit-timing-v1-protocol.c', - 'src/wayland/protocols/cursor-shape-v1-protocol.c', - 'src/wayland/protocols/fifo-v1-protocol.c', - 'src/wayland/protocols/fractional-scale-v1-protocol.c', - 'src/wayland/protocols/presentation-time-protocol.c', - 'src/wayland/protocols/primary-selection-unstable-v1-protocol.c', - 'src/wayland/protocols/tablet-v2-protocol.c', - 'src/wayland/protocols/tearing-control-v1-protocol.c', - 'src/wayland/protocols/text-input-unstable-v3-protocol.c', - 'src/wayland/protocols/viewporter-protocol.c', - 'src/wayland/protocols/xdg-decoration-protocol.c', - 'src/wayland/protocols/xdg-shell-protocol.c', - 'src/wayland/protocols/xdg-toplevel-drag-v1-protocol.c', - ) - - sources += files( - 'src/wayland/buffer.c', - 'src/wayland/clipboard.c', - 'src/wayland/drag.c', - 'src/wayland/ime.c', - 'src/wayland/keyboard.c', - 'src/wayland/pointer.c', - 'src/wayland/popup.c', - 'src/wayland/shell.c', - 'src/wayland/surface.c', - ) + proto_src + deps += [threads, m_dep, rt_dep] + if has_wayland + deps += [wl_client, wl_cursor, xkbcommon] + endif elif system == 'darwin' add_languages('objc') - sources += files('src/cocoa/window.m') deps += [ dependency('appleframeworks', modules: ['AppKit', 'Metal', 'QuartzCore']), ] +else + error('YASL supports Linux and macOS.') +endif + +if not has_wayland and not has_x11 and not has_cocoa + error('Enable at least one window backend.') +endif + +add_project_arguments( + '-DYASL_HAS_WAYLAND=' + (has_wayland ? '1' : '0'), + '-DYASL_HAS_X11=' + (has_x11 ? '1' : '0'), + '-DYASL_HAS_COCOA=' + (has_cocoa ? '1' : '0'), + language: has_cocoa ? ['c', 'objc'] : ['c'], +) +if has_cocoa + add_project_arguments('-fblocks', language: 'objc') endif +subdir('src') + yasl_lib = both_libraries( 'yasl', sources, - include_directories: [inc, include_directories('src/wayland')], + include_directories: inc, dependencies: deps, install: true, ) @@ -103,15 +103,4 @@ executable( dependencies: deps, ) -test_exe = executable( - 'yasl-test', - 'tests/test_lifecycle.c', - include_directories: inc, - link_with: yasl_lib.get_static_lib(), -) - -add_test_setup('asan') -add_test_setup('tsan') -add_test_setup('msan') - -test('basic', test_exe) +subdir('tests') -- cgit v1.2.3