Skip to content

support compiling against external libraries #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded

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

## Compile against an external libcamera

1. You must be on a Raspberry Pi, running Raspberry Pi OS Bullseye

2. Install build dependencies:

```sh
sudo apt install -y \
g++ \
xxd \
wget \
git \
cmake \
meson \
pkg-config \
python3-jinja2 \
python3-yaml \
python3-ply
```

3. Make sure that the development package of your libcamera is installed, otherwise install the default one:

```sh
sudo apt install -y \
libcamera-dev
```

3. Build with `--wrap-mode=default` (that disables embedded libraries):

```sh
meson setup --wrap-mode=default build && DESTDIR=./prefix ninja -C build install
```

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

## Cross-compile

1. You can be on any machine you like
Expand Down
41 changes: 23 additions & 18 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ project(
'cpp_std=c++17',
'buildtype=release',
'strip=true',
'prefix=/'
'prefix=/',
'wrap_mode=forcefallback'
]
)

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

x264 = subproject(
x264_dep = dependency(
'x264',
fallback : ['x264', 'libx264_dep'],
default_options : [
'default_library=static',
'cli=false',
Expand All @@ -43,10 +45,10 @@ x264 = subproject(
'bit-depth=8',
'chroma-format=all'
])
x264_dep = x264.get_variable('libx264_dep')

libcamera = subproject(
libcamera_dep = dependency(
'libcamera',
fallback : ['libcamera', 'libcamera_public'],
default_options : [
'buildtype=release',
'strip=true',
Expand All @@ -62,21 +64,24 @@ libcamera = subproject(
'tracing=disabled',
'udev=disabled'
])
libcamera_dep = libcamera.get_variable('libcamera_public')

cmake = import('cmake')
freetype_vars = cmake.subproject_options()
freetype_vars.add_cmake_defines({
'CMAKE_BUILD_TYPE': 'Release',
'BUILD_SHARED_LIBS': false,
'FT_DISABLE_ZLIB': true,
'FT_DISABLE_BZIP2': true,
'FT_DISABLE_PNG': true,
'FT_DISABLE_HARFBUZZ': true,
'FT_DISABLE_BROTLI': true
})
freetype = cmake.subproject('freetype', options : freetype_vars)
freetype_dep = freetype.dependency('freetype')
freetype_dep = dependency('freetype2', required : false)
if not freetype_dep.found()
cmake = import('cmake')
freetype_vars = cmake.subproject_options()
freetype_vars.set_override_option('wrap_mode', 'none')
freetype_vars.add_cmake_defines({
'CMAKE_BUILD_TYPE': 'Release',
'BUILD_SHARED_LIBS': false,
'FT_DISABLE_ZLIB': true,
'FT_DISABLE_BZIP2': true,
'FT_DISABLE_PNG': true,
'FT_DISABLE_HARFBUZZ': true,
'FT_DISABLE_BROTLI': true
})
freetype_proj = cmake.subproject('freetype', options : freetype_vars)
freetype_dep = freetype_proj.dependency('freetype')
endif

dependencies = [
x264_dep,
Expand Down
12 changes: 8 additions & 4 deletions post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ else
fi

mkdir -p $OUT_DIR
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/share/libcamera/ipa $OUT_DIR/ipa_conf
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera $OUT_DIR/ipa_module
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera-base.so.9.9 $OUT_DIR/
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 $OUT_DIR/

if [ -f ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 ]; then
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/share/libcamera/ipa $OUT_DIR/ipa_conf
cp -r ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera $OUT_DIR/ipa_module
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera-base.so.9.9 $OUT_DIR/
cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/lib/libcamera.so.9.9 $OUT_DIR/
fi

cp ${DESTDIR}/${MESON_INSTALL_PREFIX}/bin/mtxrpicam $OUT_DIR/