sctp: hook up internal copy of libusrsctp to build

Add option 'sctp-internal-usrsctp' so people can choose
to build againts the distro version instead.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/870

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1465>
This commit is contained in:
Tim-Philipp Müller 2020-07-25 17:56:43 +01:00
parent f4538e24b6
commit 80a0da9698
4 changed files with 88 additions and 104 deletions

View file

@ -11,22 +11,47 @@ endif
sctp_platform_deps = [] sctp_platform_deps = []
sctp_dep = cc.find_library('usrsctp', required : get_option('sctp').enabled()) found_system_usrsctp = false
if not get_option('sctp-internal-usrsctp').enabled()
sctp_dep = cc.find_library('usrsctp', required: false)
sctp_header = cc.has_header('usrsctp.h') sctp_header = cc.has_header('usrsctp.h')
if host_system == 'windows' if host_system == 'windows'
sctp_platform_deps += [cc.find_library('ws2_32')] sctp_platform_deps += [cc.find_library('ws2_32')]
endif endif
found_system_usrsctp = sctp_dep.found() and sctp_header
if get_option('sctp-internal-usrsctp').disabled() and not found_system_usrsctp
if get_option('sctp').enabled() if get_option('sctp').enabled()
if not sctp_dep.found() or not sctp_header error('sctp plugin enabled but could not find libusrsctp or usrsctp.h, and internal libusrsctp disabled')
error('sctp plugin enabled but could not find libusrsctp') else
message('Could not find libusrsctp or usrsctp.h, and internal libusrsctp disabled - not building sctp plugin')
subdir_done()
endif endif
endif endif
endif
if not found_system_usrsctp
message('Using internal libusrsctp')
subdir('usrsctp')
sctp_dep = usrsctp_dep
sctp_header = true
if get_option('sctp').enabled() and not sctp_dep.found()
error('sctp plugin enabled but could not find system libusrsctp or configure internal libusrsctp')
endif
endif
if not gst_debug_disabled
sctp_args = ['-DSCTP_DEBUG']
else
sctp_args = []
endif
if sctp_dep.found() and sctp_header if sctp_dep.found() and sctp_header
gstsctp = library('gstsctp', gstsctp = library('gstsctp',
sctp_sources, sctp_sources,
c_args : gst_plugins_bad_args, c_args : gst_plugins_bad_args + sctp_args,
include_directories : [configinc], include_directories : [configinc],
dependencies : [sctp_dep, gst_dep, gstbase_dep, gstsctp_dep, sctp_platform_deps], dependencies : [sctp_dep, gst_dep, gstbase_dep, gstsctp_dep, sctp_platform_deps],
install : true, install : true,

View file

@ -1,9 +1,3 @@
# Project definition
project('usrsctplib', 'c',
version: '1.0.0',
default_options: ['c_std=c99'],
meson_version: '>=0.49.0')
# Set compiler warning flags # Set compiler warning flags
compiler = meson.get_compiler('c') compiler = meson.get_compiler('c')
if compiler.get_argument_syntax() == 'msvc' if compiler.get_argument_syntax() == 'msvc'
@ -21,9 +15,6 @@ if compiler.get_argument_syntax() == 'msvc'
]) ])
else else
compiler_args = compiler.get_supported_arguments([ compiler_args = compiler.get_supported_arguments([
'-pedantic',
'-Wall',
'-Wextra',
'-Wfloat-equal', '-Wfloat-equal',
'-Wshadow', '-Wshadow',
'-Wpointer-arith', '-Wpointer-arith',
@ -32,12 +23,21 @@ else
'-Wno-unused-parameter', '-Wno-unused-parameter',
'-Wno-unreachable-code', '-Wno-unreachable-code',
'-Wstrict-prototypes', '-Wstrict-prototypes',
# fix GStreamer build with -Werror
'-Wno-missing-prototypes',
'-Wno-incompatible-pointer-types-discards-qualifiers',
'-Wno-address-of-packed-member',
'-Wno-discarded-qualifiers',
'-Wno-missing-declarations',
'-Wno-old-style-definition',
'-Wno-redundant-decls',
'-Wno-error',
]) ])
endif endif
add_project_arguments(compiler_args, language: 'c')
# Configuration # Configuration
compile_args = []
compile_args = [compiler_args]
# Dependency: Threads # Dependency: Threads
thread_dep = dependency('threads', required: true) thread_dep = dependency('threads', required: true)
@ -48,55 +48,57 @@ dependencies = [
] ]
# Global settings # Global settings
add_project_arguments([ compile_args += [
'-D__Userspace__', '-D__Userspace__',
'-DSCTP_SIMPLE_ALLOCATOR', '-DSCTP_SIMPLE_ALLOCATOR',
'-DSCTP_PROCESS_LEVEL_LOCKS', '-DSCTP_PROCESS_LEVEL_LOCKS',
], language: 'c') ]
# OS-specific settings # OS-specific settings
system = host_machine.system() system = host_machine.system()
if system in ['linux', 'android'] if system in ['linux', 'android']
add_project_arguments([ compile_args += [
'-D_GNU_SOURCE', '-D_GNU_SOURCE',
], language: 'c') ]
elif system == 'freebsd' elif system == 'freebsd'
add_project_arguments(compiler.get_supported_arguments([ compile_args += [compiler.get_supported_arguments([
'-Wno-address-of-packed-member', '-Wno-address-of-packed-member',
]), language: 'c') ])]
elif system in ['darwin', 'ios'] elif system in ['darwin', 'ios']
add_project_arguments([ compile_args += [[
'-D__APPLE_USE_RFC_2292', '-D__APPLE_USE_RFC_2292',
] + compiler.get_supported_arguments([ ] + compiler.get_supported_arguments([
'-Wno-address-of-packed-member', '-Wno-address-of-packed-member',
'-Wno-deprecated-declarations', '-Wno-deprecated-declarations',
]), language: 'c') ])]
elif system == 'windows' elif system == 'windows'
dependencies += compiler.find_library('ws2_32', required: true) dependencies += compiler.find_library('ws2_32', required: true)
dependencies += compiler.find_library('iphlpapi', required: true) dependencies += compiler.find_library('iphlpapi', required: true)
if compiler.get_id() == 'gcc' if compiler.get_id() == 'gcc'
add_project_arguments(compiler.get_supported_arguments([ compile_args += [compiler.get_supported_arguments([
'-Wno-format', '-Wno-format',
'-D_WIN32_WINNT=0x601', # Enables inet_ntop and friends '-D_WIN32_WINNT=0x601', # Enables inet_ntop and friends
]), language: 'c') ])]
endif endif
else else
error('Unknown system: @0@'.format(system)) warning('Unknown system: @0@'.format(system))
usrsctp_dep = dependency('', required: false)
subdir_done()
endif endif
# Feature: sys/queue # Feature: sys/queue
if compiler.has_header('sys/queue.h') if compiler.has_header('sys/queue.h')
add_project_arguments('-DHAVE_SYS_QUEUE_H', language: 'c') compile_args += ['-DHAVE_SYS_QUEUE_H']
endif endif
# Feature: sys/socket, linux/ifaddr, linux/rtnetlink # Feature: sys/socket, linux/ifaddr, linux/rtnetlink
if compiler.has_header('sys/socket.h') if compiler.has_header('sys/socket.h')
if compiler.has_header('linux/if_addr.h') if compiler.has_header('linux/if_addr.h')
add_project_arguments('-DHAVE_LINUX_IF_ADDR_H', language: 'c') compile_args += ['-DHAVE_LINUX_IF_ADDR_H']
endif endif
if compiler.has_header('linux/rtnetlink.h') if compiler.has_header('linux/rtnetlink.h')
add_project_arguments('-DHAVE_LINUX_RTNETLINK_H', language: 'c') compile_args += ['-DHAVE_LINUX_RTNETLINK_H']
endif endif
endif endif
@ -106,12 +108,12 @@ have_netinet_in = compiler.has_header('netinet/in.h')
have_netinet_ip = compiler.has_header('netinet/ip.h') have_netinet_ip = compiler.has_header('netinet/ip.h')
have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h') have_netinet_ip_icmp = compiler.has_header('netinet/ip_icmp.h')
if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_icmp if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_icmp
add_project_arguments('-DHAVE_NETINET_IP_ICMP_H', language: 'c') compile_args += ['-DHAVE_NETINET_IP_ICMP_H']
endif endif
# Feature: stdatomic # Feature: stdatomic
if compiler.has_header('stdatomic.h') if compiler.has_header('stdatomic.h')
add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c') compile_args += ['-DHAVE_STDATOMIC_H']
endif endif
# Feature: sockaddr.sa_len # Feature: sockaddr.sa_len
@ -121,7 +123,7 @@ prefix = '''
''' '''
have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix) have_sa_len = compiler.has_member('struct sockaddr', 'sa_len', prefix: prefix)
if have_sa_len if have_sa_len
add_project_arguments('-DHAVE_SA_LEN', language: 'c') compile_args += ['-DHAVE_SA_LEN']
endif endif
# Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len # Feature: sockaddr_in.sin_len / sockaddr_in6.sin6_len / sockaddr_conn.sconn_len
@ -131,90 +133,46 @@ prefix = '''
''' '''
have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix) have_sin_len = compiler.has_member('struct sockaddr_in', 'sin_len', prefix: prefix)
if have_sin_len if have_sin_len
add_project_arguments('-DHAVE_SIN_LEN', language: 'c') compile_args += ['-DHAVE_SIN_LEN']
endif endif
have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix) have_sin6_len = compiler.has_member('struct sockaddr_in6', 'sin6_len', prefix: prefix)
if have_sin6_len if have_sin6_len
add_project_arguments('-DHAVE_SIN6_LEN', language: 'c') compile_args += ['-DHAVE_SIN6_LEN']
endif endif
have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib')) have_sconn_len = compiler.has_member('struct sockaddr_conn', 'sconn_len', prefix: '#include "usrsctp.h"', include_directories: include_directories('usrsctplib'))
if have_sconn_len if have_sconn_len
add_project_arguments('-DHAVE_SCONN_LEN', language: 'c') compile_args += ['-DHAVE_SCONN_LEN']
endif endif
# Options # Options
if get_option('sctp_invariants') if false
add_project_arguments('-DINVARIANTS', language: 'c') compile_args += ['-DINVARIANTS']
endif endif
if get_option('sctp_debug') if not gst_debug_disabled
add_project_arguments('-DSCTP_DEBUG', language: 'c') compile_args += ['-DSCTP_DEBUG']
compile_args += '-DSCTP_DEBUG'
endif endif
if get_option('sctp_inet') # We do not need the socket API in GStreamer since we will wrap inside a
add_project_arguments('-DINET', language: 'c') # DTLS packet anyway, because we use SCTP for WebRTC data channels.
if false
compile_args += ['-DINET']
endif endif
if get_option('sctp_inet6') if false
add_project_arguments('-DINET6', language: 'c') compile_args += ['-DINET6']
endif endif
compile_args += ['-DSCTP_STDINT_INCLUDE=<stdint.h>']
# Library # Library
subdir('usrsctplib') subdir('usrsctplib')
# Build library # Build library
if compiler.get_id() == 'msvc' and get_option('default_library') == 'shared'
# Needed by usrsctp_def
find_program('dumpbin')
usrsctp_static = static_library('usrsctp-static', sources, usrsctp_static = static_library('usrsctp-static', sources,
dependencies: dependencies, c_args: compile_args,
include_directories: include_dirs)
usrsctp_def = custom_target('usrsctp.def',
command: [find_program('gen-def.py'), '@INPUT@'],
input: usrsctp_static,
output: 'usrsctp.def',
capture: true)
usrsctp = shared_library('usrsctp',
link_whole: usrsctp_static,
dependencies: dependencies,
vs_module_defs: usrsctp_def,
install: true,
version: meson.project_version())
else
usrsctp = library('usrsctp', sources,
dependencies: dependencies, dependencies: dependencies,
include_directories: include_dirs, include_directories: include_dirs,
install: true, install: false)
version: meson.project_version(),
c_args: '-U__APPLE__')
endif
# Declare dependency # Declare dependency
usrsctp_dep = declare_dependency( usrsctp_dep = declare_dependency(
compile_args: compile_args,
include_directories: include_dirs, include_directories: include_dirs,
link_with: usrsctp) link_with: usrsctp_static)
# Generate pkg-config file
pkg = import('pkgconfig')
pkg.generate(usrsctp,
name: 'usrsctp',
description: 'A portable SCTP userland stack',
url: 'https://github.com/sctplab/usrsctp',
extra_cflags: compile_args)
# Programs (optional)
if get_option('sctp_build_programs')
subdir('programs')
# Build executables
foreach name, sources : programs
executable(
name,
programs_helper_sources + sources,
dependencies: dependencies,
link_with: usrsctp,
include_directories: include_dirs)
endforeach
endif

View file

@ -15,6 +15,3 @@ sources = files([
subdir('netinet') subdir('netinet')
subdir('netinet6') subdir('netinet6')
# Install usrsctp.h
install_headers('usrsctp.h')

View file

@ -175,6 +175,10 @@ option('hls', type : 'feature', value : 'auto', description : 'HTTP Live Streami
option('hls-crypto', type : 'combo', value : 'auto', choices : ['auto', 'nettle', 'libgcrypt', 'openssl'], option('hls-crypto', type : 'combo', value : 'auto', choices : ['auto', 'nettle', 'libgcrypt', 'openssl'],
description: 'Crypto library to use for HLS plugin') description: 'Crypto library to use for HLS plugin')
# SCTP plugin options
option('sctp-internal-usrsctp', type: 'feature', value : 'enabled',
description: 'Whether to use the bundled usrsctp library or the system one')
# Common feature options # Common feature options
option('examples', type : 'feature', value : 'auto', yield : true) option('examples', type : 'feature', value : 'auto', yield : true)
option('tests', type : 'feature', value : 'auto', yield : true) option('tests', type : 'feature', value : 'auto', yield : true)