meson: List libraries and their corresponding gir definition
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / gst-libs / gst / vulkan / meson.build
1 gstvulkan_dep = dependency('', required: false)
2 gstvulkanxcb_dep = dependency('', required: false)
3 gstvulkanwyland_dep = dependency('', required: false)
4 if get_option('vulkan').disabled()
5   subdir_done()
6 endif
7
8 vulkan_sources = files(
9   'gstvkbuffermemory.c',
10   'gstvkbufferpool.c',
11   'gstvkcommandbuffer.c',
12   'gstvkcommandpool.c',
13   'gstvkdescriptorcache.c',
14   'gstvkdescriptorset.c',
15   'gstvkdescriptorpool.c',
16   'gstvkdevice.c',
17   'gstvkdebug.c',
18   'gstvkdisplay.c',
19   'gstvkerror.c',
20   'gstvkfence.c',
21   'gstvkformat.c',
22   'gstvkfullscreenquad.c',
23   'gstvkhandle.c',
24   'gstvkhandlepool.c',
25   'gstvkimagememory.c',
26   'gstvkimagebufferpool.c',
27   'gstvkimageview.c',
28   'gstvkinstance.c',
29   'gstvkmemory.c',
30   'gstvkphysicaldevice.c',
31   'gstvkqueue.c',
32   'gstvkswapper.c',
33   'gstvktrash.c',
34   'gstvkvideofilter.c',
35   'gstvkutils.c',
36   'gstvkwindow.c',
37 )
38
39 vulkan_headers = files(
40   'gstvkapi.h',
41   'gstvkbarrier.h',
42   'gstvkbuffermemory.h',
43   'gstvkbufferpool.h',
44   'gstvkcommandbuffer.h',
45   'gstvkcommandpool.h',
46   'gstvkdescriptorcache.h',
47   'gstvkdescriptorset.h',
48   'gstvkdescriptorpool.h',
49   'gstvkdebug.h',
50   'gstvkdevice.h',
51   'gstvkdisplay.h',
52   'gstvkerror.h',
53   'gstvkfence.h',
54   'gstvkformat.h',
55   'gstvkfullscreenquad.h',
56   'gstvkhandle.h',
57   'gstvkhandlepool.h',
58   'gstvkimagememory.h',
59   'gstvkimagebufferpool.h',
60   'gstvkimageview.h',
61   'gstvkinstance.h',
62   'gstvkmemory.h',
63   'gstvkphysicaldevice.h',
64   'gstvkqueue.h',
65   'gstvkswapper.h',
66   'gstvktrash.h',
67   'gstvkutils.h',
68   'gstvkvideofilter.h',
69   'gstvkwindow.h',
70   'vulkan-prelude.h',
71   'vulkan_fwd.h',
72   'vulkan.h',
73 )
74
75 vulkan_priv_sources = []
76 vulkan_xcb_sources = []
77 vulkan_xcb_headers = []
78 vulkan_wayland_sources = []
79 vulkan_wayland_headers = []
80
81 vulkan_windowing = false
82 vulkan_objc_args = []
83 vulkan_defines = []
84 optional_deps = []
85 has_vulkan_header = false
86 vulkan_dep = dependency('', required: false)
87 vulkan_inc_dir = ''
88 enabled_vulkan_winsys = []
89
90 vulkan_conf = configuration_data()
91 vulkan_conf_options = [
92     'GST_VULKAN_HAVE_WINDOW_XCB',
93     'GST_VULKAN_HAVE_WINDOW_WAYLAND',
94     'GST_VULKAN_HAVE_WINDOW_COCOA',
95     'GST_VULKAN_HAVE_WINDOW_IOS',
96     'GST_VULKAN_HAVE_WINDOW_WIN32',
97     'GST_VULKAN_HAVE_WINDOW_ANDROID',
98 ]
99
100 foreach option : vulkan_conf_options
101   vulkan_conf.set10(option, false)
102 endforeach
103
104 if ['ios', 'darwin'].contains(host_system)
105   # - ios does not support the loader/validation layers
106   # - We need to link directly to MoltenVK to be able to use
107   #   MoltenVK-specific functions that use dispatchable handles (like
108   #   retrieving the metal device from the VkDevice) which is currently waiting
109   #   on implementing a proper Metal extension for Vulkan
110   #   https://github.com/KhronosGroup/MoltenVK/issues/492
111   vulkan_dep = cc.find_library('MoltenVK', required : get_option('vulkan'))
112 elif host_system == 'windows'
113   vulkan_root = run_command(python3, '-c', 'import os; print(os.environ.get("VK_SDK_PATH"))').stdout().strip()
114   if vulkan_root != '' and vulkan_root != 'None'
115     vulkan_lib_dir = ''
116     if build_machine.cpu_family() == 'x86_64'
117       vulkan_lib_dir = join_paths(vulkan_root, 'Lib')
118     else
119       vulkan_lib_dir = join_paths(vulkan_root, 'Lib32')
120     endif
121
122     vulkan_lib = cc.find_library('vulkan-1', dirs: vulkan_lib_dir,
123                                  required : get_option('vulkan'))
124
125     vulkan_inc_dir = join_paths(vulkan_root, 'Include')
126     has_vulkan_header = cc.has_header('vulkan/vulkan_core.h',
127                                       args: '-I' + vulkan_inc_dir)
128
129     if vulkan_lib.found() and has_vulkan_header
130       vulkan_dep = declare_dependency(include_directories: include_directories(vulkan_inc_dir),
131                                       dependencies: vulkan_lib)
132     endif
133   endif
134 else
135   vulkan_dep = dependency('vulkan', method: 'pkg-config', required : false)
136   if not vulkan_dep.found()
137     vulkan_dep = cc.find_library('vulkan', required : false)
138   endif
139 endif
140
141 if host_system != 'windows'
142   has_vulkan_header = cc.has_header('vulkan/vulkan_core.h')
143 endif
144
145 if not has_vulkan_header and get_option('vulkan').enabled()
146   error('vulkan plugin enabled, but vulkan.h not found')
147 endif
148 if not vulkan_dep.found() and get_option('vulkan').enabled()
149   error('vulkan plugin enabled, but could not find vulkan library')
150 endif
151
152 xcb_dep = dependency('xcb', version : '>=1.10', required : get_option('x11'))
153 xkbcommon_dep = dependency('xkbcommon', required : get_option('x11'))
154 xkbcommon_x11_dep = dependency('xkbcommon-x11', required : get_option('x11'))
155
156 if xcb_dep.found() and xkbcommon_dep.found() and xkbcommon_x11_dep.found() and cc.has_header('vulkan/vulkan_xcb.h', dependencies : vulkan_dep)
157   vulkan_priv_sources += files(
158     'xcb/gstvkwindow_xcb.c',
159     'xcb/xcb_event_source.c',
160   )
161   vulkan_xcb_sources += files(
162     'xcb/gstvkdisplay_xcb.c',
163   )
164   vulkan_xcb_headers += files(
165     'xcb/xcb.h',
166     'xcb/gstvkdisplay_xcb.h'
167   )
168
169   optional_deps += [xcb_dep, xkbcommon_dep, xkbcommon_x11_dep]
170   vulkan_windowing = true
171   vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_XCB', 1)
172   enabled_vulkan_winsys += ['xcb']
173 endif
174
175 wayland_client_dep = dependency('wayland-client', version : '>=1.4', required : get_option('wayland'))
176 if wayland_client_dep.found() and cc.has_header('vulkan/vulkan_wayland.h', dependencies : vulkan_dep)
177   vulkan_priv_sources += files(
178     'wayland/gstvkdisplay_wayland.c',
179     'wayland/gstvkwindow_wayland.c',
180     'wayland/wayland_event_source.c',
181   )
182   vulkan_wayland_sources += files(
183     'wayland/gstvkdisplay_wayland.c',
184   )
185   vulkan_wayland_headers += files(
186     'wayland/wayland.h',
187     'wayland/gstvkdisplay_wayland.h'
188   )
189
190   optional_deps += wayland_client_dep
191   vulkan_windowing = true
192   vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_WAYLAND', 1)
193   enabled_vulkan_winsys += ['wayland']
194 endif
195
196 if ['darwin', 'ios'].contains(host_system)
197   objc = meson.get_compiler('objc')
198   if not objc.has_argument('-fobjc-arc')
199     error('ARC is required for building')
200   endif
201
202   vulkan_objc_args += ['-fobjc-arc']
203
204   foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : get_option('vulkan'))
205   quartzcore_dep = dependency('appleframeworks', modules : ['QuartzCore'], required : get_option('vulkan'))
206   corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : get_option('vulkan'))
207   if foundation_dep.found() and quartzcore_dep.found() and corefoundation_dep.found()
208     optional_deps += [foundation_dep, corefoundation_dep, quartzcore_dep]
209   endif
210 endif
211
212 if host_system == 'darwin'
213   cocoa_dep = dependency('appleframeworks', modules : ['Cocoa'], required : get_option('vulkan'))
214
215   if cocoa_dep.found() and cc.has_header('vulkan/vulkan_macos.h', dependencies : vulkan_dep)
216     vulkan_priv_sources += files(
217       'cocoa/gstvkdisplay_cocoa.m',
218       'cocoa/gstvkwindow_cocoa.m',
219     )
220     optional_deps += [cocoa_dep]
221     vulkan_windowing = true
222     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_COCOA', 1)
223     enabled_vulkan_winsys += ['cocoa']
224   endif
225 endif
226
227 if host_system == 'ios'
228   uikit_dep = dependency('appleframeworks', modules : ['UIKit'], required : get_option('vulkan'))
229
230   if uikit_dep.found() and cc.has_header('vulkan/vulkan_ios.h', dependencies : vulkan_dep)
231     vulkan_priv_sources += files(
232       'ios/gstvkdisplay_ios.m',
233       'ios/gstvkwindow_ios.m',
234     )
235     optional_deps += [uikit_dep]
236     vulkan_windowing = true
237     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_IOS', 1)
238     enabled_vulkan_winsys += ['ios']
239   endif
240 endif
241
242 if host_system == 'windows'
243   gdi_dep = cc.find_library('gdi32', required : get_option('vulkan'))
244
245   # Cannot use internal dependency object with cc.has_header()
246   if gdi_dep.found() and cc.has_header('vulkan/vulkan_win32.h', args: '-I' + vulkan_inc_dir)
247     vulkan_priv_sources += ['win32/gstvkwindow_win32.c']
248     optional_deps += [gdi_dep]
249     vulkan_windowing = true
250     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_WIN32', 1)
251     enabled_vulkan_winsys += ['win32']
252   endif
253 endif
254
255 if host_system == 'android'
256   if cc.has_header('vulkan/vulkan_android.h', dependencies : vulkan_dep)
257     vulkan_priv_sources += files(
258       'android/gstvkdisplay_android.c',
259       'android/gstvkwindow_android.c',
260     )
261     vulkan_windowing = true
262     vulkan_conf.set10('GST_VULKAN_HAVE_WINDOW_ANDROID', 1)
263     enabled_vulkan_winsys += ['android']
264   endif
265 endif
266
267 if not vulkan_windowing
268   if get_option('vulkan').enabled()
269     error('No Windowing system found. vulkansink will not work')
270   else
271     message('No Windowing system found. vulkansink will not work')
272   endif
273 endif
274
275 # Only needed for the vulkan plugin, but doesn't make sense to build
276 # anything else vulkan related if we are not going to build the plugin
277 glslc = find_program('glslc', required: get_option('vulkan'))
278
279 if not vulkan_dep.found() or not has_vulkan_header or not glslc.found()
280   if get_option('vulkan').enabled()
281     error('GStreamer Vulkan integration required via options, but needed dependencies not found.')
282   else
283     subdir_done()
284   endif
285 endif
286
287 gen_sources = []
288
289 install_headers(vulkan_headers, subdir : 'gstreamer-1.0/gst/vulkan')
290
291 configure_file(input : 'gstvkconfig.h.meson',
292   output : 'gstvkconfig.h',
293   install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/vulkan'),
294   configuration : vulkan_conf)
295
296 glib_mkenums = find_program('glib-mkenums')
297 mkenums = find_program('vulkan_mkenum.py')
298 vulkan_enumtypes_h = custom_target('gstvulkanenum_h',
299   output : 'vulkan-enumtypes.h',
300   input : vulkan_headers,
301   install : true,
302   install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst/vulkan/'),
303   command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
304
305 vulkan_enumtypes_c = custom_target('gstvulkanenum_c',
306   output : 'vulkan-enumtypes.c',
307   input : vulkan_headers,
308   depends : [vulkan_enumtypes_h],
309   command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
310 gen_sources += [vulkan_enumtypes_h]
311
312 gstvulkan = library('gstvulkan-' + api_version,
313   vulkan_sources, vulkan_priv_sources, vulkan_wayland_sources, vulkan_xcb_sources, vulkan_enumtypes_c, vulkan_enumtypes_h,
314   c_args : gst_plugins_bad_args + vulkan_defines + ['-DBUILDING_GST_VULKAN'],
315   objc_args : gst_plugins_bad_args + vulkan_defines + vulkan_objc_args + ['-DBUILDING_GST_VULKAN'],
316   include_directories : [configinc, libsinc],
317   version : libversion,
318   soversion : soversion,
319   darwin_versions : osxversion,
320   install : true,
321   dependencies : [gstbase_dep, gstvideo_dep, vulkan_dep] + optional_deps,
322   # don't confuse gst/vulkan/xcb/xcb.h with xcb/xcb.h
323   implicit_include_directories : false)
324
325 library_def = {'lib': gstvulkan}
326 pkg_name = 'gstreamer-vulkan-1.0'
327 pkgconfig.generate(gstvulkan,
328   libraries : [gst_dep, gstbase_dep, gstvideo_dep],
329   variables : pkgconfig_variables,
330   subdirs : pkgconfig_subdirs,
331   name : pkg_name,
332   description : 'GStreamer Vulkan support',
333 )
334
335 if build_gir
336   extra_gir_includes = []
337   gobject_introspection_dep = dependency('gobject-introspection-1.0')
338   if gobject_introspection_dep.version().version_compare('>=1.61.1')
339     # This is the first version that contains Vulkan-1.0.gir
340     extra_gir_includes += ['Vulkan-1.0']
341   endif
342
343   gir = {
344     'sources' : vulkan_sources + vulkan_headers + [vulkan_enumtypes_h, vulkan_enumtypes_c],
345     'namespace' : 'GstVulkan',
346     'nsversion' : api_version,
347     'identifier_prefix' : 'Gst',
348     'symbol_prefix' : 'gst',
349     'export_packages' : pkg_name,
350     'includes' : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0'] + extra_gir_includes,
351     'install' : true,
352     'extra_args' : gir_init_section + ['--c-include=gst/vulkan/vulkan.h'],
353     'dependencies' : [gstvideo_dep, gst_dep, gstbase_dep] + optional_deps
354   }
355
356   library_def += {'gir': [gir]}
357   if not static_build
358     vulkan_gir = gnome.generate_gir(gstvulkan, kwargs: gir)
359     gen_sources += vulkan_gir
360   endif
361 endif
362 libraries += [[pkg_name, library_def]]
363
364 gstvulkan_dep = declare_dependency(link_with : gstvulkan,
365   include_directories : [libsinc],
366   sources: gen_sources,
367   dependencies : [gstvideo_dep, gstbase_dep, vulkan_dep] + optional_deps)
368
369 meson.override_dependency(pkg_name, gstvulkan_dep)
370
371 if enabled_vulkan_winsys.contains('xcb')
372   install_headers(vulkan_xcb_headers, subdir : 'gstreamer-1.0/gst/vulkan/xcb')
373   pkgconfig.generate(
374     libraries : [gstvulkan],
375     requires : ['xcb'],
376     subdirs : pkgconfig_subdirs,
377     name : 'gstreamer-vulkan-xcb-1.0',
378     description : 'GStreamer Vulkan support (XCB Specifics)',
379   )
380   vulkan_xcb_gir = []
381   if build_gir
382     gir = {
383       'sources' : vulkan_xcb_sources + vulkan_xcb_headers,
384       'namespace' : 'GstVulkanXCB',
385       'nsversion' : api_version,
386       'identifier_prefix' : 'Gst',
387       'symbol_prefix' : 'gst',
388       'export_packages' : 'gstreamer-vulkan-xcb-1.0',
389       'install' : true,
390       'extra_args' : gir_init_section + ['--c-include=gst/vulkan/xcb/xcb.h'],
391       'dependencies' : [gstvideo_dep, gst_dep, gstbase_dep] + optional_deps
392     }
393
394     if not static_build
395       gir += {'includes' : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0', vulkan_gir[0]] + extra_gir_includes}
396       vulkan_xcb_gir = gnome.generate_gir(gstvulkan, kwargs: gir)
397     endif
398
399     gir += {'includes' :['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0', 'GstVulkan-1.0'] + extra_gir_includes}
400     library_def += {'gir':  library_def['gir'] + [gir]}
401   endif
402   gstvulkanxcb_dep = declare_dependency(dependencies : [gstvulkan_dep],
403       sources : vulkan_xcb_gir)
404   meson.override_dependency('gstreamer-vulkan-xcb-1.0', gstvulkanxcb_dep)
405 endif
406
407 if enabled_vulkan_winsys.contains('wayland')
408   install_headers(vulkan_wayland_headers, subdir : 'gstreamer-1.0/gst/vulkan/wayland')
409   pkgconfig.generate(
410     libraries : [gstvulkan],
411     requires : ['wayland-client'],
412     subdirs : pkgconfig_subdirs,
413     name : 'gstreamer-vulkan-wayland-1.0',
414     description : 'GStreamer Vulkan support (Wayland Specifics)',
415   )
416   vulkan_wayland_gir = []
417   if build_gir
418     gir = {
419       'sources' : vulkan_wayland_sources + vulkan_wayland_headers,
420       'namespace' : 'GstVulkanWayland',
421       'nsversion' : api_version,
422       'identifier_prefix' : 'Gst',
423       'symbol_prefix' : 'gst',
424       'export_packages' : 'gstreamer-vulkan-wayland-1.0',
425       'install' : true,
426       'extra_args' : gir_init_section + ['--c-include=gst/vulkan/wayland/wayland.h'],
427       'dependencies' : [gstvideo_dep, gst_dep, gstbase_dep] + optional_deps
428     }
429     if not static_build
430       gir += {'includes' : ['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0', vulkan_gir[0]] + extra_gir_includes}
431       vulkan_wayland_gir += gnome.generate_gir(gstvulkan, kwargs: gir)
432     endif
433     gir += {'includes' :['Gst-1.0', 'GstBase-1.0', 'GstVideo-1.0', 'GstVulkan-1.0'] + extra_gir_includes}
434     library_def += {'gir':  library_def['gir'] + [gir]}
435   endif
436   gstvulkanwayland_dep = declare_dependency(dependencies : [gstvulkan_dep],
437       sources : vulkan_wayland_gir)
438   meson.override_dependency('gstreamer-vulkan-wayland-1.0', gstvulkanwayland_dep)
439 endif
440