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