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