commit 37f6208

shrub  ·  2026-08-04 23:45:52 +0000 UTC
parent 5511bde
Make backend selection automatic + muon fmt
2 files changed,  +82, -59
+76, -54
  1@@ -1,21 +1,34 @@
  2 project(
  3-	'maus',
  4-	'c',
  5-	default_options: [
  6-		'c_std=c89',
  7-		'warning_level=2',
  8-		'optimization=2',
  9-	]
 10+    'maus',
 11+    'c',
 12+    default_options: [
 13+        'c_std=c89',
 14+        'warning_level=2',
 15+        'optimization=2',
 16+    ],
 17 )
 18 
 19 backend = get_option('window_backend')
 20+
 21+if backend == 'auto'
 22+    if host_machine.system() == 'windows'
 23+        backend = 'windows'
 24+    elif dependency('wayland-client', required: false).found() and dependency('wayland-cursor', required: false).found() and dependency('xkbcommon', required: false).found()
 25+        backend = 'wayland'
 26+    elif dependency('x11', required: false).found() and dependency('xext', required: false).found() and dependency('xi', required: false).found()
 27+        backend = 'x11'
 28+    else
 29+        error('failed to determine window backend')
 30+    endif
 31+endif
 32 cc = meson.get_compiler('c')
 33 
 34+
 35 inc = include_directories('include')
 36 common_sources = [
 37-	'source/maus.c',
 38-	'source/maus_font.c',
 39-	'source/utils.c',
 40+    'source/maus.c',
 41+    'source/maus_font.c',
 42+    'source/utils.c',
 43 ]
 44 backend_sources = []
 45 deps = []
 46@@ -24,67 +37,76 @@ backend_override_options = ['c_std=c89']
 47 lib_name = 'maus_' + backend
 48 
 49 if backend == 'x11'
 50-	c_args += ['-DBACKEND_X11']
 51-	deps += [
 52-		dependency('x11'),
 53-		dependency('xext'),
 54-		dependency('xi'),
 55-	]
 56-	backend_sources += ['source/maus_x11.c']
 57-
 58+    c_args += ['-DBACKEND_X11']
 59+    deps += [
 60+        dependency('x11'),
 61+        dependency('xext'),
 62+        dependency('xi'),
 63+    ]
 64+    backend_sources += ['source/maus_x11.c']
 65 
 66 elif backend == 'wayland'
 67-	c_args += ['-DBACKEND_WAY']
 68-	backend_override_options = ['c_std=c99']
 69-	deps += [ dependency('wayland-client'), dependency('wayland-cursor'), dependency('xkbcommon'), ]
 70+    c_args += ['-DBACKEND_WAY']
 71+    backend_override_options = ['c_std=c99']
 72+    deps += [
 73+        dependency('wayland-client'),
 74+        dependency('wayland-cursor'),
 75+        dependency('xkbcommon'),
 76+    ]
 77 
 78-	wayland = import('wayland')
 79-	backend_sources += wayland.scan_xml(wayland.find_protocol('xdg-shell'))
 80-	backend_sources += wayland.scan_xml(wayland.find_protocol('pointer-constraints', state: 'unstable', version: 1))
 81-	backend_sources += wayland.scan_xml(wayland.find_protocol('relative-pointer', state: 'unstable', version: 1))
 82-
 83-	backend_sources += ['source/maus_wayland.c']
 84+    wayland = import('wayland')
 85+    backend_sources += wayland.scan_xml(wayland.find_protocol('xdg-shell'))
 86+    backend_sources += wayland.scan_xml(
 87+        wayland.find_protocol('pointer-constraints', state: 'unstable', version: 1),
 88+    )
 89+    backend_sources += wayland.scan_xml(
 90+        wayland.find_protocol('relative-pointer', state: 'unstable', version: 1),
 91+    )
 92 
 93+    backend_sources += ['source/maus_wayland.c']
 94 
 95 elif backend == 'windows'
 96-	c_args += ['-DBACKEND_WIN']
 97-	deps += [
 98-		cc.find_library('gdi32'),
 99-		cc.find_library('user32'),
100-	]
101-	backend_sources += ['source/maus_windows.c']
102+    c_args += ['-DBACKEND_WIN']
103+    deps += [
104+        cc.find_library('gdi32'),
105+        cc.find_library('user32'),
106+    ]
107+    backend_sources += ['source/maus_windows.c']
108 endif
109 
110 common = static_library(
111-	'maus_common_' + backend,
112-	common_sources,
113-	include_directories: inc,
114-	c_args: c_args,
115-	override_options: ['c_std=c89'],
116+    'maus_common_' + backend,
117+    common_sources,
118+    include_directories: inc,
119+    c_args: c_args,
120+    override_options: ['c_std=c89'],
121 )
122 
123 backend_lib = static_library(
124-	'maus_backend_' + backend,
125-	backend_sources,
126-	include_directories: inc,
127-	c_args: c_args,
128-	dependencies: deps,
129-	override_options: backend_override_options,
130+    'maus_backend_' + backend,
131+    backend_sources,
132+    include_directories: inc,
133+    c_args: c_args,
134+    dependencies: deps,
135+    override_options: backend_override_options,
136 )
137 
138 maus = static_library(
139-	lib_name,
140-	objects: [
141-		common.extract_all_objects(recursive: false),
142-		backend_lib.extract_all_objects(recursive: false),
143-	],
144-	dependencies: deps,
145+    lib_name,
146+    objects: [
147+        common.extract_all_objects(recursive: false),
148+        backend_lib.extract_all_objects(recursive: false),
149+    ],
150+    dependencies: deps,
151 )
152 
153 maus_dep = declare_dependency(
154-	include_directories: inc,
155-	link_with: maus,
156-	dependencies: deps,
157-	compile_args: c_args,
158+    include_directories: inc,
159+    link_with: maus,
160+    dependencies: deps,
161+    compile_args: c_args,
162 )
163 
164+
165+message('selected backend: ' + backend)
166+
+6, -5
 1@@ -1,7 +1,8 @@
 2 option(
 3-	'window_backend',
 4-	type: 'combo',
 5-	choices: ['x11', 'wayland', 'windows'],
 6-	value: 'x11',
 7-	description: 'Window system backend'
 8+    'window_backend',
 9+    type: 'combo',
10+    choices: ['auto', 'x11', 'wayland', 'windows'],
11+    value: 'auto',
12+    description: 'Window system backend',
13 )
14+