meson: Fix automagic dependency checks in gstvulkan

Windowing, in particular, was getting silently disabled.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7091>
This commit is contained in:
Nirbheek Chauhan 2024-06-23 03:46:39 +05:30
parent 6073257bd8
commit 54a6643986
2 changed files with 94 additions and 91 deletions

View file

@ -1,7 +1,9 @@
gstvulkan_dep = dependency('', required: false)
gstvulkanxcb_dep = dependency('', required: false)
gstvulkanwyland_dep = dependency('', required: false)
if get_option('vulkan').disabled()
vulkan_windowing_opt = get_option('vulkan-windowing')
vulkan_opt = get_option('vulkan')
if vulkan_opt.disabled()
subdir_done()
endif
@ -115,7 +117,7 @@ if ['ios', 'darwin'].contains(host_system)
# retrieving the metal device from the VkDevice) which is currently waiting
# on implementing a proper Metal extension for Vulkan
# https://github.com/KhronosGroup/MoltenVK/issues/492
vulkan_dep = cc.find_library('MoltenVK', required : get_option('vulkan'))
vulkan_dep = cc.find_library('MoltenVK', required : vulkan_opt)
endif
elif host_system == 'windows'
vulkan_root = run_command(python3, '-c', 'import os; print(os.environ.get("VK_SDK_PATH"))', check: false).stdout().strip()
@ -128,11 +130,12 @@ elif host_system == 'windows'
endif
vulkan_lib = cc.find_library('vulkan-1', dirs: vulkan_lib_dir,
required : get_option('vulkan'))
required : vulkan_opt)
vulkan_inc_dir = join_paths(vulkan_root, 'Include')
has_vulkan_header = cc.has_header('vulkan/vulkan_core.h',
args: '-I' + vulkan_inc_dir)
args: '-I' + vulkan_inc_dir,
required: vulkan_opt)
if vulkan_lib.found() and has_vulkan_header
vulkan_dep = declare_dependency(include_directories: include_directories(vulkan_inc_dir),
@ -140,85 +143,87 @@ elif host_system == 'windows'
endif
endif
else
vulkan_dep = dependency('vulkan', method: 'pkg-config', required : false)
vulkan_dep = dependency('vulkan', method: 'pkg-config', required: false)
if not vulkan_dep.found()
vulkan_dep = cc.find_library('vulkan', required : false)
vulkan_dep = cc.find_library('vulkan', required: vulkan_opt)
endif
endif
if host_system != 'windows'
has_vulkan_header = cc.has_header('vulkan/vulkan_core.h', dependencies: vulkan_dep)
has_vulkan_header = cc.has_header('vulkan/vulkan_core.h', dependencies: vulkan_dep, required: vulkan_opt)
endif
if not has_vulkan_header and get_option('vulkan').enabled()
error('vulkan plugin enabled, but vulkan.h not found')
endif
if not vulkan_dep.found() and get_option('vulkan').enabled()
error('vulkan plugin enabled, but could not find vulkan library')
if 'x11' in vulkan_windowing_opt or 'auto' in vulkan_windowing_opt
vulkan_xcb_required = vulkan_opt.enabled() and 'x11' in vulkan_windowing_opt
xcb_dep = dependency('xcb', version : '>=1.10', required: vulkan_xcb_required)
xkbcommon_dep = dependency('xkbcommon', required: vulkan_xcb_required)
xkbcommon_x11_dep = dependency('xkbcommon-x11', required: vulkan_xcb_required)
if xcb_dep.found() and xkbcommon_dep.found() and xkbcommon_x11_dep.found() and \
cc.has_header('vulkan/vulkan_xcb.h', dependencies : vulkan_dep, required: vulkan_xcb_required)
vulkan_priv_sources += files(
'xcb/gstvkwindow_xcb.c',
'xcb/xcb_event_source.c',
)
vulkan_xcb_sources += files(
'xcb/gstvkdisplay_xcb.c',
)
vulkan_xcb_headers += files(
'xcb/xcb.h',
'xcb/gstvkdisplay_xcb.h'
)
optional_deps += [xcb_dep, xkbcommon_dep, xkbcommon_x11_dep]
vulkan_windowing = true
vulkan_conf.set('GST_VULKAN_HAVE_WINDOW_XCB', 1)
enabled_vulkan_winsys += ['xcb']
endif
endif
xcb_dep = dependency('xcb', version : '>=1.10', required : get_option('x11'))
xkbcommon_dep = dependency('xkbcommon', required : get_option('x11'))
xkbcommon_x11_dep = dependency('xkbcommon-x11', required : get_option('x11'))
if 'wayland' in vulkan_windowing_opt or 'auto' in vulkan_windowing_opt
vulkan_wayland_required = vulkan_opt.enabled() and 'wayland' in vulkan_windowing_opt
wayland_client_dep = dependency('wayland-client', version : '>=1.4', required: vulkan_wayland_required)
wayland_protocols_dep = dependency('wayland-protocols', version : '>= 1.15', required: vulkan_wayland_required)
wayland_scanner = find_program('wayland-scanner', required: vulkan_wayland_required)
if xcb_dep.found() and xkbcommon_dep.found() and xkbcommon_x11_dep.found() and cc.has_header('vulkan/vulkan_xcb.h', dependencies : vulkan_dep)
vulkan_priv_sources += files(
'xcb/gstvkwindow_xcb.c',
'xcb/xcb_event_source.c',
)
vulkan_xcb_sources += files(
'xcb/gstvkdisplay_xcb.c',
)
vulkan_xcb_headers += files(
'xcb/xcb.h',
'xcb/gstvkdisplay_xcb.h'
)
if wayland_client_dep.found() and wayland_protocols_dep.found() and wayland_scanner.found() and \
cc.has_header('vulkan/vulkan_wayland.h', dependencies: vulkan_dep, required: vulkan_wayland_required)
# Generate the XDG shell interface
wayland_protocols_basedir = wayland_protocols_dep.get_variable('pkgdatadir')
xdg_shell_xml_spec = join_paths(wayland_protocols_basedir, 'stable', 'xdg-shell', 'xdg-shell.xml')
xdg_shell_header = custom_target('xdg-shell-client-header',
command: [ wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@' ],
input: xdg_shell_xml_spec,
output: 'xdg-shell-client-protocol.h',
)
xdg_shell_code = custom_target('xdg-shell-client-code',
command: [ wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@' ],
input: xdg_shell_xml_spec,
output: 'xdg-shell-client-protocol.c',
)
optional_deps += [xcb_dep, xkbcommon_dep, xkbcommon_x11_dep]
vulkan_windowing = true
vulkan_conf.set('GST_VULKAN_HAVE_WINDOW_XCB', 1)
enabled_vulkan_winsys += ['xcb']
endif
vulkan_priv_sources += files(
'wayland/gstvkdisplay_wayland.c',
'wayland/gstvkwindow_wayland.c',
'wayland/wayland_event_source.c',
)
vulkan_priv_sources += [
xdg_shell_header,
xdg_shell_code,
]
vulkan_wayland_sources += files(
'wayland/gstvkdisplay_wayland.c',
)
vulkan_wayland_headers += files(
'wayland/wayland.h',
'wayland/gstvkdisplay_wayland.h'
)
wayland_client_dep = dependency('wayland-client', version : '>=1.4', required : get_option('wayland'))
wayland_protocols_dep = dependency('wayland-protocols', version : '>= 1.15', required : get_option('wayland'))
wayland_scanner = find_program('wayland-scanner', required: get_option('wayland'))
if wayland_client_dep.found() and wayland_protocols_dep.found() and wayland_scanner.found() and cc.has_header('vulkan/vulkan_wayland.h', dependencies : vulkan_dep)
# Generate the XDG shell interface
wayland_protocols_basedir = wayland_protocols_dep.get_variable('pkgdatadir')
xdg_shell_xml_spec = join_paths(wayland_protocols_basedir, 'stable', 'xdg-shell', 'xdg-shell.xml')
xdg_shell_header = custom_target('xdg-shell-client-header',
command: [ wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@' ],
input: xdg_shell_xml_spec,
output: 'xdg-shell-client-protocol.h',
)
xdg_shell_code = custom_target('xdg-shell-client-code',
command: [ wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@' ],
input: xdg_shell_xml_spec,
output: 'xdg-shell-client-protocol.c',
)
vulkan_priv_sources += files(
'wayland/gstvkdisplay_wayland.c',
'wayland/gstvkwindow_wayland.c',
'wayland/wayland_event_source.c',
)
vulkan_priv_sources += [
xdg_shell_header,
xdg_shell_code,
]
vulkan_wayland_sources += files(
'wayland/gstvkdisplay_wayland.c',
)
vulkan_wayland_headers += files(
'wayland/wayland.h',
'wayland/gstvkdisplay_wayland.h'
)
optional_deps += wayland_client_dep
vulkan_windowing = true
vulkan_conf.set('GST_VULKAN_HAVE_WINDOW_WAYLAND', 1)
enabled_vulkan_winsys += ['wayland']
optional_deps += wayland_client_dep
vulkan_windowing = true
vulkan_conf.set('GST_VULKAN_HAVE_WINDOW_WAYLAND', 1)
enabled_vulkan_winsys += ['wayland']
endif
endif
if ['darwin', 'ios'].contains(host_system)
@ -229,18 +234,18 @@ if ['darwin', 'ios'].contains(host_system)
vulkan_objc_args += ['-fobjc-arc']
foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : get_option('vulkan'))
quartzcore_dep = dependency('appleframeworks', modules : ['QuartzCore'], required : get_option('vulkan'))
corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : get_option('vulkan'))
foundation_dep = dependency('appleframeworks', modules : ['Foundation'], required : vulkan_opt)
quartzcore_dep = dependency('appleframeworks', modules : ['QuartzCore'], required : vulkan_opt)
corefoundation_dep = dependency('appleframeworks', modules : ['CoreFoundation'], required : vulkan_opt)
if foundation_dep.found() and quartzcore_dep.found() and corefoundation_dep.found()
optional_deps += [foundation_dep, corefoundation_dep, quartzcore_dep]
endif
endif
if host_system == 'darwin'
cocoa_dep = dependency('appleframeworks', modules : ['Cocoa'], required : get_option('vulkan'))
cocoa_dep = dependency('appleframeworks', modules : ['Cocoa'], required : vulkan_opt)
if cocoa_dep.found() and cc.has_header('vulkan/vulkan_macos.h', dependencies : vulkan_dep)
if cocoa_dep.found() and cc.has_header('vulkan/vulkan_macos.h', dependencies: vulkan_dep, required: vulkan_opt)
vulkan_priv_sources += files(
'cocoa/gstvkdisplay_cocoa.m',
'cocoa/gstvkwindow_cocoa.m',
@ -253,9 +258,9 @@ if host_system == 'darwin'
endif
if host_system == 'ios'
uikit_dep = dependency('appleframeworks', modules : ['UIKit'], required : get_option('vulkan'))
uikit_dep = dependency('appleframeworks', modules : ['UIKit'], required : vulkan_opt)
if uikit_dep.found() and cc.has_header('vulkan/vulkan_ios.h', dependencies : vulkan_dep)
if uikit_dep.found() and cc.has_header('vulkan/vulkan_ios.h', dependencies : vulkan_dep, required: vulkan_opt)
vulkan_priv_sources += files(
'ios/gstvkdisplay_ios.m',
'ios/gstvkwindow_ios.m',
@ -268,10 +273,10 @@ if host_system == 'ios'
endif
if host_system == 'windows'
gdi_dep = cc.find_library('gdi32', required : get_option('vulkan'))
gdi_dep = cc.find_library('gdi32', required : vulkan_opt)
# Cannot use internal dependency object with cc.has_header()
if gdi_dep.found() and cc.has_header('vulkan/vulkan_win32.h', args: '-I' + vulkan_inc_dir)
if gdi_dep.found() and cc.has_header('vulkan/vulkan_win32.h', args: '-I' + vulkan_inc_dir, required: vulkan_opt)
vulkan_priv_sources += ['win32/gstvkwindow_win32.c']
optional_deps += [gdi_dep]
vulkan_windowing = true
@ -281,7 +286,7 @@ if host_system == 'windows'
endif
if host_system == 'android'
if cc.has_header('vulkan/vulkan_android.h', dependencies : vulkan_dep)
if cc.has_header('vulkan/vulkan_android.h', dependencies : vulkan_dep, required: vulkan_opt)
vulkan_priv_sources += files(
'android/gstvkdisplay_android.c',
'android/gstvkwindow_android.c',
@ -293,7 +298,7 @@ if host_system == 'android'
endif
if not vulkan_windowing
if get_option('vulkan').enabled()
if vulkan_opt.enabled()
error('No Windowing system found. vulkansink will not work')
else
message('No Windowing system found. vulkansink will not work')
@ -301,11 +306,7 @@ if not vulkan_windowing
endif
if not vulkan_dep.found() or not has_vulkan_header
if get_option('vulkan').enabled()
error('GStreamer Vulkan integration required via options, but needed dependencies not found.')
else
subdir_done()
endif
subdir_done()
endif
if get_option('vulkan-video').allowed()

View file

@ -179,7 +179,6 @@ option('uvch264', type : 'feature', value : 'auto', description : 'UVC compliant
option('va', type : 'feature', value : 'auto', description: 'VA-API new plugin')
option('voaacenc', type : 'feature', value : 'auto', description : 'AAC audio encoder plugin')
option('voamrwbenc', type : 'feature', value : 'auto', description : 'AMR-WB audio encoder plugin')
option('vulkan', type : 'feature', value : 'auto', description : 'Vulkan video sink plugin')
option('wasapi', type : 'feature', value : 'auto', description : 'Windows Audio Session API source/sink plugin')
option('wasapi2', type : 'feature', value : 'auto', description : 'Windows Audio Session API source/sink plugin with WinRT API')
option('webview2', type : 'feature', value : 'auto', description : 'WebView2 plugin')
@ -250,9 +249,12 @@ option('nvcomp-sdk-path', type: 'string', value : '',
option('mfx-modules-dir', type: 'string', value : '',
description : 'libmfx runtime module dir, linux only')
# Vulkan plugin options
option('vulkan-video', type: 'feature', value: 'auto',
description: 'Whether to use Vulkan Video Extensions')
# Vulkan integration library and plugin options
option('vulkan', type: 'feature', value: 'auto', description: 'Vulkan integration library and video sink plugin')
option('vulkan-video', type: 'feature', value: 'auto', description: 'Whether to use Vulkan Video Extensions for encoding/decoding')
option('vulkan-windowing', type : 'array',
choices : ['x11', 'wayland', 'auto'], value : ['auto'],
description : 'A comma separated list of Vulkan windowing systems to enable. Non-Linux platforms are auto-detected.')
# License-related feature options
option('gpl', type: 'feature', value: 'disabled', yield: true,