master meson.build
  1project(
  2    'maus',
  3    'c',
  4    meson_version: '>=1.1.0',
  5    default_options: [
  6        'c_std=c89',
  7        'warning_level=2',
  8        'optimization=2',
  9    ],
 10)
 11
 12backend = get_option('window_backend')
 13
 14if backend == 'auto'
 15    if host_machine.system() == 'windows'
 16        backend = 'windows'
 17    elif dependency('wayland-client', required: false).found() and dependency('wayland-cursor', required: false).found() and dependency('xkbcommon', required: false).found()
 18        backend = 'wayland'
 19    elif dependency('x11', required: false).found() and dependency('xext', required: false).found() and dependency('xi', required: false).found()
 20        backend = 'x11'
 21    else
 22        error('failed to determine window backend')
 23    endif
 24endif
 25cc = meson.get_compiler('c')
 26
 27
 28inc = include_directories('include')
 29common_sources = [
 30    'source/maus.c',
 31    'source/maus_font.c',
 32    'source/utils.c',
 33]
 34backend_sources = []
 35deps = []
 36c_args = []
 37backend_override_options = ['c_std=c89']
 38lib_name = 'maus_' + backend
 39
 40if backend == 'x11'
 41    c_args += ['-DBACKEND_X11']
 42    deps += [
 43        dependency('x11'),
 44        dependency('xext'),
 45        dependency('xi'),
 46    ]
 47    backend_sources += ['source/maus_x11.c']
 48
 49    if host_machine.system() == 'openbsd'
 50        c_args += ['-I/usr/X11R6/include']
 51    endif
 52
 53elif backend == 'wayland'
 54    c_args += ['-DBACKEND_WAY']
 55    backend_override_options = ['c_std=c99']
 56    deps += [
 57        dependency('wayland-client'),
 58        dependency('wayland-cursor'),
 59        dependency('xkbcommon'),
 60    ]
 61
 62    wayland = import('wayland')
 63    backend_sources += wayland.scan_xml(wayland.find_protocol('xdg-shell'))
 64    backend_sources += wayland.scan_xml(
 65        wayland.find_protocol('pointer-constraints', state: 'unstable', version: 1),
 66    )
 67    backend_sources += wayland.scan_xml(
 68        wayland.find_protocol('relative-pointer', state: 'unstable', version: 1),
 69    )
 70
 71    backend_sources += ['source/maus_wayland.c']
 72
 73elif backend == 'windows'
 74    c_args += ['-DBACKEND_WIN']
 75    deps += [
 76        cc.find_library('gdi32'),
 77        cc.find_library('user32'),
 78    ]
 79    backend_sources += ['source/maus_windows.c']
 80endif
 81
 82common = static_library(
 83    'maus_common_' + backend,
 84    common_sources,
 85    include_directories: inc,
 86    c_args: c_args,
 87    override_options: ['c_std=c89'],
 88)
 89
 90backend_lib = static_library(
 91    'maus_backend_' + backend,
 92    backend_sources,
 93    include_directories: inc,
 94    c_args: c_args,
 95    dependencies: deps,
 96    override_options: backend_override_options,
 97)
 98
 99maus = static_library(
100    lib_name,
101    objects: [
102        common.extract_all_objects(recursive: false),
103        backend_lib.extract_all_objects(recursive: false),
104    ],
105    dependencies: deps,
106)
107
108maus_dep = declare_dependency(
109    include_directories: inc,
110    link_with: maus,
111    dependencies: deps,
112    compile_args: c_args,
113)
114
115
116message('selected backend: ' + backend)
117