summaryrefslogtreecommitdiff
path: root/meson.build
blob: b6af11739c2aa9fac8db04c96b6bafabd0811b21 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
project(
    'yasl',
    'c',
    meson_version: '>=1.6.0',
    version: '0.2.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_dbus = false
has_egl = false
has_vulkan = 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'))
    xext = dependency('xext', required: get_option('x11'))
    xrandr = dependency('xrandr', required: false)
    has_x11 = x11.found() and xi.found() and x11_xkb.found() and xext.found()
    if has_x11
        deps += [x11, xi, x11_xkb, xext]
        if xrandr.found()
            deps += [xrandr]
            add_project_arguments('-DYASL_HAS_XRANDR=1', language: 'c')
        endif
    endif
    dbus = dependency('dbus-1', required: get_option('dbus'))
    has_dbus = dbus.found()
    if has_dbus
        deps += [dbus]
    endif
    egl_dep = dependency('egl', required: false)
    wayland_egl_dep = dependency('wayland-egl', required: false)
    has_egl = egl_dep.found() and (not has_wayland or wayland_egl_dep.found())
    if has_egl
        deps += egl_dep
        if has_wayland
            deps += wayland_egl_dep
        endif
    endif
    vulkan_dep = dependency('vulkan', required: false)
    has_vulkan = vulkan_dep.found()
    m_dep = cc.find_library('m', required: false)
    rt_dep = cc.find_library('rt', required: false)
    deps += [m_dep, rt_dep]
    if has_wayland
        deps += [wl_client, wl_cursor, xkbcommon]
    endif
elif system == 'darwin'
    add_languages('objc', native: false)
    if not cc.compiles('''
        #if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 140000
        #error YASL requires macOS 14 or newer
        #endif
        int main(void) { return 0; }
        ''', name: 'macOS deployment target is at least 14')
        error('Cocoa requires macOS 14 or newer. Set MACOSX_DEPLOYMENT_TARGET=14.0 or a newer target before configuring.')
    endif
    deps += [
        dependency('appleframeworks', modules: ['AppKit', 'Metal', 'QuartzCore', 'UserNotifications']),
    ]
else
    error('YASL supports Linux and macOS.')
endif

if has_cocoa
    vulkan_dep = dependency('vulkan', required: false)
    has_vulkan = vulkan_dep.found()
endif

if not has_wayland and not has_x11 and not has_cocoa
    error('Enable at least one window backend.')
endif

add_project_arguments(
    '-Werror=deprecated-declarations',
    '-DYASL_HAS_EGL=' + (has_egl ? '1' : '0'),
    '-DYASL_HAS_VULKAN=' + (has_vulkan ? '1' : '0'),
    '-DYASL_HAS_WAYLAND=' + (has_wayland ? '1' : '0'),
    '-DYASL_HAS_X11=' + (has_x11 ? '1' : '0'),
    '-DYASL_HAS_COCOA=' + (has_cocoa ? '1' : '0'),
    '-DYASL_HAS_DBUS=' + (has_dbus ? '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,
    version: meson.project_version(),
    # Until 1.0, every minor release may break the ABI.
    soversion: '0.2',
    include_directories: inc,
    dependencies: deps,
    gnu_symbol_visibility: 'hidden',
    install: true,
)

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

install_headers('include/yasl/yasl.h', 'include/yasl/keycodes.h', subdir: 'yasl')
if has_vulkan
    install_headers('include/yasl/vulkan.h', subdir: 'yasl')
endif
pkgconfig = import('pkgconfig')
pkgconfig.generate(yasl_lib, name: 'yasl',
    description: 'Desktop surfaces for application-owned rendering',
    libraries_private: deps,
)


hello_example = executable(
    'yasl-hello',
    'examples/hello.c',
    include_directories: inc,
    link_with: yasl_lib.get_shared_lib(),
)

interactive_example = 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,
)

notepad_example = executable(
    'yasl-notepad',
    'examples/notepad.c',
    dependencies: yasl_dep,
)

if has_egl
    game_example = executable(
        'yasl-game',
        'examples/game.c',
        dependencies: yasl_dep,
    )
endif

subdir('tests')