-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeson.build
More file actions
361 lines (316 loc) · 11.8 KB
/
meson.build
File metadata and controls
361 lines (316 loc) · 11.8 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# ==============================================================================
# Haiku Native Meson Template
# Analogous to the Haiku Generic Makefile v2.6
# ==============================================================================
# Version is read from the .rdef at configure time (see bottom of file).
# Set a fallback here in case no .rdef is present yet.
project('Origami', 'cpp',
version : '0.0.1',
default_options : [
'cpp_std=c++20',
'warning_level=2', # 0=none, 1=default, 2=all (→ WARNINGS)
'optimization=2', # 0=none, 1=some, 2=full (→ OPTIMIZE)
'debug=false', # true → DEBUGGER := TRUE
]
)
# ------------------------------------------------------------------------------
# Binary type — comment in exactly one block
# TYPE = APP | SHARED | STATIC
# ------------------------------------------------------------------------------
bin_type = 'APP' # change to 'SHARED' or 'STATIC' as needed
# Binary name defaults to the project name — override here if needed.
app_name = meson.project_name()
# ------------------------------------------------------------------------------
# MIME signature (needed for localization / resources)
# APP_MIME_SIG
# ------------------------------------------------------------------------------
app_mime_sig = 'application/x-vnd.senlabs-origami'
# ------------------------------------------------------------------------------
# Source file discovery (replaces explicit SRCS list)
# Meson has no built-in glob, so we use a small Python helper.
# Add or adjust the glob patterns to taste.
# ------------------------------------------------------------------------------
fs = import('fs')
srcs = run_command(
'python3', '-c',
'''
import glob, sys
patterns = [
"src/**/*.cpp",
"src/**/*.c",
"src/*.cpp",
"src/*.c",
]
files = []
for p in patterns:
files += glob.glob(p, recursive=True)
print("\\n".join(sorted(set(files))))
''',
check : true
).stdout().strip().split('\n')
# Filter out empty strings that can appear when no files match
srcs = srcs[0] != '' ? srcs : []
# ------------------------------------------------------------------------------
# Haiku path discovery via findpaths
# -e: only return paths that actually exist on this system/installation.
#
# findpaths -e returns a subset of, e.g.:
# /boot/home/config/non-packaged/develop/headers
# /boot/home/config/develop/headers
# /boot/system/non-packaged/develop/headers
# /boot/system/develop/headers
# ------------------------------------------------------------------------------
_haiku_inc_dirs = []
_haiku_lib_dirs = []
_haiku_pkgc_dirs = []
if host_machine.system() == 'haiku'
_fp_headers = run_command('findpaths', '-e', 'B_FIND_PATH_HEADERS_DIRECTORY', check: false)
_fp_libs = run_command('findpaths', '-e', 'B_FIND_PATH_LIB_DIRECTORY', check: false)
_fp_data = run_command('findpaths', '-e', 'B_FIND_PATH_DATA_DIRECTORY', check: false)
foreach p : _fp_headers.stdout().strip().split('\n')
if p != ''
_haiku_inc_dirs += p
endif
endforeach
foreach p : _fp_libs.stdout().strip().split('\n')
if p != ''
_haiku_lib_dirs += p
_haiku_pkgc_dirs += p / 'pkgconfig' # <libdir>/pkgconfig is the convention
endif
endforeach
message('Haiku header roots: ' + ', '.join(_haiku_inc_dirs))
message('Haiku library roots: ' + ', '.join(_haiku_lib_dirs))
message('Haiku pkg-config dirs: ' + ', '.join(_haiku_pkgc_dirs))
endif
# ------------------------------------------------------------------------------
# Include paths
# SYSTEM_INCLUDE_PATHS / LOCAL_INCLUDE_PATHS
# ------------------------------------------------------------------------------
local_inc = include_directories(
'src',
'include',
# add more local dirs here
)
# System-wide Haiku include roots
haiku_inc = include_directories(_haiku_inc_dirs)
# ------------------------------------------------------------------------------
# Libraries
# LIBS / LIBPATHS
#
# pkg-config: Meson only searches standard system paths by default.
# On Haiku we must point it at the pkgconfig dirs we discovered above.
# The cleanest way is the pkg_config_path keyword (Meson ≥ 0.59).
# ------------------------------------------------------------------------------
cc = meson.get_compiler('cpp')
# pkg-config based dependencies
# Meson 1.10 does not support the pkg_config_path keyword.
# Instead we set PKG_CONFIG_PATH via the environment before meson setup:
#
# PKG_CONFIG_PATH=$(findpaths -e -p pkgconfig B_FIND_PATH_LIB_DIRECTORY | tr '\n' ':') \
# meson setup build
#
# Alternatively, add this to your ~/.profile on Haiku:
# export PKG_CONFIG_PATH=/boot/system/non-packaged/lib/pkgconfig:/boot/system/lib/pkgconfig
#
deps = [
dependency('plutobook', required: true),
dependency('cairo', required: false),
]
# Haiku system libs (not in pkg-config, found by name in the lib roots)
deps += cc.find_library('be', dirs: _haiku_lib_dirs, required: true)
# Add more Haiku libs as needed, e.g.:
# deps += cc.find_library('tracker', dirs: _haiku_lib_dirs, required: false)
# deps += cc.find_library('media', dirs: _haiku_lib_dirs, required: false)
# deps += cc.find_library('network', dirs: _haiku_lib_dirs, required: false)
# deps += cc.find_library('locale', dirs: _haiku_lib_dirs, required: false)
# Extra compiler flags (→ COMPILER_FLAGS / DEFINES)
extra_c_args = [
# '-DDEBUG=1',
# '-DSOME_FEATURE',
]
# ------------------------------------------------------------------------------
# Resource handling
# Haiku resources are compiled from .rdef files with the "rc" tool,
# then linked via xres. We wire both steps up as custom targets.
#
# RDEFS / RSRCS
# ------------------------------------------------------------------------------
rdef_files = files(
# 'resources/app.rdef',
)
rsrc_files = files(
# 'resources/app.rsrc',
)
# Compile each .rdef → .rsrc via the "rc" resource compiler
compiled_rsrcs = []
foreach rdef : rdef_files
rsrc_name = fs.stem(rdef) + '.rsrc'
compiled_rsrcs += custom_target(rsrc_name,
input : rdef,
output : rsrc_name,
command : ['rc', '-o', '@OUTPUT@', '@INPUT@'],
)
endforeach
all_rsrcs = compiled_rsrcs + rsrc_files
# ------------------------------------------------------------------------------
# Localization (→ LOCALES)
# Uses Haiku's catkey / linkcatkeys toolchain.
# List the language codes you want to support (always include 'en').
# ------------------------------------------------------------------------------
locales = [
'en',
# 'de',
# 'fr',
]
# ------------------------------------------------------------------------------
# Build the binary
# ------------------------------------------------------------------------------
if bin_type == 'APP'
exe = executable(app_name,
sources : srcs,
include_directories : [local_inc, haiku_inc],
dependencies : deps,
c_args : extra_c_args,
cpp_args : extra_c_args,
install : true,
install_dir : get_option('bindir'),
)
# Attach resources with xres after linking
if all_rsrcs.length() > 0
xres_inputs = [exe]
foreach r : all_rsrcs
xres_inputs += r
endforeach
run_target('attach-resources',
command : ['xres', '-o', exe.full_path()] + all_rsrcs,
depends : [exe] + all_rsrcs,
)
endif
elif bin_type == 'SHARED'
shared_library(app_name,
sources : srcs,
include_directories : [local_inc, haiku_inc],
dependencies : deps,
c_args : extra_c_args,
cpp_args : extra_c_args,
install : true,
)
elif bin_type == 'STATIC'
static_library(app_name,
sources : srcs,
include_directories : [local_inc, haiku_inc],
dependencies : deps,
c_args : extra_c_args,
cpp_args : extra_c_args,
install : true,
)
endif
# ------------------------------------------------------------------------------
# Localization targets (→ LOCALES)
# "meson compile catkeys" → regenerate locales/en.catkeys
# "meson compile catalogs" → compile all .catkeys → .catalog
#
# Entirely optional — if no locales/ dir or no .catkeys files exist the
# build proceeds normally with English strings built in.
# ------------------------------------------------------------------------------
fs = import('fs')
if locales.length() > 0
# "meson compile catkeys" — scan sources, write en.catkeys template.
# Always available so you can bootstrap the locales/ dir from scratch.
# output must be a plain filename (no path separators allowed by Meson).
# The cp afterwards puts it where translators expect it in the source tree.
custom_target('catkeys',
output : 'en.catkeys',
command : [
'sh', '-c',
'mkdir -p "@SOURCE_ROOT@/locales" && ' +
'collectcatkeys -s "@0@" -o "@OUTPUT@" @1@ && ' +
'cp "@OUTPUT@" "@SOURCE_ROOT@/locales/en.catkeys"'
.format(app_mime_sig, ' '.join(srcs)),
],
build_by_default : false,
)
# "meson compile catalog-<lang>" — compile .catkeys → .catalog.
# Only registered for languages whose .catkeys file already exists.
foreach lang : locales
catkeys_file = meson.project_source_root() / 'locales' / lang + '.catkeys'
if fs.exists(catkeys_file)
custom_target('catalog-' + lang,
input : catkeys_file,
output : lang + '.catalog',
command : [
'linkcatkeys',
'-o', '@OUTPUT@',
'-s', app_mime_sig,
'-l', lang,
'@INPUT@',
],
install : true,
install_dir : 'data/locale/catalogs' / app_mime_sig,
build_by_default : false,
)
else
message('Skipping catalog for "' + lang + '" — locales/' + lang + '.catkeys not found.')
endif
endforeach
endif
# ------------------------------------------------------------------------------
# Version stamping (→ APP_VERSION)
# Parsed directly from the .rdef at configure time — no duplication.
#
# Expects a "app_version" resource block in the .rdef, e.g.:
#
# resource app_version {
# "major" = 1,
# "middle" = 2,
# "minor" = 0,
# "variety" = 0, // 0=d 1=a 2=b 4=rc 8=final
# "internal" = 0,
# "short" = "1.2.0",
# "long" = "1.2.0 © 2025 YourName"
# };
# ------------------------------------------------------------------------------
if rdef_files.length() > 0
# The parser lives in a separate file to avoid conflicts between
# Meson's own ''' multiline strings and Python's ''' syntax.
_ver = run_command(
'python3',
meson.project_source_root() / 'parse_rdef_version.py',
files(rdef_files[0]),
check : false,
)
if _ver.returncode() == 0
_v = _ver.stdout().strip().split('\n')
_v_major = _v[0]
_v_middle = _v[1]
_v_minor = _v[2]
_variety = _v[3]
_internal = _v[4]
_v_short = _v[5]
_v_long = _v[6]
# Wire setversion as a post-build step on the executable
if bin_type == 'APP'
meson.add_install_script(
'setversion', exe.full_path(),
'-app', _v_major, _v_middle, _v_minor, _variety, _internal,
'-short', _v_short,
'-long', _v_long,
)
endif
message('Version from rdef: ' + _v_short + ' (' + _v_long + ')')
else
warning('Could not parse version from rdef — skipping setversion.')
endif
endif
# ------------------------------------------------------------------------------
# Summary
# ------------------------------------------------------------------------------
summary({
'Binary' : app_name,
'Type' : bin_type,
'Version' : meson.project_version(),
'MIME sig' : app_mime_sig,
'C++ std' : get_option('cpp_std'),
'Optimize' : get_option('optimization'),
'Debug' : get_option('debug'),
}, section: 'Build configured successfully')