Files
Jetson/recorder/CMakeLists.txt
T
AngePierreandClaude Opus 5 23b30ac1e8 Add the MKV recorder so a node can Record, not only preview
The recorder was the gap: it is FTF's own customised SDK example (a 1139-line
K4A MKV writer), not a stock sample, and it lived only in one machine's build
tree. Bring its source into the repo and build it as part of install.

It writes K4A-format MKV — the format the rest of Ithaca reads — so it stays,
and gets its libk4a from the Orbbec K4A wrapper rather than Microsoft's Azure
Kinect SDK, which is set aside. build_k4a_wrapper.sh builds that wrapper;
build_sdk.sh injects the recorder into the SDK examples tree and builds it there
against the wrapper (it depends on the SDK's own cmake targets). Found by rpath
at runtime, so no LD_LIBRARY_PATH.

install.sh now builds wrapper -> SDK+recorder -> preview server, each reusing an
existing build so the Nano is untouched. If the wrapper is unavailable the
install still completes preview-only and says so.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 16:21:44 +02:00

116 lines
4.8 KiB
CMake

# Copyright (c) Orbbec Inc. / French Touch Factory. All Rights Reserved.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.10)
project(ob_stream_depth_color_k4arec_pipeline)
if(WIN32)
set(K4A_WRAPPER_DIR
"C:/Ithaca_Projects/RGBD/Clone K4A Depot V2/OrbbecSDK-K4A-Wrapper"
CACHE PATH "Path to OrbbecSDK-K4A-Wrapper root directory")
# Windows: the wrapper's own out-of-source build dir is conventionally "Build",
# producing MSVC import libs (k4a.lib/k4arecord.lib) alongside the DLLs in bin/.
set(K4A_WRAPPER_BUILD_SUBDIR "Build")
else()
set(K4A_WRAPPER_DIR
"$ENV{HOME}/Downloads/OrbbecSDK-K4A-Wrapper"
CACHE PATH "Path to OrbbecSDK-K4A-Wrapper root directory")
# Linux: built with a lowercase "build" dir; shared libs land in lib/, not bin/.
set(K4A_WRAPPER_BUILD_SUBDIR "build")
endif()
if(NOT EXISTS "${K4A_WRAPPER_DIR}/include/k4a/k4a.h")
message(WARNING
"${PROJECT_NAME}: K4A wrapper not found at '${K4A_WRAPPER_DIR}'. "
"Set K4A_WRAPPER_DIR to the OrbbecSDK-K4A-Wrapper root. Skipping.")
return()
endif()
add_executable(${PROJECT_NAME} depth_color_k4arec_pipeline.cpp)
# C++14: the source uses digit-separator literals (2'000'000ULL); C++11 rejects them.
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
# rightW/rightH (Spout) and pinCpu/pinCore (SetProcessAffinityMask) are only read
# inside #ifdef _WIN32 blocks, so non-Windows builds see them as set-but-unused —
# harmless, but this SDK's own linux_config.cmake enables -Werror globally.
if(NOT WIN32)
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-but-set-variable)
endif()
# SYSTEM: the K4A wrapper's public headers have GCC-pedantic issues (stray ';'
# after struct/enum decls) that -Wpedantic -Werror (set globally by this SDK's
# own linux_config.cmake) would otherwise turn into hard errors. -isystem makes
# GCC/Clang suppress warnings from headers found there.
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
"${K4A_WRAPPER_DIR}/include"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/src/orbbec/include"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/src/orbbec/record/sdk/include"
)
if(WIN32)
set(K4A_LIB "${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4a.lib")
set(K4ARECORD_LIB "${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4arecord.lib")
endif()
target_link_libraries(${PROJECT_NAME}
ob::${OB_SDK_LIB_NAME}
ob::examples::utils
${OpenCV_LIBS}
$<$<BOOL:${WIN32}>:${K4A_LIB}>
$<$<BOOL:${WIN32}>:${K4ARECORD_LIB}>
$<$<BOOL:${WIN32}>:SpoutDX>
# Linux: libk4a.so/libk4arecord.so are dlopen'd (RTLD_DEEPBIND) at runtime
# instead of link-time linked — see the dlopen comment block near the top
# of depth_color_k4arec_pipeline.cpp for why. Needs libdl for dlopen/dlsym.
$<$<NOT:$<BOOL:${WIN32}>>:dl>
)
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "examples")
if(MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()
if(NOT WIN32)
# Linux: libk4a.so/libk4arecord.so aren't on the system search path — rpath
# the wrapper's build/lib so the binary finds them without LD_LIBRARY_PATH.
# BUILD_RPATH (not INSTALL_RPATH+BUILD_WITH_INSTALL_RPATH) so this ADDS to
# CMake's automatic build-tree rpath instead of replacing it — the automatic
# one is what makes libOrbbecSDK.so (built earlier in this same tree) found.
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH "${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/lib")
endif()
if(WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4a.dll"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4arecord.dll"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/depthengine_2_0.dll"
$<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMENT "Copying K4A wrapper DLLs"
)
endif()
if(WIN32 AND TARGET opencv_world)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:opencv_world>"
$<TARGET_FILE_DIR:${PROJECT_NAME}>
COMMENT "Copying OpenCV DLL"
)
endif()
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
if(WIN32)
install(FILES
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4a.dll"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/k4arecord.dll"
"${K4A_WRAPPER_DIR}/${K4A_WRAPPER_BUILD_SUBDIR}/bin/depthengine_2_0.dll"
DESTINATION bin
)
endif()
if(WIN32 AND TARGET opencv_world)
install(FILES "$<TARGET_FILE:opencv_world>" DESTINATION bin)
endif()