From e8b015ac9754efefd7f7fee13a2b0d157b4d112a Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Wed, 21 Aug 2024 11:48:52 +0200 Subject: [PATCH] support compiling against external libraries (#12) --- README.md | 35 +++++++++++++++++++++++++++++++++++ meson.build | 41 +++++++++++++++++++++++------------------ post_install.sh | 12 ++++++++---- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 914ccf7..3843a29 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/meson.build b/meson.build index a5bbdd6..472579b 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,8 @@ project( 'cpp_std=c++17', 'buildtype=release', 'strip=true', - 'prefix=/' + 'prefix=/', + 'wrap_mode=forcefallback' ] ) @@ -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', @@ -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', @@ -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, diff --git a/post_install.sh b/post_install.sh index 4ec074f..b38a247 100755 --- a/post_install.sh +++ b/post_install.sh @@ -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/