Add support for Meson as alternative/parallel build system

https://github.com/mesonbuild/meson
This commit is contained in:
Thibault Saunier 2016-09-05 11:30:43 -03:00
parent df995fad7b
commit 16f971226d
6 changed files with 161 additions and 0 deletions

10
config.h.meson Normal file
View file

@ -0,0 +1,10 @@
#mesondefine PACKAGE
#mesondefine VERSION
#mesondefine GST_PACKAGE_NAME
#mesondefine PACKAGE_NAME
#mesondefine GST_API_VERSION
#mesondefine PLUGINDIR
#mesondefine PY_LIB_LOC
#mesondefine PY_ABI_FLAGS
#mesondefine PY_LIB_SUFFIX
#mesondefine PYTHON_VERSION

1
gi/meson.build Normal file
View file

@ -0,0 +1 @@
subdir('overrides')

18
gi/overrides/meson.build Normal file
View file

@ -0,0 +1,18 @@
pysources = ['Gst.py', 'GstPbutils.py']
install_data(pysources,
install_dir: pygi_override_dir)
gstpython = shared_library('_gi_gst',
sources: ['gstmodule.c'],
name_prefix: '',
name_suffix: py_so_suffix,
install: true,
install_dir : pygi_override_dir,
dependencies : [gst_dep, python_dep, pygobject_dep])
# Workaround to get uninstalled working.
foreach source: pysources
run_command(python, '-c', 'import os; os.symlink("@0@/@1@", "@2@/@3@")'.format(
meson.current_source_dir(), source,
meson.current_build_dir(), source))
endforeach

56
meson.build Normal file
View file

@ -0,0 +1,56 @@
project('gst-python', 'c', 'cpp',
version : '1.9.2.1',
meson_version : '>= 0.33.0',
default_options : [ 'warning_level=1',
'c_std=gnu99',
'buildtype=debugoptimized' ])
gst_version = meson.project_version()
version_arr = gst_version.split('.')
gst_version_major = version_arr[0]
gst_version_minor = version_arr[1]
api_version = '@0@.0'.format(gst_version_major)
gst_req = '>= @0@.@1@.0'.format(gst_version_major, gst_version_minor)
gst_dep = dependency('gstreamer-1.0', version : gst_req,
fallback : ['gstreamer', 'gst_dep'])
gstbase_dep = dependency('gstreamer-base-1.0', version : gst_req,
fallback : ['gstreamer', 'gst_base_dep'])
gmodule_dep = dependency('gmodule-2.0')
pygobject_dep = dependency('pygobject-3.0 >= 3.0')
python_dep = dependency('python3')
python = find_program('python3')
pythondetector = find_program('pythondetector')
py_so_suffix = run_command(pythondetector, '--sosuffix').stdout().strip()
pygi_override_dir = run_command(pythondetector, '--pygi-overridedir').stdout().strip()
python_abi_flags = run_command(pythondetector, '--abiflags').stdout().strip()
pylib_loc = run_command(pythondetector, '--libloc').stdout().strip()
assert(pylib_loc != 'None', 'Python dynamic library path could not be determined')
pylib_suffix = 'so'
if host_machine.system() == 'windows'
pylib_suffix = 'dll'
elif host_machine.system() == 'darwin'
pylib_suffix = 'dylib'
endif
cdata = configuration_data()
cdata.set('PACKAGE', '"gst-python"')
cdata.set('VERSION', '"@0@"'.format(gst_version))
cdata.set('GST_PACKAGE_NAME', '"GStreamer Python"')
cdata.set('PACKAGE_NAME', '"GStreamer Python"')
cdata.set('GST_API_VERSION', '"@0@"'.format(api_version))
cdata.set('PLUGINDIR', '"@0@/gstreamer-1.0"'.format(get_option('libdir')))
cdata.set('PY_LIB_LOC', '"@0@"'.format(pylib_loc))
cdata.set('PY_ABI_FLAGS', '"@0@"'.format(python_abi_flags))
cdata.set('PY_LIB_SUFFIX', '"@0@"'.format(pylib_suffix))
cdata.set('PYTHON_VERSION', '"@0@"'.format(python_dep.version()))
configure_file(input : 'config.h.meson',
output : 'config.h',
configuration : cdata)
configinc = include_directories('.')
subdir('gi')
subdir('plugin')

8
plugin/meson.build Normal file
View file

@ -0,0 +1,8 @@
gst_elements_shared = shared_library('gstpythonplugin',
['gstpythonplugin.c'],
c_args : '-DHAVE_CONFIG_H -DPY_LIB_LOC=@0@'.format(pylib_loc),
include_directories : [configinc],
dependencies : [gst_dep, pygobject_dep, gstbase_dep, python_dep, gmodule_dep],
install : true,
install_dir : '@0@/gstreamer-1.0'.format(get_option('libdir')),
)

68
pythondetector Normal file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env python3
import os
import platform
import subprocess
import sys
from distutils import sysconfig
def get_python_abiflags():
try:
return subprocess.check_output([os.path.basename(sys.executable) + '-config',
'--abiflags']).decode(errors='ignore').strip()
except FileNotFoundError:
return ''
def get_python_libloc():
# OSX is a pain. Python as shipped by apple installs libpython in /usr/lib
# so we hardcode that. Other systems can use --with-libpython-dir to
# override this.
if platform.system().lower() == 'darwin':
return '/usr/lib'
python_libs = sysconfig.get_python_lib(standard_lib=1)
pylib_loc = python_libs + '/config'
pyversion = "%d.%d" % (sys.version_info.major, sys.version_info.minor)
abiflags = get_python_abiflags()
py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
if os.path.exists(os.path.join(py_sharedlib)):
return pylib_loc
pylib_loc = sys.prefix + '/lib64'
py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
if os.path.exists(os.path.join(py_sharedlib)):
return pylib_loc
pylib_loc = sys.prefix + '/lib'
py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
if os.path.exists(os.path.join(py_sharedlib)):
return pylib_loc
pylib_loc = '/usr/lib'
py_sharedlib = pylib_loc + '/libpython' + pyversion + abiflags + '.so'
if os.path.exists(os.path.join(py_sharedlib)):
return pylib_loc
return "None"
if __name__ == "__main__":
if len(sys.argv) > 2:
print("Only 1 argument accepted")
exit(1)
if sys.argv[1] == '--abiflags':
print(get_python_abiflags())
elif sys.argv[1] == '--sosuffix':
get = sysconfig.get_config_var
suffix = get("EXT_SUFFIX") or get("SO") or ".so"
print(suffix[1:])
elif sys.argv[1] == '--pygi-overridedir':
import gi
print(gi._overridesdir)
elif sys.argv[1] == '--libloc':
print(get_python_libloc())