1subdir('androidmedia')
2subdir('applemedia')
3subdir('bluez')
4subdir('d3dvideosink')
5subdir('decklink')
6subdir('directsound')
7#subdir('dshowdecwrapper')
8#subdir('dshowsrcwrapper')
9#subdir('dshowvideosink')
10subdir('dvb')
11subdir('fbdev')
12subdir('ipcpipeline')
13subdir('kms')
14subdir('msdk')
15subdir('opensles')
16subdir('shm')
17subdir('tinyalsa')
18subdir('uvch264')
19subdir('vdpau')
20subdir('wasapi')
21subdir('winks')
22subdir('winscreencap')
23
24# CUDA dependency
25cuda_dep = dependency('', required : false)
26cudart_dep = dependency('', required : false)
27cuda_libdir = ''
28cuda_incdir = ''
29
30cuda_versions = [
31    '10.1',
32    '10.0',
33    '9.2',
34    '9.1',
35    '9.0',
36    '8.0',
37    '7.5',
38    '7.0',
39    '6.5',
40  ]
41cuda_ver = ''
42
43# FIXME: use break syntax when we use meson >= '0.49'
44foreach v : cuda_versions
45  if cuda_ver == ''
46    cuda_dep = dependency('cuda-' + v, required: false)
47    cudart_dep = dependency('cudart-' + v, required: false)
48    if cuda_dep.found() and cudart_dep.found()
49      cuda_ver = v
50    endif
51  endif
52endforeach
53
54if cuda_dep.found()
55  cuda_header_found = cc.has_header('cuda.h', dependencies: cuda_dep)
56  cuda_lib_found = cc.has_function('cuInit', dependencies: cuda_dep)
57  if not cuda_header_found or not cuda_lib_found
58    message ('Missing required header and/or function in cuda dependency')
59    cuda_dep = dependency('', required : false)
60  endif
61endif
62
63if cudart_dep.found()
64  cudart_header_found = cc.has_header('cuda_runtime_api.h', dependencies: cudart_dep)
65  cudart_lib_found = cc.has_function('cudaGetErrorString', dependencies: cudart_dep)
66  if not cudart_header_found or not cudart_lib_found
67    message ('Missing required header and/or function in cudart dependency')
68    cudart_dep = dependency('', required : false)
69  endif
70endif
71
72if not cuda_dep.found() or not cudart_dep.found()
73  cuda_root = run_command(python3, '-c', 'import os; print(os.environ.get("CUDA_PATH"))').stdout().strip()
74  if cuda_root != '' and cuda_root != 'None'
75    if host_machine.system() == 'windows'
76      arc = ''
77      if build_machine.cpu_family() == 'x86_64'
78        arc = 'x64'
79      else
80        arc = 'Win32'
81      endif
82      cuda_libdir = join_paths (cuda_root, 'lib', arc)
83    else
84      cuda_libdir = [join_paths (cuda_root, 'lib'), join_paths (cuda_root, 'lib', 'stubs'),
85                     join_paths (cuda_root, 'lib64'), join_paths (cuda_root, 'lib64', 'stubs')]
86    endif
87    cuda_incdir = join_paths (cuda_root, 'include')
88    cuda_lib = cc.find_library('cuda', dirs: cuda_libdir, required: false)
89    cudart_lib = cc.find_library('cudart', dirs: cuda_libdir, required: false)
90
91    if cuda_lib.found()
92      cuda_header_found = cc.has_header('cuda.h', args: '-I' + cuda_incdir)
93      cuda_lib_found = cc.has_function('cuInit', dependencies: cuda_lib)
94      if cuda_header_found and cuda_lib_found
95        cuda_dep = declare_dependency(include_directories: include_directories(cuda_incdir),
96                                      dependencies: cuda_lib)
97      endif
98    endif
99
100    if cudart_lib.found()
101      cudart_header_found = cc.has_header('cuda_runtime_api.h', args: '-I' + cuda_incdir)
102      cudart_lib_found = cc.has_function('cudaGetErrorString', dependencies: cudart_lib)
103      if cudart_header_found and cudart_lib_found
104        cudart_dep = declare_dependency(dependencies: cudart_lib)
105      endif
106    endif
107
108  endif
109endif
110
111if cuda_dep.found() and cudart_dep.found()
112  subdir('nvdec')
113  subdir('nvenc')
114elif get_option('nvdec').enabled()
115  error('The nvdec plugin was enabled explicitly, but required CUDA dependencies were not found.')
116elif get_option('nvenc').enabled()
117  error('The nvenc plugin was enabled explicitly, but required CUDA dependencies were not found.')
118endif
119