summaryrefslogtreecommitdiff
path: root/meson.build
blob: 66732406c61d27aa52eedf298b3df2816c4028aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
project(
    'yasl',
    'c',
    meson_version: '>=1.6.0',
    version: '0.1.0',
    default_options: [
        'c_std=c23',
        'warning_level=2',
        'b_lto=false',
    ],
)

cc = meson.get_compiler('c')
system = host_machine.system()

inc = include_directories('include', 'src')

deps = []
sources = []

has_wayland = false
has_x11 = false
has_cocoa = system == 'darwin'

if system == 'linux'
    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'))
    xi = dependency('xi', required: get_option('x11'))
    x11_xkb = dependency('xkbcommon', required: get_option('x11'))
    has_x11 = x11.found() and xi.found() and x11_xkb.found()
    if has_x11
        deps += [x11, xi, x11_xkb]
    endif
    threads = dependency('threads')
    m_dep = cc.find_library('m', required: false)
    rt_dep = cc.find_library('rt', required: false)
    deps += [threads, m_dep, rt_dep]
    if has_wayland
        deps += [wl_client, wl_cursor, xkbcommon]
    endif
elif system == 'darwin'
    add_languages('objc')
    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,
    dependencies: deps,
    gnu_symbol_visibility: 'hidden',
    install: true,
)

install_headers(
    'include/yasl/yasl.h',
    'include/yasl/timing.h',
    'include/yasl/loop.h',
    'include/yasl/native.h',
    subdir: 'yasl',
)

if has_wayland
    install_headers('include/yasl/native/wayland.h', subdir: 'yasl/native')
endif
if has_x11
    install_headers('include/yasl/native/x11.h', subdir: 'yasl/native')
endif
if has_cocoa
    install_headers('include/yasl/native/cocoa.h', subdir: 'yasl/native')
endif

pkg = import('pkgconfig')
pkg.generate(
    yasl_lib.get_shared_lib(),
    name: 'yasl',
    description: 'Yet Another Surface Library - minimal, modern desktop window surface abstraction',
    version: meson.project_version(),
    subdirs: '.',
)

yasl_dep = declare_dependency(
    link_with: yasl_lib.get_static_lib(),
    include_directories: include_directories('include'),
    dependencies: deps,
)
meson.override_dependency('yasl', yasl_dep)

executable(
    'yasl-example',
    'examples/simple_window.c',
    include_directories: inc,
    link_with: yasl_lib.get_shared_lib(),
    dependencies: deps,
)

tablet_example = executable(
    'yasl-tablet',
    'examples/tablet.c',
    dependencies: yasl_dep,
)

subdir('tests')