8b3268ef669135fb1575178798f290802db58968
[platform/upstream/gstreamer.git] / gst-libs / gst / vulkan / meson.build
1 if get_option('vulkan').disabled()
2   gstvulkan_dep = dependency('', required: false)
3   subdir_done()
4 endif
5
6 vulkan_sources = [
7   'gstvkbuffermemory.c',
8   'gstvkbufferpool.c',
9   'gstvkcommandbuffer.c',
10   'gstvkcommandpool.c',
11   'gstvkdescriptorcache.c',
12   'gstvkdescriptorset.c',
13   'gstvkdescriptorpool.c',
14   'gstvkdevice.c',
15   'gstvkdebug.c',
16   'gstvkdisplay.c',
17   'gstvkerror.c',
18   'gstvkfence.c',
19   'gstvkformat.c',
20   'gstvkhandle.c',
21   'gstvkhandlepool.c',
22   'gstvkimagememory.c',
23   'gstvkimagebufferpool.c',
24   'gstvkimageview.c',
25   'gstvkinstance.c',
26   'gstvkmemory.c',
27   'gstvkphysicaldevice.c',
28   'gstvkqueue.c',
29   'gstvkswapper.c',
30   'gstvktrash.c',
31   'gstvkvideofilter.c',
32   'gstvkutils.c',
33   'gstvkwindow.c',
34 ]
35
36 vulkan_headers = [
37   'gstvkapi.h',
38   'gstvkbarrier.h',
39   'gstvkbuffermemory.h',
40   'gstvkbufferpool.h',
41   'gstvkcommandbuffer.h',
42   'gstvkcommandpool.h',
43   'gstvkdescriptorcache.h',
44   'gstvkdescriptorset.h',
45   'gstvkdescriptorpool.h',
46   'gstvkdebug.h',
47   'gstvkdevice.h',
48   'gstvkdisplay.h',
49   'gstvkerror.h',
50   'gstvkfence.h',
51   'gstvkformat.h',
52   'gstvkhandle.h',
53   'gstvkhandlepool.h',
54   'gstvkimagememory.h',
55   'gstvkimagebufferpool.h',
56   'gstvkimageview.h',
57   'gstvkinstance.h',
58   'gstvkmemory.h',
59   'gstvkphysicaldevice.h',
60   'gstvkqueue.h',
61   'gstvkswapper.h',
62   'gstvktrash.h',
63   'gstvkutils.h',
64   'gstvkvideofilter.h',
65   'gstvkwindow.h',
66   'vulkan-prelude.h',
67   'vulkan_fwd.h',
68   'vulkan.h',
69 ]
70
71 vulkan_xcb_headers = []
72 vulkan_wayland_headers = []
73
74 vulkan_windowing = false
75 vulkan_objc_args = []
76 vulkan_defines = []
77 optional_deps = []
78 has_vulkan_header = false
79 vulkan_dep = dependency('', required: false)
80 vulkan_inc_dir = ''
81
82 vulkan_conf = configuration_data()
83 vulkan_conf_options = [
84     'GST_VULKAN_HAVE_WINDOW_XCB',
85     'GST_VULKAN_HAVE_WINDOW_WAYLAND',
86     'GST_VULKAN_HAVE_WINDOW_COCOA',
87     'GST_VULKAN_HAVE_WINDOW_IOS',
88     'GST_VULKAN_HAVE_WINDOW_WIN32',
89     'GST_VULKAN_HAVE_WINDOW_ANDROID',
90 ]
91
92 foreach option : vulkan_conf_options
93   vulkan_conf.set10(option, false)
94 endforeach
95
96 if host_system == 'ios'
97   vulkan_dep = cc.find_library('MoltenVK', required : get_option('vulkan'))
98 elif host_system == 'windows'
99   vulkan_root = run_command(python3, '-c', 'import os; print(os.environ.get("VK_SDK_PATH"))').stdout().strip()
100   if vulkan_root != '' and vulkan_root != 'None'
101     vulkan_lib_dir = ''
102     if build_machine.cpu_family() == 'x86_64'
103       vulkan_lib_dir = join_paths(vulkan_root, 'Lib')
104     else
105       vulkan_lib_dir = join_paths(vulkan_root, 'Lib32')
106     endif
107
108     vulkan_lib = cc.find_library('vulkan-1', dirs: vulkan_lib_dir,
109                                  required : get_option('vulkan'))
110
111     vulkan_inc_dir = join_paths(vulkan_root, 'Include')
112     has_vulkan_header = cc.has_header('vulkan/vulkan_core.h',
113                                       args: '-I' + vulkan_inc_dir)
114
115     if vulkan_lib.found() and has_vulkan_header
116       vulkan_dep = declare_dependency(include_directories: include_directories(vulkan_inc_dir),
117                                       dependencies: vulkan_lib)
118     endif
119   endif
120 else
121   vulkan_dep = dependency('vulkan', method: 'pkg-config', required : false)
122   if not vulkan_dep.found()
123     vulkan_dep = cc.find_library('vulkan', required : false)
124   endif
125 endif
126
127 if host_system != 'windows'
128   has_vulkan_header = cc.has_header('vulkan/vulkan_core.h')
129 endif
130
131 if not has_vulkan_header and get_option('vulkan').enabled()
132   error('vulkan plugin enabled, but vulkan.h not found')
133 endif
134 if not vulkan_dep.found() and get_option('vulkan').enabled()
135   error('vulkan plugin enabled, but could not find vulkan library')
136 endif
137
138 xcb_dep = dependency('xcb', version : '>=1.10', required : get_option('x11'))
139 if xcb_dep.found() and cc.has_header('vulkan/vulkan_xcb.h', dependencies : vulkan_dep)
140   vulkan_sources += [
141     'xcb/gstvkdisplay_xcb.c',
142     'xcb/gstvkwindow_xcb.c',
143     'xcb/xcb_event_source.c',
144   ]
145   vulkan_xcb_headers += [
146     'xcb/gstvkdisplay_xcb.h'
147   ]
148
149   optional_deps += xcb_dep
150   vulkan_windowing = true
151   vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_XCB', 1)
152   endif
153
154 wayland_client_dep = dependency('wayland-client', version : '>=1.4', required : get_option('wayland'))
155 if wayland_client_dep.found() and cc.has_header('vulkan/vulkan_wayland.h', dependencies : vulkan_dep)
156   vulkan_sources += [
157     'wayland/gstvkdisplay_wayland.c',
158     'wayland/gstvkwindow_wayland.c',
159     'wayland/wayland_event_source.c',
160   ]
161   vulkan_wayland_headers += [
162     'wayland/gstvkdisplay_wayland.h'
163   ]
164
165   optional_deps += wayland_client_dep
166   vulkan_windowing = true
167   vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_WAYLAND', 1)
168 endif
169
170 if ['darwin', 'ios'].contains(host_system)
171   objc = meson.get_compiler('objc')
172   if not objc.has_argument('-fobjc-arc')
173     error('ARC is required for building')
174   endif
175
176   vulkan_objc_args += ['-fobjc-arc']
177
178   foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : get_option('vulkan'))
179   quartzcore_dep = dependency('appleframeworks', modules : ['QuartzCore'], required : get_option('vulkan'))
180   corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : get_option('vulkan'))
181   if foundation_dep.found() and quartzcore_dep.found() and corefoundation_dep.found()
182     optional_deps += [foundation_dep, corefoundation_dep, quartzcore_dep]
183   endif
184 endif
185
186 if host_system == 'darwin'
187   cocoa_dep = dependency('appleframeworks', modules : ['Cocoa'], required : get_option('vulkan'))
188
189   if cocoa_dep.found() and cc.has_header('vulkan/vulkan_macos.h', dependencies : vulkan_dep)
190     vulkan_sources += [
191       'cocoa/gstvkdisplay_cocoa.m',
192       'cocoa/gstvkwindow_cocoa.m',
193     ]
194     optional_deps += [cocoa_dep]
195     vulkan_windowing = true
196     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_COCOA', 1)
197   endif
198 endif
199
200 if host_system == 'ios'
201   uikit_dep = dependency('appleframeworks', modules : ['UIKit'], required : get_option('vulkan'))
202
203   if uikit_dep.found() and cc.has_header('vulkan/vulkan_ios.h', dependencies : vulkan_dep)
204     vulkan_sources += [
205       'ios/gstvkdisplay_ios.m',
206       'ios/gstvkwindow_ios.m',
207     ]
208     optional_deps += [uikit_dep]
209     vulkan_windowing = true
210     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_IOS', 1)
211   endif
212 endif
213
214 if host_system == 'windows'
215   gdi_dep = cc.find_library('gdi32', required : get_option('vulkan'))
216
217   # Cannot use internal dependency object with cc.has_header()
218   if gdi_dep.found() and cc.has_header('vulkan/vulkan_win32.h', args: '-I' + vulkan_inc_dir)
219     vulkan_sources += ['win32/gstvkwindow_win32.c']
220     optional_deps += [gdi_dep]
221     vulkan_windowing = true
222     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_WIN32', 1)
223   endif
224 endif
225
226 if host_system == 'android'
227   if cc.has_header('vulkan/vulkan_android.h', dependencies : vulkan_dep)
228     vulkan_sources += [
229       'android/gstvkdisplay_android.c',
230       'android/gstvkwindow_android.c',
231     ]
232     vulkan_windowing = true
233     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_ANDROID', 1)
234   endif
235 endif
236
237 if not vulkan_windowing
238   warning('No Windowing system found.  vulkansink will not work')
239 endif
240
241 if not vulkan_dep.found() or not has_vulkan_header
242   if get_option('vulkan').enabled()
243     error('GStreamer Vulkan integration required via options, but needed dependencies not found.')
244   else
245     gstvulkan_dep = dependency('', required : false)
246     subdir_done()
247   endif
248 endif
249
250 gen_sources = []
251
252 install_headers(vulkan_headers, subdir : 'gstreamer-1.0/gst/vulkan')
253 install_headers(vulkan_xcb_headers, subdir : 'gstreamer-1.0/gst/vulkan/xcb')
254 install_headers(vulkan_wayland_headers, subdir : 'gstreamer-1.0/gst/vulkan/wayland')
255
256 configure_file(input : 'gstvkconfig.h.meson',
257   output : 'gstvkconfig.h',
258   install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/vulkan'),
259   configuration : vulkan_conf)
260
261 vulkan_enums = gnome.mkenums_simple('vulkan-enumtypes',
262   sources : vulkan_headers,
263   body_prefix : '#ifdef HAVE_CONFIG_H\n#include "config.h"\n#endif',
264   header_prefix : '#include <gst/vulkan/vulkan-prelude.h>',
265   decorator : 'GST_VULKAN_API',
266   install_header: true,
267   install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/vulkan'))
268 vulkan_enumtypes_c = vulkan_enums[0]
269 vulkan_enumtypes_h = vulkan_enums[1]
270 gen_sources += [vulkan_enumtypes_h]
271
272 gstvulkan = library('gstvulkan-' + api_version,
273   vulkan_sources, vulkan_enumtypes_c, vulkan_enumtypes_h,
274   c_args : gst_plugins_bad_args + vulkan_defines + ['-DBUILDING_GST_VULKAN'],
275   objc_args : gst_plugins_bad_args + vulkan_defines + vulkan_objc_args + ['-DBUILDING_GST_VULKAN'],
276   include_directories : [configinc, libsinc],
277   version : libversion,
278   soversion : soversion,
279   darwin_versions : osxversion,
280   install : true,
281   dependencies : [gstbase_dep, gstvideo_dep, vulkan_dep] + optional_deps)
282
283 if build_gir
284   extra_gir_includes = []
285   gobject_introspection_dep = dependency('gobject-introspection-1.0')
286   if gobject_introspection_dep.version().version_compare('>=1.61.1')
287     # This is the first version that contains Vulkan-1.0.gir
288     extra_gir_includes += ['Vulkan-1.0']
289   endif
290
291   vulkan_gir = gnome.generate_gir(gstvulkan,
292     sources : vulkan_sources + vulkan_headers + [vulkan_enumtypes_h, vulkan_enumtypes_c],
293     namespace : 'GstVulkan',
294     nsversion : api_version,
295     identifier_prefix : 'Gst',
296     symbol_prefix : 'gst',
297     export_packages : 'gstreamer-vulkan-1.0',
298     includes : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0'] + extra_gir_includes,
299     install : true,
300     extra_args : gir_init_section + ['--c-include=gst/vulkan/vulkan.h'],
301     dependencies : [gstvideo_dep, gst_dep, gstbase_dep] + optional_deps
302   )
303   gen_sources += vulkan_gir
304 endif
305
306 gstvulkan_dep = declare_dependency(link_with : gstvulkan,
307   include_directories : [libsinc],
308   sources: gen_sources,
309   dependencies : [gstvideo_dep, gstbase_dep, vulkan_dep] + optional_deps)