#!/usr/bin/env bash # Makes sure the Orbbec K4A wrapper is built for THIS platform, and prints where # it is as K4A_WRAPPER_DIR=... for build_sdk.sh (the recorder example needs its # headers) and for the recorder's runtime rpath (its libk4a.so/libk4arecord.so). # # This is the libk4a provider — Orbbec's own, NOT Microsoft's Azure Kinect SDK. # It bundles its own OrbbecSDK internally, so it builds standalone. The recorder # dlopens the libk4a it produces (RTLD_DEEPBIND) rather than link-time linking it, # which is why only its build/lib path matters at runtime, not link time. # # Reuses an existing build (leaving a working node untouched) or clones + builds. set -euo pipefail here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) eval "$("$here/detect_platform.sh")" REPO_URL="${OB_K4A_REPO:-https://github.com/orbbec/OrbbecSDK-K4A-Wrapper}" # The tag the Nano runs. A caller can override to one known to build on a newer # JetPack. REF="${OB_K4A_REF:-v1.10.4}" find_wrapper() { local d="$1" [[ -f "$d/include/k4a/k4a.h" ]] || return 1 [[ -f "$d/build/lib/libk4a.so" ]] || return 1 echo "$d" } for candidate in "${K4A_WRAPPER_DIR:-}" \ "$HOME/OrbbecSDK-K4A-Wrapper" \ "$HOME/Downloads/OrbbecSDK-K4A-Wrapper"; do [[ -z "$candidate" ]] && continue if find_wrapper "$candidate" >/dev/null 2>&1; then echo ">> Wrapper K4A deja bati, reutilise: $candidate" >&2 echo "K4A_WRAPPER_DIR=$candidate" exit 0 fi done dir="${K4A_WRAPPER_DIR:-$HOME/OrbbecSDK-K4A-Wrapper}" echo ">> Wrapper K4A absent — clone et compilation (JetPack ${JETPACK}, ${SOC})" >&2 echo ">> ${REPO_URL} @ ${REF} -> ${dir}" >&2 if [[ ! -d "$dir/.git" ]]; then # --recursive: the wrapper carries its OrbbecSDK and depth engine as submodules. git clone --recursive --depth 1 --branch "$REF" "$REPO_URL" "$dir" >&2 fi mkdir -p "$dir/build" ( cd "$dir/build" cmake .. -DCMAKE_BUILD_TYPE=Release >&2 make -j"$(nproc)" k4a k4arecord >&2 ) if ! find_wrapper "$dir" >/dev/null 2>&1; then cat >&2 <> Wrapper K4A bati: $dir" >&2 echo "K4A_WRAPPER_DIR=$dir"