-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathmeson.build
More file actions
1067 lines (995 loc) · 36.6 KB
/
meson.build
File metadata and controls
1067 lines (995 loc) · 36.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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
project('nvencc', ['cpp', 'cuda'],
version: run_command('git', 'describe', '--tags', '--abbrev=0', check: true).stdout().strip(),
license: 'MIT',
meson_version: '>=0.61.0',
default_options: [
'cpp_std=c++17',
'buildtype=release',
'warning_level=1',
]
)
# ==============================================================================
# コンパイラ設定
# ==============================================================================
cpp = meson.get_compiler('cpp')
cuda = meson.get_compiler('cuda')
fs = import('fs')
source_root = meson.project_source_root()
build_root = meson.project_build_root()
# プラットフォームチェック
is_linux = host_machine.system() == 'linux'
is_x86_64 = host_machine.cpu_family() == 'x86_64'
if not is_linux
error('This meson.build is for Linux only')
endif
# ==============================================================================
# CUDA パス自動検出
# ==============================================================================
# CUDA_PATH環境変数、または /usr/local/cuda を使用
cuda_path = get_option('nvenc_cuda_dir')
if cuda_path == ''
cuda_path_env = run_command('sh', '-c', 'echo $CUDA_PATH', check: false).stdout().strip()
if cuda_path_env != ''
cuda_path = cuda_path_env
elif fs.is_dir('/usr/local/cuda')
cuda_path = '/usr/local/cuda'
else
error('CUDA not found. Set CUDA_PATH or cuda_path option.')
endif
endif
message('Using CUDA path: ' + cuda_path)
cuda_lib_dir = cuda_path / 'lib64'
cuda_bin_dir = cuda_path / 'bin'
cuda_target_lib_dir = cuda_path / 'targets' / 'x86_64-linux' / 'lib'
cuda_stub_lib_dir = cuda_target_lib_dir / 'stubs'
# ==============================================================================
# CUDAバージョン検出 & compute_xx 自動設定
# ==============================================================================
nvcc_path = cuda_bin_dir / 'nvcc'
cuda_version_result = run_command(nvcc_path, '--version', check: true)
cuda_version_output = cuda_version_result.stdout()
# "release X.Y" からバージョン抽出
cuda_ver_cmd = run_command('sh', '-c',
'echo "' + cuda_version_output + '" | grep -oP "release \\K[0-9]+\\.[0-9]+"',
check: false)
cuda_ver_str = cuda_ver_cmd.stdout().strip()
if cuda_ver_str == ''
error('Could not parse CUDA version from nvcc output')
endif
cuda_ver_parts = cuda_ver_str.split('.')
cuda_ver_major = cuda_ver_parts[0].to_int()
cuda_ver_minor = cuda_ver_parts[1].to_int()
message('Detected CUDA version: @0@.@1@'.format(cuda_ver_major, cuda_ver_minor))
if cuda_ver_major < 10
error('CUDA >= 10.0 required, but CUDA @0@.@1@ found.'.format(cuda_ver_major, cuda_ver_minor))
endif
# CUDAバージョンに応じたGPU code生成オプション
gpu_code_gen = []
# CUDA 10以下: compute_30も追加
if cuda_ver_major <= 10
gpu_code_gen += ['--generate-code', 'arch=compute_30,code=[compute_30,sm_30]']
endif
# CUDA 12以下: compute_50, compute_61追加
if cuda_ver_major <= 12
gpu_code_gen += ['--generate-code', 'arch=compute_50,code=[compute_50,sm_50]']
gpu_code_gen += ['--generate-code', 'arch=compute_61,code=[compute_61,sm_61]']
endif
# 常に: compute_75
gpu_code_gen += ['--generate-code', 'arch=compute_75,code=[compute_75,sm_75]']
# CUDA 11.1以上: compute_86追加
if (cuda_ver_major == 11 and cuda_ver_minor >= 1) or cuda_ver_major >= 12
gpu_code_gen += ['--generate-code', 'arch=compute_86,code=[compute_86,sm_86]']
endif
# CUDA 12.8以上: compute_120追加
if (cuda_ver_major == 12 and cuda_ver_minor >= 8) or cuda_ver_major >= 13
gpu_code_gen += ['--generate-code', 'arch=compute_120,code=[compute_120,sm_120]']
endif
message('GPU code generation targets: ' + ' '.join(gpu_code_gen))
# ==============================================================================
# ビルドオプション
# ==============================================================================
enable_vapoursynth = get_option('enable_vapoursynth')
enable_avisynth = get_option('enable_avisynth')
enable_libass = get_option('enable_libass')
enable_libplacebo_option = get_option('enable_libplacebo')
libplacebo_static = get_option('libplacebo_static')
enable_vmaf_option = get_option('enable_vmaf')
libvmaf_static = get_option('libvmaf_static')
enable_libvship_option = get_option('enable_libvship')
enable_vulkan_option = get_option('enable_vulkan')
# ==============================================================================
# 依存関係検出
# ==============================================================================
# 必須依存
threads_dep = dependency('threads')
dl_dep = cpp.find_library('dl', required: true)
# CUDA
cuda_dep = dependency('cuda', version: '>=10.0', required: true)
# CUDA追加ライブラリ (Driver API, NPP)
# Linux container では libcuda.so の stub が targets/.../lib/stubs に置かれるため、
# 実ドライバ(cuda-drivers)ではなく cuda-driver-dev の stub を優先して利用する。
cuda_driver_search_dirs = [cuda_stub_lib_dir, cuda_target_lib_dir, cuda_lib_dir, '/usr/lib/wsl/lib']
message('CUDA driver search dirs: ' + ' '.join(cuda_driver_search_dirs))
cuda_driver_probe = cpp.find_library('cuda', dirs: cuda_driver_search_dirs, required: true)
cuda_driver_lib_dir = ''
foreach dir : cuda_driver_search_dirs
if cuda_driver_lib_dir == '' and fs.exists(dir / 'libcuda.so')
cuda_driver_lib_dir = dir
endif
endforeach
if cuda_driver_lib_dir == ''
message('libcuda.so was resolved by the toolchain search path')
cuda_driver_dep = declare_dependency(link_args: ['-lcuda'])
else
cuda_driver_dep = declare_dependency(link_args: ['-L' + cuda_driver_lib_dir, '-lcuda'])
endif
npp_search_dirs = [cuda_target_lib_dir, cuda_lib_dir]
cpp.find_library('nppif_static', dirs: npp_search_dirs, required: true)
cpp.find_library('nppig_static', dirs: npp_search_dirs, required: true)
cpp.find_library('nppc_static', dirs: npp_search_dirs, required: true)
cpp.find_library('culibos', dirs: npp_search_dirs, required: true)
npp_lib_dir = ''
foreach dir : npp_search_dirs
if npp_lib_dir == '' and fs.exists(dir / 'libnppif_static.a') and fs.exists(dir / 'libnppig_static.a') and fs.exists(dir / 'libnppc_static.a') and fs.exists(dir / 'libculibos.a')
npp_lib_dir = dir
endif
endforeach
if npp_lib_dir == ''
message('NPP libraries were resolved by the toolchain search path')
npp_deps = declare_dependency(link_args: ['-lnppif_static', '-lnppig_static', '-lnppc_static', '-lculibos'])
else
npp_deps = declare_dependency(link_args: ['-L' + npp_lib_dir, '-lnppif_static', '-lnppig_static', '-lnppc_static', '-lculibos'])
endif
rt_dep = cpp.find_library('rt', required: true)
# FFmpeg (必須)
libavutil_dep = dependency('libavutil', required: true)
libavcodec_dep = dependency('libavcodec', required: true)
libavformat_dep = dependency('libavformat', required: true)
libavfilter_dep = dependency('libavfilter', required: true)
libavdevice_dep = dependency('libavdevice', required: true)
libswresample_dep = dependency('libswresample', required: true)
ffmpeg_deps = [
libavutil_dep,
libavcodec_dep,
libavformat_dep,
libavfilter_dep,
libavdevice_dep,
libswresample_dep,
]
# オプション依存
# ヘッダ自動取得先(ビルドディレクトリ内)
_ext_headers_dir = build_root / 'external_headers'
_vpy_fetched_inc = _ext_headers_dir / 'vapoursynth-R72' / 'include'
_avs_fetched_inc = _ext_headers_dir / 'AviSynthPlus-3.7.5' / 'avs_core' / 'include'
# VapourSynth ヘッダ自動ダウンロード用シェルスクリプト
_fetch_vpy_sh = '''
dest="$1"
[ -f "$dest/vapoursynth-R72/include/VapourSynth.h" ] && exit 0
mkdir -p "$dest"
url="https://github.com/vapoursynth/vapoursynth/archive/refs/tags/R72.tar.gz"
if command -v wget >/dev/null 2>&1; then
wget -q -O "$dest/vpy.tar.gz" "$url" || exit 1
else
curl -fsSL -o "$dest/vpy.tar.gz" "$url" || exit 1
fi
tar xf "$dest/vpy.tar.gz" -C "$dest" || exit 1
rm -f "$dest/vpy.tar.gz"
'''
# AviSynthPlus ヘッダ自動ダウンロード用シェルスクリプト
_fetch_avs_sh = '''
dest="$1"
[ -f "$dest/AviSynthPlus-3.7.5/avs_core/include/avisynth_c.h" ] && exit 0
mkdir -p "$dest"
url="https://github.com/AviSynth/AviSynthPlus/archive/refs/tags/v3.7.5.tar.gz"
if command -v wget >/dev/null 2>&1; then
wget -q -O "$dest/avs.tar.gz" "$url" || exit 1
else
curl -fsSL -o "$dest/avs.tar.gz" "$url" || exit 1
fi
tar xf "$dest/avs.tar.gz" -C "$dest" || exit 1
rm -f "$dest/avs.tar.gz"
'''
vapoursynth_compile_dep = disabler()
have_vapoursynth_headers = false
if enable_vapoursynth
vapoursynth_pkg_dep = dependency('vapoursynth', required: false)
vapoursynth_compile_dep = declare_dependency()
if vapoursynth_pkg_dep.found()
vapoursynth_compile_dep = vapoursynth_pkg_dep.partial_dependency(includes: true, compile_args: true)
endif
vapoursynth_v3_headers_code = '''
#include "VapourSynth.h"
#include "VSScript.h"
int main(void) { return 0; }
'''
have_vapoursynth_v3_headers = cpp.compiles(
vapoursynth_v3_headers_code,
dependencies: vapoursynth_compile_dep,
args: get_option('cpp_args'),
)
vapoursynth_v4_headers_code = '''
#include "VSScript4.h"
int main(void) { return 0; }
'''
have_vapoursynth_v4_headers = cpp.compiles(
vapoursynth_v4_headers_code,
dependencies: vapoursynth_compile_dep,
args: get_option('cpp_args'),
)
have_vapoursynth_headers = have_vapoursynth_v3_headers and have_vapoursynth_v4_headers
if not have_vapoursynth_headers
_fetch = run_command(
'sh', '-c', _fetch_vpy_sh, 'fetch_vpy', _ext_headers_dir,
check: false,
)
if _fetch.returncode() == 0
vapoursynth_compile_dep = declare_dependency(
compile_args: ['-I' + _vpy_fetched_inc],
)
have_vapoursynth_v3_headers = cpp.compiles(
vapoursynth_v3_headers_code,
dependencies: vapoursynth_compile_dep,
args: get_option('cpp_args'),
)
have_vapoursynth_v4_headers = cpp.compiles(
vapoursynth_v4_headers_code,
dependencies: vapoursynth_compile_dep,
args: get_option('cpp_args'),
)
have_vapoursynth_headers = have_vapoursynth_v3_headers and have_vapoursynth_v4_headers
endif
if not have_vapoursynth_headers
error('VapourSynth headers not found (require V3: VapourSynth.h/VSScript.h and V4: VSScript4.h)')
endif
endif
endif
avisynth_compile_dep = disabler()
have_avisynth_headers = false
if enable_avisynth
avisynth_pkg_dep = dependency('avisynth', required: false)
avisynth_compile_dep = declare_dependency()
if avisynth_pkg_dep.found()
avisynth_compile_dep = avisynth_pkg_dep.partial_dependency(includes: true, compile_args: true)
endif
avisynth_headers_code = '''
#include "avisynth_c.h"
int main(void) { return 0; }
'''
have_avisynth_headers = cpp.compiles(
avisynth_headers_code,
dependencies: avisynth_compile_dep,
args: get_option('cpp_args'),
)
if not have_avisynth_headers
_fetch = run_command(
'sh', '-c', _fetch_avs_sh, 'fetch_avs', _ext_headers_dir,
check: false,
)
if _fetch.returncode() == 0
avisynth_compile_dep = declare_dependency(
compile_args: ['-I' + _avs_fetched_inc],
)
have_avisynth_headers = cpp.compiles(
avisynth_headers_code,
dependencies: avisynth_compile_dep,
args: get_option('cpp_args'),
)
endif
if not have_avisynth_headers
error('AviSynth headers not found (avisynth_c.h)')
endif
endif
endif
if enable_libass
libass_dep = dependency('libass', required: true)
else
libass_dep = disabler()
endif
have_vmaf_headers = false
vmaf_headers_from_default = false
vmaf_compile_dep = declare_dependency()
vmaf_link_dep = declare_dependency()
have_vmaf_link = false
if enable_vmaf_option != 'disabled'
vmaf_headers_code = '''
#include <libvmaf/libvmaf.h>
int main(void) {
VmafConfiguration cfg = { 0 };
VmafPicture pic;
(void)cfg;
(void)pic;
return 0;
}
'''
vmaf_pkg_dep = dependency('libvmaf', required: false, static: libvmaf_static)
vmaf_pkg_libdirs = []
if vmaf_pkg_dep.found()
vmaf_pkg_compile_dep = vmaf_pkg_dep.partial_dependency(includes: true, compile_args: true)
vmaf_pkg_libdir = vmaf_pkg_dep.get_variable(pkgconfig: 'libdir', default_value: '')
if vmaf_pkg_libdir != ''
vmaf_pkg_libdirs += vmaf_pkg_libdir
endif
have_vmaf_headers = cpp.compiles(
vmaf_headers_code,
dependencies: vmaf_pkg_compile_dep,
args: get_option('cpp_args'),
)
if have_vmaf_headers
vmaf_compile_dep = vmaf_pkg_compile_dep
message('Using VMAF headers from libvmaf dependency')
endif
endif
vmaf_header_search_dirs = [
source_root / 'vmaf' / 'libvmaf' / 'include',
build_root / '..' / 'vmaf' / 'libvmaf' / 'include',
]
foreach dir : vmaf_header_search_dirs
if not have_vmaf_headers and fs.is_dir(dir) and (not libvmaf_static or not vmaf_pkg_dep.found())
vmaf_candidate_dep = declare_dependency(
compile_args: ['-I' + dir],
)
have_vmaf_headers = cpp.compiles(
vmaf_headers_code,
dependencies: vmaf_candidate_dep,
args: get_option('cpp_args'),
)
if have_vmaf_headers
vmaf_compile_dep = vmaf_candidate_dep
message('Using VMAF headers from: ' + dir)
endif
endif
endforeach
if not have_vmaf_headers and (not libvmaf_static or not vmaf_pkg_dep.found())
have_vmaf_headers = cpp.compiles(
vmaf_headers_code,
args: get_option('cpp_args'),
)
vmaf_headers_from_default = have_vmaf_headers
endif
if vmaf_headers_from_default
message('Using VMAF headers from the default include path')
endif
if libvmaf_static
vmaf_static_probe = cpp.find_library('vmaf', static: true, dirs: vmaf_pkg_libdirs, required: false)
have_vmaf_link = vmaf_static_probe.found()
if have_vmaf_link
if vmaf_pkg_dep.found()
vmaf_link_dep = vmaf_pkg_dep
else
vmaf_link_dep = declare_dependency(dependencies: vmaf_static_probe)
endif
endif
if enable_vmaf_option == 'enabled' and not have_vmaf_link
error('Static libvmaf not found')
endif
if have_vmaf_headers and not have_vmaf_link
message('Static libvmaf not found, disabling VMAF support')
have_vmaf_headers = false
vmaf_compile_dep = declare_dependency()
endif
endif
if enable_vmaf_option == 'enabled' and not have_vmaf_headers
error('VMAF headers not found (libvmaf/libvmaf.h)')
endif
endif
have_vulkan_headers = false
vulkan_compile_dep = declare_dependency()
if enable_vulkan_option != 'disabled'
vulkan_pkg_dep = dependency('vulkan', required: false)
if vulkan_pkg_dep.found()
vulkan_compile_dep = vulkan_pkg_dep.partial_dependency(includes: true, compile_args: true)
endif
vulkan_headers_code = '''
#include <vulkan/vulkan.h>
int main(void) { return VK_HEADER_VERSION; }
'''
have_vulkan_headers = cpp.compiles(
vulkan_headers_code,
dependencies: vulkan_compile_dep,
args: get_option('cpp_args'),
)
if enable_vulkan_option == 'enabled' and not have_vulkan_headers
error('Vulkan headers not found (vulkan/vulkan.h)')
endif
endif
have_libplacebo_headers = false
libplacebo_compile_dep = declare_dependency()
libplacebo_link_dep = declare_dependency()
have_libplacebo_link = false
if enable_libplacebo_option != 'disabled'
libplacebo_headers_code = '''
#include <libplacebo/dispatch.h>
#include <libplacebo/renderer.h>
#include <libplacebo/shaders.h>
int main(void) { return PL_API_VER; }
'''
libplacebo_pkg_dep = dependency('libplacebo', required: false, static: libplacebo_static)
libplacebo_pkg_libdirs = []
if libplacebo_pkg_dep.found()
libplacebo_compile_dep = libplacebo_pkg_dep.partial_dependency(includes: true, compile_args: true)
libplacebo_pkg_libdir = libplacebo_pkg_dep.get_variable(pkgconfig: 'libdir', default_value: '')
if libplacebo_pkg_libdir != ''
libplacebo_pkg_libdirs += libplacebo_pkg_libdir
endif
have_libplacebo_headers = cpp.compiles(
libplacebo_headers_code,
dependencies: libplacebo_compile_dep,
args: get_option('cpp_args'),
)
if libplacebo_static
libplacebo_static_probe = cpp.find_library('placebo', static: true, dirs: libplacebo_pkg_libdirs, required: false)
have_libplacebo_link = libplacebo_static_probe.found()
if have_libplacebo_link
libplacebo_link_dep = libplacebo_pkg_dep
endif
endif
else
have_libplacebo_headers = cpp.compiles(
libplacebo_headers_code,
args: get_option('cpp_args'),
)
endif
if libplacebo_static
if enable_libplacebo_option == 'enabled' and not have_libplacebo_link
error('Static libplacebo not found')
endif
if have_libplacebo_headers and not have_libplacebo_link
message('Static libplacebo not found, disabling libplacebo support')
have_libplacebo_headers = false
libplacebo_compile_dep = declare_dependency()
endif
endif
if enable_libplacebo_option == 'enabled' and not have_libplacebo_headers
error('libplacebo headers not found')
endif
endif
have_libvship_headers = false
libvship_compile_dep = declare_dependency()
if enable_libvship_option != 'disabled'
libvship_headers_code = '''
#include "VshipAPI.h"
int main(void) {
Vship_Version v;
(void)v;
return 0;
}
'''
# libvship はヘッダ参照だけで利用できるため、cpp_args で渡された include
# path を C++ 側で確認し、CUDA 側にはその -I を複写する。
libvship_header_search_dirs = [
source_root / '..' / 'Vship' / 'src',
build_root / '..' / 'Vship' / 'src',
build_root / '..' / '..' / 'Vship' / 'src',
]
foreach dir : libvship_header_search_dirs
if not have_libvship_headers and fs.is_dir(dir)
libvship_candidate_dep = declare_dependency(
compile_args: ['-I' + dir],
)
have_libvship_headers = cpp.compiles(
libvship_headers_code,
dependencies: libvship_candidate_dep,
args: get_option('cpp_args'),
)
if have_libvship_headers
libvship_compile_dep = libvship_candidate_dep
message('Using Vship headers from: ' + dir)
endif
endif
endforeach
if enable_libvship_option == 'enabled' and not have_libvship_headers
error('Vship headers not found (VshipAPI.h)')
endif
endif
# ==============================================================================
# libdovi / libhdr10plus (システムにあれば使う、なければビルドディレクトリ内でビルド)
# ==============================================================================
# libdovi / libhdr10plus: system優先、なければ同梱build (configure互換)
cargo_prog = find_program('cargo', required: false)
if cargo_prog.found()
cargo_home_dir = source_root / '.cargo_home'
cargo_c_check = run_command(
'env',
'CARGO_HOME=' + cargo_home_dir,
cargo_prog.full_path(),
'cinstall',
'--version',
check: false,
)
if cargo_c_check.returncode() != 0
cargo_c_install = run_command(
'env',
'CARGO_HOME=' + cargo_home_dir,
cargo_prog.full_path(),
'install',
'cargo-c',
'--locked',
check: false,
)
if cargo_c_install.returncode() != 0
error('Failed to install cargo-c (exit=' + cargo_c_install.returncode().to_string() + ')\nstdout:\n' + cargo_c_install.stdout().strip() + '\nstderr:\n' + cargo_c_install.stderr().strip())
endif
endif
endif
libdovi_dep = dependency('dovi', required: false)
if not libdovi_dep.found()
if not cargo_prog.found()
error('cargo is required to build bundled libdovi when system dovi is not available')
endif
libdovi_install_dir = build_root / 'rust_libs' / 'libdovi'
libdovi_build_result = run_command(
'env',
'CARGO_HOME=' + cargo_home_dir,
'CARGO=' + cargo_prog.full_path(),
'bash',
source_root / 'build_libdovi.sh',
libdovi_install_dir,
check: false,
)
if libdovi_build_result.returncode() != 0
error('Failed to build bundled libdovi (exit=' + libdovi_build_result.returncode().to_string() + ')\nstdout:\n' + libdovi_build_result.stdout().strip() + '\nstderr:\n' + libdovi_build_result.stderr().strip())
endif
libdovi_lib_dirs = []
if fs.is_file(libdovi_install_dir / 'lib/x86_64-linux-gnu/libdovi.a')
libdovi_lib_dirs += libdovi_install_dir / 'lib/x86_64-linux-gnu'
elif fs.is_file(libdovi_install_dir / 'lib64/libdovi.a')
libdovi_lib_dirs += libdovi_install_dir / 'lib64'
elif fs.is_file(libdovi_install_dir / 'lib/libdovi.a')
libdovi_lib_dirs += libdovi_install_dir / 'lib'
endif
if libdovi_lib_dirs.length() == 0
error('Bundled libdovi build succeeded but libdovi.a was not found')
endif
libdovi_lib = cpp.find_library('dovi', dirs: libdovi_lib_dirs, static: true, required: true)
libdovi_dep = declare_dependency(
dependencies: libdovi_lib,
compile_args: ['-I' + (libdovi_install_dir / 'include')],
)
if not cpp.compiles(
'#include <libdovi/rpu_parser.h>\nint main(void){ dovi_parse_rpu(nullptr, 0); return 0; }',
dependencies: libdovi_dep,
)
error('Bundled libdovi check failed (libdovi/rpu_parser.h)')
endif
endif
libhdr10plus_dep = dependency('hdr10plus-rs', required: false)
if not libhdr10plus_dep.found()
if not cargo_prog.found()
error('cargo is required to build bundled libhdr10plus-rs when system hdr10plus-rs is not available')
endif
libhdr10plus_install_dir = build_root / 'rust_libs' / 'libhdr10plus'
libhdr10plus_build_result = run_command(
'env',
'CARGO_HOME=' + cargo_home_dir,
'CARGO=' + cargo_prog.full_path(),
'bash',
source_root / 'build_libhdr10plus.sh',
libhdr10plus_install_dir,
check: false,
)
if libhdr10plus_build_result.returncode() != 0
error('Failed to build bundled libhdr10plus-rs (exit=' + libhdr10plus_build_result.returncode().to_string() + ')\nstdout:\n' + libhdr10plus_build_result.stdout().strip() + '\nstderr:\n' + libhdr10plus_build_result.stderr().strip())
endif
libhdr10plus_lib_dirs = []
if fs.is_file(libhdr10plus_install_dir / 'lib/x86_64-linux-gnu/libhdr10plus-rs.a')
libhdr10plus_lib_dirs += libhdr10plus_install_dir / 'lib/x86_64-linux-gnu'
elif fs.is_file(libhdr10plus_install_dir / 'lib64/libhdr10plus-rs.a')
libhdr10plus_lib_dirs += libhdr10plus_install_dir / 'lib64'
elif fs.is_file(libhdr10plus_install_dir / 'lib/libhdr10plus-rs.a')
libhdr10plus_lib_dirs += libhdr10plus_install_dir / 'lib'
endif
if libhdr10plus_lib_dirs.length() == 0
error('Bundled libhdr10plus-rs build succeeded but libhdr10plus-rs.a was not found')
endif
libhdr10plus_lib = cpp.find_library('hdr10plus-rs', dirs: libhdr10plus_lib_dirs, static: true, required: true)
libhdr10plus_dep = declare_dependency(
dependencies: libhdr10plus_lib,
compile_args: ['-I' + (libhdr10plus_install_dir / 'include')],
)
if not cpp.compiles(
'#include <libhdr10plus-rs/hdr10plus.h>\nint main(void){ hdr10plus_rs_parse_json(nullptr); return 0; }',
dependencies: libhdr10plus_dep,
)
error('Bundled libhdr10plus-rs check failed (libhdr10plus-rs/hdr10plus.h)')
endif
endif
# ==============================================================================
# FFmpeg API バージョンチェック
# ==============================================================================
conf_data = configuration_data()
# AVChannelLayout 構造体の存在確認
av_channel_layout_code = '''
#include <libavutil/channel_layout.h>
int main(void) { AVChannelLayout ch_layout; return 0; }
'''
conf_data.set10('AV_CHANNEL_LAYOUT_STRUCT_AVAIL',
cpp.compiles(av_channel_layout_code, dependencies: libavutil_dep))
# AVFrame::duration メンバーの存在確認
av_frame_duration_code = '''
#include <libavutil/frame.h>
int main(void) { AVFrame *frame; frame->duration = 0; return 0; }
'''
conf_data.set10('AV_FRAME_DURATION_AVAIL',
cpp.compiles(av_frame_duration_code, dependencies: libavutil_dep))
# AVCodecParameters::coded_side_data メンバーの存在確認
avcodec_par_side_data_code = '''
#include <libavcodec/codec_par.h>
int main(void) { AVCodecParameters *codecpar; codecpar->coded_side_data = 0; return 0; }
'''
conf_data.set10('AVCODEC_PAR_CODED_SIDE_DATA_AVAIL',
cpp.compiles(avcodec_par_side_data_code, dependencies: libavcodec_dep))
# 機能有効/無効フラグ
conf_data.set10('ENABLE_AVI_READER', false)
conf_data.set10('ENABLE_AVISYNTH_READER', enable_avisynth and have_avisynth_headers)
conf_data.set10('ENABLE_VAPOURSYNTH_READER', enable_vapoursynth and have_vapoursynth_headers)
conf_data.set10('ENABLE_AVSW_READER', true)
conf_data.set10('ENABLE_SM_READER', false)
conf_data.set10('ENABLE_LIBASS_SUBBURN', libass_dep.found())
conf_data.set10('ENABLE_VMAF', have_vmaf_headers)
conf_data.set10('ENABLE_LIBVSHIP', have_libvship_headers)
conf_data.set10('ENABLE_AVCODEC_OUT_THREAD', true)
conf_data.set10('ENABLE_CPP_REGEX', true)
conf_data.set10('ENABLE_DTL', true)
conf_data.set10('ENABLE_LIBDOVI', libdovi_dep.found())
conf_data.set10('ENABLE_LIBHDR10PLUS', libhdr10plus_dep.found())
conf_data.set10('ENABLE_VULKAN', have_vulkan_headers)
conf_data.set10('ENABLE_LIBPLACEBO', have_libplacebo_headers)
conf_data.set10('LIBPLACEBO_STATIC_LINK', have_libplacebo_headers and libplacebo_static and have_libplacebo_link)
conf_data.set10('LIBVMAF_STATIC_LINK', have_vmaf_headers and libvmaf_static and have_vmaf_link)
conf_data.set10('ENABLE_PERF_COUNTER', false)
# AVS_INTERF_VER (AviSynth)
if enable_avisynth and have_avisynth_headers
conf_data.set('AVS_INTERF_VER', 12)
else
conf_data.set('AVS_INTERF_VER', 0)
endif
# rgy_config.h 生成
configure_file(
output: 'rgy_config.h',
configuration: conf_data,
)
# rgy_rev.h 生成
rev_count = run_command('sh', '-c', 'cd "' + source_root + '" && git rev-list HEAD | wc -l', check: false).stdout().strip()
if rev_count == ''
rev_count = '0'
endif
rev_data = configuration_data()
rev_data.set_quoted('ENCODER_REV', rev_count)
rev_data.set('ENABLE_METRIC_FRAMEWORK', 0)
configure_file(
output: 'rgy_rev.h',
configuration: rev_data,
)
# ビルドディレクトリをインクルードパスの先頭に追加
# (ソースディレクトリの古いrgy_config.hより優先させるため)
# mesonの include_directories('.') はソースディレクトリを指すため、
# 明示的にビルドディレクトリを cpp_args で追加する
build_dir_include = '-I' + meson.current_build_dir()
# ==============================================================================
# 共通コンパイルフラグ
# ==============================================================================
common_cpp_args = [
build_dir_include, # ビルドディレクトリを先にインクルード
'-DLINUX',
'-DUNIX',
'-D_FILE_OFFSET_BITS=64',
'-D__USE_LARGEFILE64',
'-D__STDC_FORMAT_MACROS',
'-D__STDC_CONSTANT_MACROS',
'-DLINUX64',
'-Wno-unknown-pragmas',
'-Wno-unused',
'-Wno-missing-braces',
]
common_include_dirs = include_directories(
'.',
'NVEncSDK/Common/inc',
'NVEncCore',
'NVEncNVOFFRUC',
'NVEncNVSDKNGX',
'jitify',
'tinyxml2',
'cppcodec',
'ttmath',
'dtl',
)
# ==============================================================================
# ソースファイル
# ==============================================================================
nvencsdk_sources = files(
'NVEncSDK/Common/src/dynlink_nvcuvid.cpp',
)
nvenccore_sources = files(
'NVEncCore/CuvidDecode.cpp',
'NVEncCore/FrameQueue.cpp',
'NVEncCore/NVEncCmd.cpp',
'NVEncCore/NVEncCore.cpp',
'NVEncCore/NVEncDevice.cpp',
'NVEncCore/NVEncFilter.cpp',
'NVEncCore/NVEncFilterAfs.cpp',
'NVEncCore/NVEncFilterColorspace.cpp',
'NVEncCore/NVEncFilterCurves.cpp',
'NVEncCore/NVEncFilterCustom.cpp',
'NVEncCore/NVEncFilterDelogo.cpp',
'NVEncCore/NVEncFilterDenoiseFFT3D.cpp',
'NVEncCore/NVEncFilterDenoiseGauss.cpp',
'NVEncCore/NVEncFilterLibplacebo.cpp',
'NVEncCore/NVEncFilterNGX.cpp',
'NVEncCore/NVEncFilterNVOFFRUC.cpp',
'NVEncCore/NVEncFilterNvvfx.cpp',
'NVEncCore/NVEncFilterOverlay.cpp',
'NVEncCore/NVEncFilterPad.cpp',
'NVEncCore/NVEncFilterParam.cpp',
'NVEncCore/NVEncFilterRff.cpp',
'NVEncCore/NVEncFilterSelectEvery.cpp',
'NVEncCore/NVEncFilterSsim.cpp',
'NVEncCore/NVEncFilterSubburn.cpp',
'NVEncCore/NVEncParam.cpp',
'NVEncCore/NVEncUtil.cpp',
'NVEncCore/NVEncFilterVulkan.cpp',
'NVEncCore/cl_func.cpp',
'NVEncCore/convert_csp.cpp',
'NVEncCore/cpu_info.cpp',
'NVEncCore/gpu_info.cpp',
'NVEncCore/gpuz_info.cpp',
'NVEncCore/logo.cpp',
'NVEncCore/rgy_aspect_ratio.cpp',
'NVEncCore/rgy_avlog.cpp',
'NVEncCore/rgy_avutil.cpp',
'NVEncCore/rgy_bitstream.cpp',
'NVEncCore/rgy_bitstream_aac.cpp',
'NVEncCore/rgy_chapter.cpp',
'NVEncCore/rgy_cmd.cpp',
'NVEncCore/rgy_codepage.cpp',
'NVEncCore/rgy_def.cpp',
'NVEncCore/rgy_device.cpp',
'NVEncCore/rgy_device_info_cache.cpp',
'NVEncCore/rgy_device_info_cache_nvenc.cpp',
'NVEncCore/rgy_device_info_wmi.cpp',
'NVEncCore/rgy_device_usage.cpp',
'NVEncCore/rgy_device_vulkan.cpp',
'NVEncCore/rgy_env.cpp',
'NVEncCore/rgy_err.cpp',
'NVEncCore/rgy_event.cpp',
'NVEncCore/rgy_faw.cpp',
'NVEncCore/rgy_filesystem.cpp',
'NVEncCore/rgy_filter.cpp',
'NVEncCore/rgy_frame.cpp',
'NVEncCore/rgy_frame_info.cpp',
'NVEncCore/rgy_hdr10plus.cpp',
'NVEncCore/rgy_ini.cpp',
'NVEncCore/rgy_input.cpp',
'NVEncCore/rgy_input_avcodec.cpp',
'NVEncCore/rgy_input_avi.cpp',
'NVEncCore/rgy_input_avs.cpp',
'NVEncCore/rgy_input_raw.cpp',
'NVEncCore/rgy_input_sm.cpp',
'NVEncCore/rgy_input_vpy.cpp',
'NVEncCore/rgy_language.cpp',
'NVEncCore/rgy_level.cpp',
'NVEncCore/rgy_level_av1.cpp',
'NVEncCore/rgy_level_h264.cpp',
'NVEncCore/rgy_level_hevc.cpp',
'NVEncCore/rgy_libplacebo.cpp',
'NVEncCore/rgy_libvmaf.cpp',
'NVEncCore/rgy_libvship.cpp',
'NVEncCore/rgy_log.cpp',
'NVEncCore/rgy_memmem.cpp',
'NVEncCore/rgy_nvrtc.cpp',
'NVEncCore/rgy_output.cpp',
'NVEncCore/rgy_output_avcodec.cpp',
'NVEncCore/rgy_perf_counter.cpp',
'NVEncCore/rgy_parallel_enc.cpp',
'NVEncCore/rgy_perf_monitor.cpp',
'NVEncCore/rgy_pipe.cpp',
'NVEncCore/rgy_pipe_linux.cpp',
'NVEncCore/rgy_prm.cpp',
'NVEncCore/rgy_resource.cpp',
'NVEncCore/rgy_simd.cpp',
'NVEncCore/rgy_status.cpp',
'NVEncCore/rgy_thread_affinity.cpp',
'NVEncCore/rgy_timecode.cpp',
'NVEncCore/rgy_util.cpp',
'NVEncCore/rgy_vapoursynth_wrapper.cpp',
'NVEncCore/rgy_vapoursynth_wrapper_v3.cpp',
'NVEncCore/rgy_vapoursynth_wrapper_v4.cpp',
'NVEncCore/rgy_version.cpp',
'NVEncCore/rgy_vulkan.cpp',
'NVEncCore/rgy_wav_parser.cpp',
)
# SIMD最適化ソース (個別フラグが必要)
# これらは static_library で個別にビルドしてリンク
tinyxml2_sources = files(
'tinyxml2/tinyxml2.cpp',
)
nvencc_sources = files(
'NVEncC/NVEncC.cpp',
)
# CUDAソース
cuda_sources = files(
'NVEncCore/NVEncFilterAfsAnalyze.cu',
'NVEncCore/NVEncFilterAfsFilter.cu',
'NVEncCore/NVEncFilterAfsMerge.cu',
'NVEncCore/NVEncFilterAfsSynthesize.cu',
'NVEncCore/NVEncFilterConvolution3d.cu',
'NVEncCore/NVEncFilterCrop.cu',
'NVEncCore/NVEncFilterCurves.cu',
'NVEncCore/NVEncFilterDeband.cu',
'NVEncCore/NVEncFilterDecimate.cu',
'NVEncCore/NVEncFilterDecomb.cu',
'NVEncCore/NVEncFilterDelogo.cu',
'NVEncCore/NVEncFilterDenoiseDct.cu',
'NVEncCore/NVEncFilterDenoiseFFT3D8FP16.cu',
'NVEncCore/NVEncFilterDenoiseFFT3D8FP32.cu',
'NVEncCore/NVEncFilterDenoiseFFT3D16FP16.cu',
'NVEncCore/NVEncFilterDenoiseFFT3D16FP32.cu',
'NVEncCore/NVEncFilterDenoiseKnn.cu',
'NVEncCore/NVEncFilterDenoiseNLMeans.cu',
'NVEncCore/NVEncFilterDenoisePmd.cu',
'NVEncCore/NVEncFilterEdgelevel.cu',
'NVEncCore/NVEncFilterMsharpen.cu',
'NVEncCore/NVEncFilterMpdecimate.cu',
'NVEncCore/NVEncFilterNnedi.cu',
'NVEncCore/NVEncFilterOverlay.cu',
'NVEncCore/NVEncFilterResize.cu',
'NVEncCore/NVEncFilterSmooth.cu',
'NVEncCore/NVEncFilterMsmooth.cu',
'NVEncCore/NVEncFilterSsim.cu',
'NVEncCore/NVEncFilterSubburn.cu',
'NVEncCore/NVEncFilterTransform.cu',
'NVEncCore/NVEncFilterTweak.cu',
'NVEncCore/NVEncFilterUnsharp.cu',
'NVEncCore/NVEncFilterWarpsharp.cu',
'NVEncCore/NVEncFilterYadif.cu',
)
# ==============================================================================
# SIMD専用ライブラリ (個別コンパイルフラグ)
# ==============================================================================
simd_sse2_lib = static_library('simd_sse2',
'NVEncCore/convert_csp_sse2.cpp',
cpp_args: common_cpp_args + ['-msse2'],
include_directories: common_include_dirs,
)
simd_ssse3_lib = static_library('simd_ssse3',
'NVEncCore/convert_csp_ssse3.cpp',
cpp_args: common_cpp_args + ['-mssse3'],
include_directories: common_include_dirs,
)
simd_sse41_lib = static_library('simd_sse41',
'NVEncCore/convert_csp_sse41.cpp',
cpp_args: common_cpp_args + ['-msse4.1'],
include_directories: common_include_dirs,
)
simd_avx_lib = static_library('simd_avx',
'NVEncCore/convert_csp_avx.cpp',
cpp_args: common_cpp_args + ['-mavx', '-mpopcnt'],
include_directories: common_include_dirs,
)
simd_avx2_lib = static_library('simd_avx2',
[
'NVEncCore/convert_csp_avx2.cpp',
'NVEncCore/rgy_bitstream_avx2.cpp',
'NVEncCore/rgy_faw_avx2.cpp',
'NVEncCore/rgy_memmem_avx2.cpp',
],
cpp_args: common_cpp_args + ['-mavx2', '-mfma', '-mpopcnt', '-mbmi', '-mbmi2'],
include_directories: common_include_dirs,
)
simd_avx512_lib = static_library('simd_avx512',
[
'NVEncCore/rgy_bitstream_avx512bw.cpp',
'NVEncCore/rgy_faw_avx512bw.cpp',
'NVEncCore/rgy_memmem_avx512bw.cpp',
],
cpp_args: common_cpp_args + ['-mavx512f', '-mavx512bw', '-mpopcnt', '-mbmi', '-mbmi2'],
include_directories: common_include_dirs,
)
simd_libs = [
simd_sse2_lib,
simd_ssse3_lib,
simd_sse41_lib,
simd_avx_lib,
simd_avx2_lib,
simd_avx512_lib,
]
# ==============================================================================
# CUDA コンパイルフラグ (バージョンに応じて自動設定)
# ==============================================================================
cuda_args = gpu_code_gen + [
'-Wno-deprecated-gpu-targets',
'--cudart=static',
'-std=c++17',
]
cuda_include_args = []
foreach arg : get_option('cpp_args')
if arg.startswith('-I')
cuda_include_args += [arg]
endif
endforeach
cuda_args += cuda_include_args
# ==============================================================================
# 依存関係まとめ
# ==============================================================================
all_deps = [
threads_dep,
dl_dep,
cuda_dep,
cuda_driver_dep,
npp_deps,
rt_dep,
] + ffmpeg_deps
if vapoursynth_compile_dep.found()
all_deps += vapoursynth_compile_dep
endif
if avisynth_compile_dep.found()
all_deps += avisynth_compile_dep
endif
if libass_dep.found()
all_deps += libass_dep
endif
if have_libplacebo_headers
all_deps += libplacebo_compile_dep
endif
if have_libplacebo_link