Skip to content

Commit e8b015a

Browse files
authored
support compiling against external libraries (#12)
1 parent 2ec6715 commit e8b015a

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,41 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded
3434

3535
This will produce the `build/mtxrpicam_32` or `build/mtxrpicam_64` folder (depending on the architecture).
3636

37+
## Compile against an external libcamera
38+
39+
1. You must be on a Raspberry Pi, running Raspberry Pi OS Bullseye
40+
41+
2. Install build dependencies:
42+
43+
```sh
44+
sudo apt install -y \
45+
g++ \
46+
xxd \
47+
wget \
48+
git \
49+
cmake \
50+
meson \
51+
pkg-config \
52+
python3-jinja2 \
53+
python3-yaml \
54+
python3-ply
55+
```
56+
57+
3. Make sure that the development package of your libcamera is installed, otherwise install the default one:
58+
59+
```sh
60+
sudo apt install -y \
61+
libcamera-dev
62+
```
63+
64+
3. Build with `--wrap-mode=default` (that disables embedded libraries):
65+
66+
```sh
67+
meson setup --wrap-mode=default build && DESTDIR=./prefix ninja -C build install
68+
```
69+
70+
This will produce the `build/mtxrpicam_32` or `build/mtxrpicam_64` folder (depending on the architecture).
71+
3772
## Cross-compile
3873

3974
1. You can be on any machine you like

meson.build

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ project(
88
'cpp_std=c++17',
99
'buildtype=release',
1010
'strip=true',
11-
'prefix=/'
11+
'prefix=/',
12+
'wrap_mode=forcefallback'
1213
]
1314
)
1415

@@ -33,8 +34,9 @@ cpp_args = [
3334
add_project_arguments(c_args, language : 'c')
3435
add_project_arguments(cpp_args, language : 'cpp')
3536

36-
x264 = subproject(
37+
x264_dep = dependency(
3738
'x264',
39+
fallback : ['x264', 'libx264_dep'],
3840
default_options : [
3941
'default_library=static',
4042
'cli=false',
@@ -43,10 +45,10 @@ x264 = subproject(
4345
'bit-depth=8',
4446
'chroma-format=all'
4547
])
46-
x264_dep = x264.get_variable('libx264_dep')
4748

48-
libcamera = subproject(
49+
libcamera_dep = dependency(
4950
'libcamera',
51+
fallback : ['libcamera', 'libcamera_public'],
5052
default_options : [
5153
'buildtype=release',
5254
'strip=true',
@@ -62,21 +64,24 @@ libcamera = subproject(
6264
'tracing=disabled',
6365
'udev=disabled'
6466
])
65-
libcamera_dep = libcamera.get_variable('libcamera_public')
6667

67-
cmake = import('cmake')
68-
freetype_vars = cmake.subproject_options()
69-
freetype_vars.add_cmake_defines({
70-
'CMAKE_BUILD_TYPE': 'Release',
71-
'BUILD_SHARED_LIBS': false,
72-
'FT_DISABLE_ZLIB': true,
73-
'FT_DISABLE_BZIP2': true,
74-
'FT_DISABLE_PNG': true,
75-
'FT_DISABLE_HARFBUZZ': true,
76-
'FT_DISABLE_BROTLI': true
77-
})
78-
freetype = cmake.subproject('freetype', options : freetype_vars)
79-
freetype_dep = freetype.dependency('freetype')
68+
freetype_dep = dependency('freetype2', required : false)
69+
if not freetype_dep.found()
70+
cmake = import('cmake')
71+
freetype_vars = cmake.subproject_options()
72+
freetype_vars.set_override_option('wrap_mode', 'none')
73+
freetype_vars.add_cmake_defines({
74+
'CMAKE_BUILD_TYPE': 'Release',
75+
'BUILD_SHARED_LIBS': false,
76+
'FT_DISABLE_ZLIB': true,
77+
'FT_DISABLE_BZIP2': true,
78+
'FT_DISABLE_PNG': true,
79+
'FT_DISABLE_HARFBUZZ': true,
80+
'FT_DISABLE_BROTLI': true
81+
})
82+
freetype_proj = cmake.subproject('freetype', options : freetype_vars)
83+
freetype_dep = freetype_proj.dependency('freetype')
84+
endif
8085

8186
dependencies = [
8287
x264_dep,

post_install.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ else
99
fi
1010

1111
mkdir -p $OUT_DIR
12-
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/share/libcamera/ipa $OUT_DIR/ipa_conf
13-
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera $OUT_DIR/ipa_module
14-
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera-base.so.9.9 $OUT_DIR/
15-
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 $OUT_DIR/
12+
13+
if [ -f ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 ]; then
14+
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/share/libcamera/ipa $OUT_DIR/ipa_conf
15+
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera $OUT_DIR/ipa_module
16+
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera-base.so.9.9 $OUT_DIR/
17+
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 $OUT_DIR/
18+
fi
19+
1620
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/bin/mtxrpicam $OUT_DIR/

0 commit comments

Comments
 (0)