Meson: Use library() to build both static and shared libs

Meson supports building both static and shared libraries in a single
library() call. It has the advantage of reusing the same .o objects and
thus avoid double compilation.

https://bugzilla.gnome.org/show_bug.cgi?id=794627
This commit is contained in:
Xavier Claessens 2018-03-23 12:48:37 -04:00 committed by Tim-Philipp Müller
parent ca3698b9c1
commit b00b1d5361
7 changed files with 119 additions and 190 deletions

View file

@ -223,65 +223,46 @@ if disable_tracer_hooks
libgst_c_args += ['-DGST_DISABLE_GST_TRACER_HOOKS'] libgst_c_args += ['-DGST_DISABLE_GST_TRACER_HOOKS']
endif endif
# Make it possible to build both static and shared versions
# at the same time. By default use shared for unit tests etc.
# This choice is arbitrary.
if libtype != 'shared'
libgst_static = static_library('gstreamer-1.0', gst_sources,
gstenum_h, gstenum_c, grammar, parser, gst_registry,
c_args : [libgst_c_args],
include_directories : [configinc,
# HACK, change include paths in .y and .l in final version.
include_directories('parse')],
install : true,
link_with : printf_lib,
dependencies : [gobject_dep, gmodule_dep, glib_dep, mathlib] + backtrace_deps + platform_deps,
)
libgst = libgst_static
endif
# Make sure that subproject building gir files work # Make sure that subproject building gir files work
gst_incdirs = [configinc] gst_incdirs = [configinc]
gst_gen_sources = [gstenum_h] gst_gen_sources = [gstenum_h]
if libtype != 'static' libgst = library('gstreamer-1.0', gst_sources,
libgst_shared = shared_library('gstreamer-1.0', gst_sources, gstenum_h, gstenum_c, grammar, parser, gst_registry,
gstenum_h, gstenum_c, grammar, parser, gst_registry, version : libversion,
version : libversion, soversion : soversion,
soversion : soversion, c_args : libgst_c_args,
c_args : libgst_c_args, include_directories : [configinc,
include_directories : [configinc, # HACK, change include paths in .y and .l in final version.
# HACK, change include paths in .y and .l in final version. include_directories('parse')],
include_directories('parse')], link_with : printf_lib,
link_with : printf_lib, install : true,
install : true, dependencies : [gobject_dep, gmodule_dep, glib_dep, mathlib, dl_dep] + backtrace_deps
dependencies : [gobject_dep, gmodule_dep, glib_dep, mathlib, dl_dep] + backtrace_deps + platform_deps,
+ platform_deps, )
)
libgst = libgst_shared
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/gst.h' ]
if meson.is_subproject()
# FIXME: There must be a better way to do this
# Need to pass the include path to find gst/gst.h and gst/gstenumtypes.h (built)
gst_gir_extra_args += ['--cflags-begin',
'-I' + meson.current_source_dir() + '/..',
'-I' + meson.current_build_dir() + '/..',
'--cflags-end']
endif
gst_incdirs += [configinc] if build_gir
gst_gen_sources += [gnome.generate_gir(libgst_shared, gst_gir_extra_args = gir_init_section + [ '--c-include=gst/gst.h' ]
sources : gst_sources + gst_headers + gst_enums + [gst_version_h], if meson.is_subproject()
namespace : 'Gst', # FIXME: There must be a better way to do this
nsversion : apiversion, # Need to pass the include path to find gst/gst.h and gst/gstenumtypes.h (built)
identifier_prefix : 'Gst', gst_gir_extra_args += ['--cflags-begin',
symbol_prefix : 'gst', '-I' + meson.current_source_dir() + '/..',
export_packages : 'gstreamer-1.0', '-I' + meson.current_build_dir() + '/..',
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0' ], '--cflags-end']
install : true,
extra_args : gst_gir_extra_args,
)]
endif endif
gst_incdirs += [configinc]
gst_gen_sources += [gnome.generate_gir(libgst,
sources : gst_sources + gst_headers + gst_enums + [gst_version_h],
namespace : 'Gst',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-1.0',
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0' ],
install : true,
extra_args : gst_gir_extra_args,
)]
endif endif
gst_dep = declare_dependency(link_with : libgst, gst_dep = declare_dependency(link_with : libgst,

View file

@ -36,46 +36,33 @@ gst_base_headers = [
'gsttypefindhelper.h', 'gsttypefindhelper.h',
] ]
if libtype != 'shared'
gst_base_static = static_library('gstbase-@0@'.format(apiversion),
gst_base_sources,
c_args : gst_c_args,
install : true,
include_directories : [configinc, libsinc],
dependencies : [gobject_dep, glib_dep, gst_dep],
)
gst_base = gst_base_static
endif
gst_base_gen_sources = [] gst_base_gen_sources = []
if libtype != 'static' gst_base = library('gstbase-@0@'.format(apiversion),
gst_base_shared = shared_library('gstbase-@0@'.format(apiversion), gst_base_sources,
gst_base_sources, c_args : gst_c_args,
c_args : gst_c_args, version : libversion,
version : libversion, soversion : soversion,
soversion : soversion, install : true,
include_directories : [configinc, libsinc],
dependencies : [gobject_dep, glib_dep, gst_dep],
)
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/base/base.h' ]
gst_base_gen_sources += [gnome.generate_gir(gst_base,
sources : gst_base_sources + gst_base_headers,
namespace : 'GstBase',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-base-1.0',
dependencies : [gst_dep],
include_directories : [configinc, libsinc, privinc],
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gst-1.0'],
install : true, install : true,
include_directories : [configinc, libsinc], extra_args : gst_gir_extra_args,
dependencies : [gobject_dep, glib_dep, gst_dep], )]
)
gst_base = gst_base_shared
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/base/base.h' ]
gst_base_gen_sources += [gnome.generate_gir(gst_base_shared,
sources : gst_base_sources + gst_base_headers,
namespace : 'GstBase',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-base-1.0',
dependencies : [gst_dep],
include_directories : [configinc, libsinc, privinc],
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gst-1.0'],
install : true,
extra_args : gst_gir_extra_args,
)]
endif
endif endif
gst_base_dep = declare_dependency(link_with : gst_base, gst_base_dep = declare_dependency(link_with : gst_base,

View file

@ -35,47 +35,33 @@ controller_enums = gnome.mkenums_simple('controller-enumtypes',
gstcontroller_c = controller_enums[0] gstcontroller_c = controller_enums[0]
gstcontroller_h = controller_enums[1] gstcontroller_h = controller_enums[1]
if libtype != 'shared'
gst_controller_static = static_library('gstcontroller-@0@'.format(apiversion),
gst_controller_sources, gstcontroller_h, gstcontroller_c,
c_args : gst_c_args,
install : true,
include_directories : [configinc, libsinc],
dependencies : [gobject_dep, glib_dep, mathlib, gst_dep],
)
gst_controller = gst_controller_static
endif
gst_controller_gen_sources = [gstcontroller_h] gst_controller_gen_sources = [gstcontroller_h]
if libtype != 'static' gst_controller = library('gstcontroller-@0@'.format(apiversion),
gst_controller_shared = shared_library('gstcontroller-@0@'.format(apiversion), gst_controller_sources, gstcontroller_h, gstcontroller_c,
gst_controller_sources, gstcontroller_h, gstcontroller_c, c_args : gst_c_args,
c_args : gst_c_args, install : true,
version : libversion,
soversion : soversion,
include_directories : [configinc, libsinc],
dependencies : [gobject_dep, glib_dep, mathlib, gst_dep],
)
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/controller/controller.h' ]
gst_controller_gir = gnome.generate_gir(gst_controller,
sources : gst_controller_sources + gst_controller_headers + [gstcontroller_h] + [gstcontroller_c],
namespace : 'GstController',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-controller-1.0',
dependencies : [gst_dep],
include_directories : [configinc, libsinc, privinc],
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gst-1.0'],
install : true, install : true,
version : libversion, extra_args : gst_gir_extra_args,
soversion : soversion,
include_directories : [configinc, libsinc],
dependencies : [gobject_dep, glib_dep, mathlib, gst_dep],
) )
gst_controller = gst_controller_shared gst_controller_gen_sources += [gst_controller_gir]
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/controller/controller.h' ]
gst_controller_gir = gnome.generate_gir(gst_controller_shared,
sources : gst_controller_sources + gst_controller_headers + [gstcontroller_h] + [gstcontroller_c],
namespace : 'GstController',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-controller-1.0',
dependencies : [gst_dep],
include_directories : [configinc, libsinc, privinc],
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gst-1.0'],
install : true,
extra_args : gst_gir_extra_args,
)
gst_controller_gen_sources += [gst_controller_gir]
endif
endif endif
gst_controller_dep = declare_dependency(link_with : gst_controller, gst_controller_dep = declare_dependency(link_with : gst_controller,

View file

@ -22,46 +22,33 @@ gst_net_headers = [
] ]
install_headers(gst_net_headers, subdir : 'gstreamer-1.0/gst/net/') install_headers(gst_net_headers, subdir : 'gstreamer-1.0/gst/net/')
if libtype != 'shared'
gst_net_static = static_library('gstnet-@0@'.format(apiversion),
gst_net_sources,
c_args : gst_c_args,
include_directories : [configinc, libsinc],
install : true,
dependencies : [gio_dep, gst_base_dep],
)
gst_net = gst_net_static
endif
gst_net_gen_sources = [] gst_net_gen_sources = []
if libtype != 'static' gst_net = library('gstnet-@0@'.format(apiversion),
gst_net_shared = shared_library('gstnet-@0@'.format(apiversion), gst_net_sources,
gst_net_sources, c_args : gst_c_args,
c_args : gst_c_args, include_directories : [configinc, libsinc],
version : libversion,
soversion : soversion,
install : true,
dependencies : [gio_dep, gst_base_dep],
)
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/net/net.h' ]
gst_net_gir = gnome.generate_gir(gst_net,
sources : gst_net_sources + gst_net_headers,
namespace : 'GstNet',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-net-1.0',
dependencies : [gst_base_dep],
include_directories : [configinc, libsinc], include_directories : [configinc, libsinc],
version : libversion, includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gio-2.0', 'Gst-1.0'],
soversion : soversion,
install : true, install : true,
dependencies : [gio_dep, gst_base_dep], extra_args : gst_gir_extra_args,
) )
gst_net = gst_net_shared gst_net_gen_sources += [gst_net_gir]
if build_gir
gst_gir_extra_args = gir_init_section + [ '--c-include=gst/net/net.h' ]
gst_net_gir = gnome.generate_gir(gst_net_shared,
sources : gst_net_sources + gst_net_headers,
namespace : 'GstNet',
nsversion : apiversion,
identifier_prefix : 'Gst',
symbol_prefix : 'gst',
export_packages : 'gstreamer-net-1.0',
dependencies : [gst_base_dep],
include_directories : [configinc, libsinc],
includes : ['GLib-2.0', 'GObject-2.0', 'GModule-2.0', 'Gio-2.0', 'Gst-1.0'],
install : true,
extra_args : gst_gir_extra_args,
)
gst_net_gen_sources += [gst_net_gir]
endif
endif endif
gst_net_dep = declare_dependency(link_with : gst_net, gst_net_dep = declare_dependency(link_with : gst_net,

View file

@ -24,7 +24,7 @@ soversion = 0
libversion = '@0@.@1@.0'.format(soversion, gst_version_minor * 100 + gst_version_micro) libversion = '@0@.@1@.0'.format(soversion, gst_version_minor * 100 + gst_version_micro)
prefix = get_option('prefix') prefix = get_option('prefix')
libtype = get_option('library_format') libtype = get_option('default_library')
libexecdir = get_option('libexecdir') libexecdir = get_option('libexecdir')
helpers_install_dir = join_paths(libexecdir, 'gstreamer-1.0') helpers_install_dir = join_paths(libexecdir, 'gstreamer-1.0')
@ -418,6 +418,10 @@ gir_init_section = [ '--add-init-section=extern void gst_init(gint*,gchar**);' +
'gst_init(NULL,NULL);' ] 'gst_init(NULL,NULL);' ]
gst_c_args = ['-DHAVE_CONFIG_H'] gst_c_args = ['-DHAVE_CONFIG_H']
# FIXME: This is only needed on windows and probably breaks when
# libtype=='both'. We should add this flag to static_c_args instead when Meson
# supports it: https://github.com/mesonbuild/meson/issues/3304
if libtype == 'static' if libtype == 'static'
gst_c_args += ['-DGST_STATIC_COMPILATION'] gst_c_args += ['-DGST_STATIC_COMPILATION']
endif endif

View file

@ -5,7 +5,6 @@ option('disable_examples', type : 'boolean', value : false)
option('disable_gst_debug', type : 'boolean', value : false) option('disable_gst_debug', type : 'boolean', value : false)
option('disable_registry', type : 'boolean', value : false) option('disable_registry', type : 'boolean', value : false)
option('disable_tracer_hooks', type : 'boolean', value : false) option('disable_tracer_hooks', type : 'boolean', value : false)
option('library_format', type : 'combo', choices : ['shared', 'static', 'both'], value : 'shared')
option('disable_introspection', option('disable_introspection',
type : 'boolean', value : false, type : 'boolean', value : false,
description : 'Whether to disable the introspection generation') description : 'Whether to disable the introspection generation')

View file

@ -25,26 +25,11 @@ gst_elements_sources = [
'gstvalve.c', 'gstvalve.c',
] ]
if libtype != 'shared' gst_elements = library('gstcoreelements',
gst_elements_static = static_library('gstcoreelements', gst_elements_sources,
gst_elements_sources, c_args : gst_c_args,
c_args : gst_c_args, include_directories : [configinc],
include_directories : [configinc], dependencies : [gobject_dep, glib_dep, gst_dep, gst_base_dep],
dependencies : [gobject_dep, glib_dep, gst_dep, gst_base_dep], install : true,
install : true, install_dir : join_paths(get_option('libdir'), 'gstreamer-1.0'),
install_dir : join_paths(get_option('libdir'), 'gstreamer-1.0'), )
)
gst_elements = gst_elements_static
endif
if libtype != 'static'
gst_elements_shared = shared_library('gstcoreelements',
gst_elements_sources,
c_args : gst_c_args,
include_directories : [configinc],
dependencies : [gobject_dep, glib_dep, gst_dep, gst_base_dep],
install : true,
install_dir : join_paths(get_option('libdir'), 'gstreamer-1.0'),
)
gst_elements = gst_elements_shared
endif