forked from arch1t3cht/Aegisub
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeson.build
More file actions
535 lines (457 loc) · 16.6 KB
/
Copy pathmeson.build
File metadata and controls
535 lines (457 loc) · 16.6 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
project('Aegisub', ['c', 'cpp'],
license : 'BSD-3-Clause',
meson_version : '>=1.0.0',
default_options : [
'cpp_std=c++20',
'buildtype=debugoptimized',
'luajit:lua52compat=true',
],
version : '3.4.1')
cmake = import('cmake')
if host_machine.system() == 'windows'
add_project_arguments('-DNOMINMAX', language : 'cpp')
add_project_arguments('-DUNICODE', language : 'cpp')
if not get_option('csri').disabled()
add_global_arguments('-DCSRI_NO_EXPORT', language : 'c')
endif
if get_option('fallback_nasm') or \
not find_program('nasm', required : false).found()
nasm = subproject('nasm').get_variable('nasm')
meson.override_find_program('nasm', nasm)
endif
endif
if host_machine.system() == 'windows'
powershell_exe = find_program('powershell')
version_sh = find_program('tools/version.ps1')
else
version_sh = find_program('tools/version.sh')
endif
version_inc = include_directories('.')
# Build command for version script, passing version override if provided
version_cmd = [version_sh, meson.current_build_dir(), meson.current_source_dir()]
if get_option('version') != ''
version_cmd += ['-VersionOverride', get_option('version')]
endif
version_h = custom_target('git_version.h',
command : version_cmd,
build_by_default : true,
build_always_stale : true, # has internal check whether target file will be refreshed
output : ['git_version.h'])
meson.add_dist_script(version_sh, meson.current_build_dir(), meson.current_source_dir(), 'dist')
if host_machine.system() == 'darwin' and get_option('build_osx_bundle')
prefix = meson.current_build_dir() / 'Aegisub.app' / 'Contents'
bindir = prefix / 'MacOS'
datadir = prefix / 'SharedSupport'
localedir = prefix / 'Resources'
dataroot = datadir
else
prefix = get_option('prefix')
bindir = prefix / get_option('bindir')
datadir = prefix / get_option('datadir')
localedir = prefix / get_option('localedir')
dataroot = datadir / 'aegisub'
endif
docdir = prefix / 'doc'
# MSVC sets this automatically with -MDd, but it has a different meaning on other platforms
if get_option('debug') and host_machine.system() != 'windows'
add_project_arguments('-D_DEBUG', language : 'cpp')
endif
if get_option('buildtype') == 'release'
add_project_arguments('-DNDEBUG', language : 'cpp')
endif
conf = configuration_data()
conf.set_quoted('P_BIN', bindir)
conf.set_quoted('P_DATA', dataroot)
conf.set_quoted('P_LOCALE', localedir)
if get_option('credit') != ''
conf.set_quoted('BUILD_CREDIT', get_option('credit'))
endif
if get_option('build_appimage')
conf.set('APPIMAGE_BUILD', 1)
endif
if get_option('official_release')
conf.set('AEGI_OFFICIAL_RELEASE', 1)
endif
conf.set('WITH_UPDATE_CHECKER', get_option('enable_update_checker'))
if get_option('enable_update_checker')
conf.set_quoted('UPDATE_CHECKER_SERVER', get_option('update_server'))
conf.set_quoted('UPDATE_CHECKER_BASE_URL', get_option('update_url'))
curl_disable = ['tool', 'dict', 'file', 'ftp', 'gopher', 'imap', 'ldap', 'ldaps', 'mqtt', 'pop3', 'rtmp', 'rtsp', 'smb', 'smtp', 'telnet', 'tftp']
curl_options = []
foreach opt : curl_disable
curl_options += opt + '=disabled'
endforeach
if host_machine.system() == 'windows'
curl_options += 'schannel=enabled'
elif host_machine.system() == 'darwin'
curl_options += 'secure-transport=enabled'
else
curl_options += 'openssl=enabled'
endif
endif
deps = []
deps_inc = []
dep_avail = []
add_project_arguments('-DMI_MALLOC=1', language : ['cpp', 'c'])
if get_option('enable_update_checker')
deps += dependency('libcurl', allow_fallback: true, default_options: curl_options)
endif
deps += dependency('mimalloc_static')
deps += dependency('ffnvcodec')
#deps += dependency('vpl')
if host_machine.system() == 'darwin'
add_languages('objc', 'objcpp', native : false, required : true)
elif host_machine.system() != 'windows'
conf.set('WITH_FONTCONFIG', 1)
deps += dependency('fontconfig')
endif
cxx = meson.get_compiler('cpp')
cc = meson.get_compiler('c')
deps += cc.find_library('m', required : false)
deps += cc.find_library('dl', required : false)
iconv_dep = dependency('iconv', fallback : ['iconv', 'libiconv_dep'])
deps += iconv_dep
deps += dependency('libass', version : '>=0.9.7',
fallback : ['libass', 'libass_dep'])
boost_modules = ['chrono', 'thread', 'locale', 'regex']
if not get_option('local_boost')
boost_dep = dependency('boost', version : '>=1.70.0',
modules : boost_modules + ['system'],
required : false,
static : get_option('default_library') == 'static')
endif
if get_option('local_boost') or not boost_dep.found()
boost_dep = []
boost = subproject('boost')
foreach module : boost_modules
boost_dep += boost.get_variable('boost_' + module + '_dep')
endforeach
endif
if cc.get_argument_syntax() == 'gcc'
# Work around compile error in Boost GIL, can be removed once
# https://github.com/boostorg/gil/commit/2956a0e9ef71f5c4f3163c8b8d675679e0fbaaff
# is in a boost release that's available everywhere
add_project_arguments(cc.get_supported_arguments(['-Wno-missing-template-arg-list-after-template-kw']), language: 'cpp')
endif
deps += boost_dep
if host_machine.system() == 'windows'
conf.set('BOOST_USE_WINDOWS_H', 1)
endif
deps += dependency('zlib')
wx_minver = '>=' + get_option('wx_version')
wx_dep = dependency('wxWidgets', version : wx_minver,
required : false,
modules : ['std', 'stc', 'gl'])
if wx_dep.found()
deps += wx_dep
else
build_shared = true
if get_option('default_library') == 'static'
build_shared = false
endif
build_type = 'Release'
if get_option('buildtype') == 'debug'
build_type = 'Debug'
endif
opt_var = cmake.subproject_options()
opt_var.set_override_option('cpp_std', 'c++17')
opt_var.add_cmake_defines({
'wxBUILD_INSTALL' : false,
'wxBUILD_PRECOMP' : 'OFF', # otherwise breaks project generation w/ meson
'wxBUILD_SHARED' : build_shared,
'wxUSE_WEBVIEW' : false, # breaks build on linux
'wxUSE_REGEX' : 'builtin',
'CMAKE_BUILD_TYPE' : build_type,
'wxUSE_IMAGE' : true,
'wxBUILD_MONOLITHIC' : true # otherwise breaks project generation w/ meson
})
wx = cmake.subproject('wxWidgets', options : opt_var)
deps += [
wx.dependency('wxmono'),
wx.dependency('wxregex'),
wx.dependency('wxscintilla'),
wx.dependency('wxlexilla')
]
if host_machine.system() == 'windows' or host_machine.system() == 'darwin'
deps += [
wx.dependency('wxpng'),
wx.dependency('wxjpeg')
]
endif
if host_machine.system() == 'windows'
deps += [
wx.dependency('wxzlib'),
wx.dependency('wxexpat'),
]
if cc.has_header('rpc.h')
deps += cc.find_library('rpcrt4', required : true)
else
error('Missing Windows SDK RPC Library (rpc.h / rpcrt4.lib)')
endif
if cc.has_header('commctrl.h')
deps += cc.find_library('comctl32', required : true)
else
error('Missing Windows SDK Common Controls Library (commctrl.h / comctl32.lib)')
endif
endif
endif
# ICU 数据库(子项目构建时需要,系统 ICU 自带数据则无需)
icu_data_dep = dependency('icu-data', required : false)
if icu_data_dep.found()
deps += icu_data_dep
endif
deps += dependency('icu-uc', allow_fallback : true, version : '>=4.8.1.1')
deps += dependency('icu-i18n', allow_fallback : true, version : '>=4.8.1.1')
foreach dep : [
# audio, in order of precedence
['libpulse', [], 'PulseAudio', [], []],
['alsa', [], 'ALSA', [], []],
['portaudio-2.0', [], 'PortAudio', [], []],
['openal', '>=0.0.8', 'OpenAL', [], ['OpenAL']],
# video
['ffms2', '>=2.22', 'FFMS2', ['ffms2', 'ffms2_dep'], []],
# other
['fftw3', [], 'FFTW3', [], []],
['hunspell', [], 'Hunspell', ['hunspell', 'hunspell_dep'], []],
['uchardet', [], 'uchardet', ['uchardet', 'uchardet_dep'], []],
]
optname = dep[0].split('-')[0]
if not get_option(optname).disabled()
# [provide] section is ignored if required is false;
# must provided define fallback explicitly
d = dependency(dep[0], version : dep[1], required : false, allow_fallback : true)
if not d.found() and dep[4].length() > 0 and host_machine.system() == 'darwin'
d = dependency('appleframeworks', modules : dep[4], required : false)
endif
if d.found()
deps += d
conf.set('WITH_@0@'.format(dep[0].split('-')[0].to_upper()), 1)
dep_avail += dep[2]
elif get_option(optname).enabled()
error('@0@ enabled but not found'.format(dep[2]))
endif
endif
endforeach
needs_ffmpeg = false
if get_option('bestsource').enabled()
conf.set('WITH_BESTSOURCE', 1)
deps += dependency('bestsource', version : '>=16.0',
fallback : ['bestsource', 'bestsource_dep'],
default_options : ['enable_plugin=false'])
dep_avail += 'BestSource'
needs_ffmpeg = true
endif
if needs_ffmpeg
conf.set('WITH_FFMPEG', 1)
deps += [
dependency('libavformat', default_options : ['tests=disabled']),
dependency('libavcodec', default_options : ['tests=disabled']),
dependency('libavutil', default_options : ['tests=disabled']),
dependency('libswscale', default_options : ['tests=disabled']),
]
endif
if get_option('avisynth').enabled()
conf.set('WITH_AVISYNTH', 1) # bundled separately with installer
dep_avail += 'AviSynth'
avs_opt = cmake.subproject_options()
avs_opt.add_cmake_defines({
'HEADERS_ONLY' : true
})
avs = cmake.subproject('avisynth', options : avs_opt)
deps_inc += avs.include_directories('AviSynth-Headers')
if host_machine.system() == 'windows'
deps += cc.find_library('avifil32', required : true)
endif
endif
if get_option('vapoursynth').enabled()
conf.set('WITH_VAPOURSYNTH', 1)
vs_sub = subproject('vapoursynth')
deps_inc += vs_sub.get_variable('vs_inc')
dep_avail += 'VapourSynth'
endif
if host_machine.system() == 'windows'
if not get_option('directsound').disabled()
dsound_dep = cc.find_library('dsound', required : get_option('directsound'))
winmm_dep = cc.find_library('winmm', required : get_option('directsound'))
ole32_dep = cc.find_library('ole32', required : get_option('directsound'))
have_dsound_h = cc.has_header('dsound.h')
if not have_dsound_h and get_option('directsound').enabled()
error('DirectSound enabled but dsound.h not found')
endif
dxguid_dep = cc.find_library('dxguid', required : true)
if dsound_dep.found() and winmm_dep.found() and ole32_dep.found() and dxguid_dep.found() and have_dsound_h
deps += [dsound_dep, winmm_dep, ole32_dep, dxguid_dep]
conf.set('WITH_DIRECTSOUND', 1)
dep_avail = ['DirectSound'] + dep_avail
endif
endif
if not get_option('xaudio2').disabled()
have_xaudio_h = cc.has_header('xaudio2.h')
xaudio2_dep = cc.find_library('xaudio2', required : true)
if have_xaudio_h and xaudio2_dep.found()
deps += [xaudio2_dep]
conf.set('WITH_XAUDIO2', 1)
dep_avail += 'XAudio2'
# XAudio2 needs Windows 8 or newer, so we tell meson not to define an older windows or else it can break things.
add_project_arguments('-D_WIN32_WINNT=0x0602', language : 'cpp')
else
# Windows 8 not required if XAudio2 fails to be found. revert for compat.
add_project_arguments('-D_WIN32_WINNT=0x0601', language : 'cpp')
endif
if not have_dsound_h and get_option('xaudio2').enabled()
error('xaudio2 enabled but xaudio2.h not found')
endif
else
# Windows 8 not required if XAudio2 is disabled. revert for compat.
add_project_arguments('-D_WIN32_WINNT=0x0601', language : 'cpp')
endif
endif
if host_machine.system() == 'windows' and cc.has_header('dwrite_3.h')
conf.set('HAVE_DWRITE_3', 1)
endif
if host_machine.system() == 'windows' and cc.has_header('dwrite_3.h')
conf.set('HAVE_DWRITE_3', 1)
endif
if host_machine.system() == 'darwin'
frameworks_dep = dependency('appleframeworks', modules : ['CoreText', 'CoreFoundation', 'AppKit', 'Carbon', 'IOKit', 'QuartzCore'])
deps += frameworks_dep
endif
# TODO: OSS
def_audio = get_option('default_audio_output')
if def_audio != 'auto'
if not dep_avail.contains(def_audio)
error('Default audio output "@0@" selected but not available'.format(def_audio))
endif
elif dep_avail.length() != 0
def_audio = dep_avail[0]
else
def_audio = ''
endif
conf_meson = configuration_data()
conf_meson.set('DEFAULT_PLAYER_AUDIO', def_audio)
luajit = dependency('luajit', version : '>=2.0.0', required : get_option('system_luajit'))
if luajit.found() and luajit.type_name() != 'internal'
luajit_test = cc.run('''#include <lauxlib.h>
int main(void)
{
lua_State *L = luaL_newstate();
if (!L) return 1;
// This is valid in lua 5.2, but a syntax error in 5.1
const char testprogram[] = "function foo() while true do break return end end";
return luaL_loadstring(L, testprogram) == LUA_ERRSYNTAX;
}''', dependencies : luajit)
if luajit_test.returncode() == 1
if get_option('system_luajit')
error('System luajit found but not compiled in 5.2 mode')
else
message('System luajit found but not compiled in 5.2 mode; using built-in luajit')
endif
else
deps += luajit
endif
else
message('System luajit not found; using built-in luajit')
endif
if not deps.contains(luajit)
message('Using built-in luajit')
subproject('luajit')
luajit = dependency('luajit')
assert(luajit.type_name() == 'internal', 'System luajit used instead of built-in luajit')
endif
if luajit.type_name() == 'internal'
deps += luajit
endif
subdir('vendor/luabins/src')
dep_gl = dependency('gl', required : false)
if not dep_gl.found()
if host_machine.system() == 'windows'
dep_gl = cc.find_library('opengl32', required : false)
else
dep_gl = cc.find_library('GL', required : false)
endif
if not cc.has_header('GL/glcorearb.h')
dep_gl = dependency('', required : false)
endif
endif
if not dep_gl.found()
error('OpenGL implementation not found')
endif
deps += dep_gl
if not get_option('csri').disabled() and host_machine.system() == 'windows'
conf.set('WITH_CSRI', 1)
csri_sp = subproject('csri')
deps += csri_sp.get_variable('csri_dep')
endif
acconf = configure_file(output : 'acconf.h', configuration : conf)
# 配置编译定义和顺序依赖
aegisub_order_dep = []
aegisub_defines = []
if get_option('b_pch')
aegisub_order_dep += acconf
else
foreach key : conf.keys()
if '@0@'.format(conf.get(key)) == 'true'
assert(conf.get(key) == true)
aegisub_defines += '-D@0@'.format(key)
elif '@0@'.format(conf.get(key)) != 'false'
aegisub_defines += '-D@0@=@1@'.format(key, conf.get(key))
endif
endforeach
if host_machine.system() == 'windows'
aegisub_defines += '-DWIN32_LEAN_AND_MEAN'
endif
endif
subdir('automation')
subdir('libaegisub')
subdir('packages')
subdir('po')
subdir('src')
if get_option('tests')
subdir('tests')
endif
aegisub_cpp_pch = ['src/include/agi_pre.h']
aegisub_c_pch = ['src/include/agi_pre_c.h']
link_args = []
link_depends = []
if host_machine.system() == 'windows'
manifest_file = configure_file(copy : true, input : 'src/res/Aegisub.exe.manifest', output : 'Aegisub.exe.manifest')
link_args += ['/MANIFEST:EMBED', '/MANIFESTINPUT:@0@'.format(manifest_file)]
link_depends += manifest_file
endif
configure_file(copy : true, input : 'gifski/lib/gifski.lib', output : 'gifski.lib')
configure_file(copy : true, input : 'libimagequant/lib/imagequant_sys.lib', output : 'imagequant_sys.lib')
# 创建依赖项
other_dep = declare_dependency(
include_directories : ['gifski/inc', 'libimagequant/inc'],
link_args : ['gifski.lib', 'imagequant_sys.lib', '-luserenv', '-lntdll']
)
aegisub = executable('Aegisub', aegisub_src, version_h, acconf, resrc,
link_with : [libresrc, libluabins, libaegisub],
link_args : link_args,
link_depends : link_depends,
include_directories : [libaegisub_inc, libresrc_inc, version_inc, deps_inc, include_directories(['src', 'src/include'])],
cpp_pch : aegisub_cpp_pch,
c_pch : aegisub_c_pch,
install : true,
install_dir : bindir,
dependencies : [deps, other_dep],
win_subsystem : 'windows')
# 构建时复制3D LUT文件到构建目录data/cube/,确保dev运行时可找到
# 注:run_command的CWD为源码目录,故需使用绝对路径
cube_src_dir = meson.project_source_root() / 'src' / 'cube'
cube_dst_dir = meson.project_build_root() / 'data' / 'cube'
run_command(powershell_exe, '-Command',
'New-Item -ItemType Directory -Force "' + cube_dst_dir + '" | Out-Null',
check: false)
foreach cube_file : ['PQ2SDR.cube', 'HLG2SDR.cube', 'DV2SDR.cube']
run_command(powershell_exe, '-Command',
'Copy-Item -Force "' + cube_src_dir / cube_file + '" "' + cube_dst_dir / cube_file + '"',
check: false)
endforeach
# 安装HDR/DV色彩映射所需的3D LUT文件
install_data('src/cube/PQ2SDR.cube',
install_dir : bindir / 'data' / 'cube')
install_data('src/cube/HLG2SDR.cube',
install_dir : bindir / 'data' / 'cube')
install_data('src/cube/DV2SDR.cube',
install_dir : bindir / 'data' / 'cube')