diff options
author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2022-05-09 13:10:20 +0300 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2022-05-10 13:53:43 +0200 |
commit | 8aa02271fd716ed046970a0b1f89176963303f50 (patch) | |
tree | da81430f03dc967addbdec3c143001b1490c751d /src/py/libcamera/meson.build | |
parent | 5cb17e0c138aa3afef92e8d95d876d2bd94516ed (diff) |
Add Python bindings
Add libcamera Python bindings. pybind11 is used to generate the C++ <->
Python layer.
We use pybind11 'smart_holder' version to avoid issues with private
destructors and shared_ptr. There is also an alternative solution here:
https://github.com/pybind/pybind11/pull/2067
Only a subset of libcamera classes are exposed. Implementing and testing
the wrapper classes is challenging, and as such only classes that I have
needed have been added so far.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/py/libcamera/meson.build')
-rw-r--r-- | src/py/libcamera/meson.build | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build new file mode 100644 index 00000000..edf4a629 --- /dev/null +++ b/src/py/libcamera/meson.build @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: CC0-1.0 + +py3_dep = dependency('python3', required : get_option('pycamera')) + +if not py3_dep.found() + pycamera_enabled = false + subdir_done() +endif + +pycamera_enabled = true + +pybind11_proj = subproject('pybind11') +pybind11_dep = pybind11_proj.get_variable('pybind11_dep') + +pycamera_sources = files([ + 'pyenums.cpp', + 'pymain.cpp', +]) + +pycamera_deps = [ + libcamera_public, + py3_dep, + pybind11_dep, +] + +pycamera_args = [ + '-fvisibility=hidden', + '-Wno-shadow', + '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT', + '-DLIBCAMERA_BASE_PRIVATE', +] + +destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera' + +pycamera = shared_module('_libcamera', + pycamera_sources, + install : true, + install_dir : destdir, + name_prefix : '', + dependencies : pycamera_deps, + cpp_args : pycamera_args) + +run_command('ln', '-fsT', '../../../../src/py/libcamera/__init__.py', + meson.current_build_dir() / '__init__.py', + check: true) + +install_data(['__init__.py'], install_dir : destdir) + +# \todo Generate stubs when building. See https://peps.python.org/pep-0484/#stub-files +# Note: Depends on pybind11-stubgen. To generate pylibcamera stubs: +# $ PYTHONPATH=build/src/py pybind11-stubgen --no-setup-py -o build/src/py libcamera +# $ mv build/src/py/libcamera-stubs/* build/src/py/libcamera/ |