summaryrefslogtreecommitdiff
path: root/src/py/libcamera/meson.build
blob: 4807ca7d75ed36f8f3f12f6425ebfcd7b1cee006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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

pybind11_dep = dependency('pybind11', required : get_option('pycamera'))

if not pybind11_dep.found()
    pycamera_enabled = false
    subdir_done()
endif

pycamera_enabled = true

pycamera_sources = files([
    'py_camera_manager.cpp',
    'py_color_space.cpp',
    'py_enums.cpp',
    'py_geometry.cpp',
    'py_helpers.cpp',
    'py_main.cpp',
    'py_transform.cpp',
])

# Generate controls

gen_py_controls_input_files = []
gen_py_controls_template = files('py_controls_generated.cpp.in')

gen_py_controls = files('gen-py-controls.py')

foreach file : controls_files
    gen_py_controls_input_files += files('../../libcamera/' + file)
endforeach

pycamera_sources += custom_target('py_gen_controls',
                                  input : gen_py_controls_input_files,
                                  output : ['py_controls_generated.cpp'],
                                  command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@',
                                             '-t', gen_py_controls_template, '@INPUT@'])

# Generate properties

gen_py_property_enums_input_files = []
gen_py_properties_template = files('py_properties_generated.cpp.in')

foreach file : properties_files
    gen_py_property_enums_input_files += files('../../libcamera/' + file)
endforeach

pycamera_sources += custom_target('py_gen_properties',
                                  input : gen_py_property_enums_input_files,
                                  output : ['py_properties_generated.cpp'],
                                  command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@',
                                             '-t', gen_py_properties_template, '@INPUT@'])

# Generate formats

gen_py_formats_input_files = files([
    '../../libcamera/formats.yaml',
    'py_formats_generated.cpp.in',
])

gen_py_formats = files('gen-py-formats.py')

pycamera_sources += custom_target('py_gen_formats',
                                  input : gen_py_formats_input_files,
                                  output : ['py_formats_generated.cpp'],
                                  command : [gen_py_formats, '-o', '@OUTPUT@', '@INPUT@'])

pycamera_deps = [
    libcamera_private,
    py3_dep,
    pybind11_dep,
]

pycamera_args = [
    '-fvisibility=hidden',
    '-Wno-shadow',
    '-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT',
]

destdir = get_option('libdir') / ('python' + py3_dep.version()) / 'site-packages' / 'libcamera'

pycamera = shared_module('_libcamera',
                         pycamera_sources,
                         install : true,
                         install_dir : destdir,
                         install_tag : 'python-runtime',
                         name_prefix : '',
                         dependencies : pycamera_deps,
                         cpp_args : pycamera_args)

# Create symlinks from the build dir to the source dir so that we can use the
# Python module directly from the build dir.

run_command('ln', '-fsrT', files('__init__.py'),
            meson.current_build_dir() / '__init__.py',
            check : true)

run_command('ln', '-fsrT', meson.current_source_dir() / 'utils',
            meson.current_build_dir() / 'utils',
            check : true)

install_data(['__init__.py'],
             install_dir : destdir,
             install_tag : 'python-runtime')

# \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