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