Skip to content

Third‐party Libraries

andrestraker edited this page Dec 18, 2025 · 2 revisions

GENERATED BY COPILOT - REVIEW IS NEEDED.

libaditof SDK – Third‑Party Dependencies and CMake Options

This page lists the main third‑party dependencies used by the SDK library (sdk/) and explains which CMake options enable or disable them.

All references are based on:

  • Top‑level CMakeLists.txt
  • sdk/CMakeLists.txt

1. Always‑used dependencies

These are linked into the aditof SDK library unconditionally (no CMake options).

1.1 json‑c

Where: sdk/CMakeLists.txt

target_link_libraries(${PROJECT_NAME} PRIVATE json-c)

# json-c may need libbsd on Linux/Unix systems
if(UNIX AND NOT APPLE)
    find_library(BSD_LIBRARY bsd)
    if(BSD_LIBRARY)
        target_link_libraries(${PROJECT_NAME} PRIVATE ${BSD_LIBRARY})
    endif()
endif()

# Add json-c include directories (both source and build for generated headers)
target_include_directories(${PROJECT_NAME} PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/third-party/json-c
    ${CMAKE_BINARY_DIR}/libaditof/dependencies/third-party/json-c
)
  • Always used by the core SDK (aditof).
  • On non‑macOS Unix, libbsd is linked if found (see next subsection).

1.2 crc32

Where: sdk/CMakeLists.txt

target_link_libraries(${PROJECT_NAME} PRIVATE crc32)
  • CRC32 library built under dependencies/.
  • Always linked into aditof.

1.3 libbsd (optional, platform‑dependent)

Where: sdk/CMakeLists.txt

if(UNIX AND NOT APPLE)
    find_library(BSD_LIBRARY bsd)
    if(BSD_LIBRARY)
        target_link_libraries(${PROJECT_NAME} PRIVATE ${BSD_LIBRARY})
    endif()
endif()
  • Used only on UNIX (non‑macOS) if the bsd library is available.
  • No dedicated CMake option; purely platform‑driven.

2. Logging – glog (optional)

2.1 Enabling glog

Top‑level option:

option(WITH_GLOG_DEPENDENCY "Build with GLOG dependency to be used for logging?" OFF)

When WITH_GLOG_DEPENDENCY=ON:

Top level (CMakeLists.txt):

if(WITH_GLOG_DEPENDENCY)
    add_definitions(-DUSE_GLOG)
    if(WITH_SUBMODULES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/glog/.git" )
        # build glog from submodule
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glog)
        ...
    endif()
endif()

SDK level (sdk/CMakeLists.txt):

if(WITH_GLOG_DEPENDENCY)
    # Prevent macro name collisions between custom log.h and glog
    add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES)

    if(NOT WITH_SUBMODULES AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../glog/.git")
        find_package(glog 0.3.5 REQUIRED)
    else()
        target_link_libraries(${PROJECT_NAME} PUBLIC glog)
    endif()
endif()

Summary:

  • Controlled by: WITH_GLOG_DEPENDENCY (default OFF).
  • If ON:
    • -DUSE_GLOG and -DGLOG_NO_ABBREVIATED_SEVERITIES are defined.
    • glog is either:
      • Built from the glog submodule (WITH_SUBMODULES=ON), or
      • Found on the system with find_package(glog 0.3.5 REQUIRED).

3. Network / RPC stack

These dependencies are only used when the network interface is enabled.

3.1 Protobuf

Top‑level options:

option(WITH_NETWORK "Build network interface?" ON)
option(WITH_PROTOBUF_DEPENDENCY "Build with PROTOBUF dependency?" ON)

Top‑level behavior:

if(NOT WITH_PROTOBUF_DEPENDENCY)
    if(NOT ON_TARGET)
        message(FATAL_ERROR "SDK can be built without protobuf only on target builds!")
    endif()
else()
    add_definitions(-DUSE_PROTOBUF)
    if(WITH_NETWORK AND WITH_SUBMODULES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/protobuf/.git" )
        # build protobuf from submodule
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/protobuf/cmake)
    endif()
endif()

SDK‑level behavior:

if(WITH_NETWORK AND WITH_PROTOBUF_DEPENDENCY)
    if(NOT WITH_SUBMODULES AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../protobuf/.git")
        find_package(Protobuf 3.9.0 REQUIRED)
    else()
        target_link_libraries(${PROJECT_NAME} PUBLIC libprotobuf)
    endif()

    target_sources(${PROJECT_NAME} PRIVATE ${PROTO_HDRS} ${PROTO_SRCS})
    target_include_directories(${PROJECT_NAME} PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}
    )

    # Network buffer.proto -> buffer.pb.h / buffer.pb.cc
    set(NET_PROTO_HRDS "${CMAKE_CURRENT_SOURCE_DIR}/buffer.pb.h")
    set(NET_PROTO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/buffer.pb.cc")

    add_custom_command(OUTPUT ${NET_PROTO_HRDS} ${NET_PROTO_SRCS}
        COMMAND protoc buffer.proto
                -I ${CMAKE_CURRENT_SOURCE_DIR}/src/connections/network
                --cpp_out=.
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

    target_sources(${PROJECT_NAME} PRIVATE ${NET_PROTO_HRDS} ${NET_PROTO_SRCS})
    target_include_directories(${PROJECT_NAME} PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}
    )
endif()

Summary:

  • Used when:
    • WITH_NETWORK=ON and WITH_PROTOBUF_DEPENDENCY=ON (default).
  • Provides:
    • -DUSE_PROTOBUF definition.
    • libprotobuf from:
      • The protobuf submodule (WITH_SUBMODULES=ON), or
      • A system install via find_package(Protobuf 3.9.0 REQUIRED).

3.2 ZeroMQ (libzmq) and cppzmq

Top‑level configuration for libzmq submodule:

if(WITH_SUBMODULES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libzmq/.git")
    set(BUILD_SHARED OFF CACHE BOOL "Disable shared libs")
    set(BUILD_STATIC ON CACHE BOOL "Build Static library")
    set(BUILD_TESTS OFF CACHE BOOL "Disable building tests for libzmq")
    set(POSITION_INDEPENDENT_CODE 1)
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libzmq)
    unset(POSITION_INDEPENDENT_CODE)
endif()

SDK‑level behavior inside the network block:

if ( WITH_NETWORK )
    # Include cppzmq headers
    set(CPPZMQ_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../cppzmq")

    if(NOT WITH_SUBMODULES AND NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../libzmq/.git")
        find_package(ZeroMQ REQUIRED)
    else()
        include_directories(${CPPZMQ_INSTALL_DIR})
        target_link_libraries(${PROJECT_NAME} PUBLIC libzmq-static)
    endif()
endif()

Summary:

  • Used when:
    • WITH_NETWORK=ON and WITH_PROTOBUF_DEPENDENCY=ON (since this is in the network + protobuf block).
  • Behavior:
    • If WITH_SUBMODULES=ON and libzmq submodule exists:
      • libzmq-static is built and linked.
      • cppzmq headers are included from ../cppzmq.
    • Otherwise:
      • A system ZeroMQ install is required (find_package(ZeroMQ REQUIRED)).

4. Depth compute libraries (ToF processing)

These provide depth processing functionality either via closed‑source or open‑source libraries.

4.1 Options and platform detection

Top‑level options:

option(USE_DEPTH_COMPUTE_OPENSOURCE "Use an open source implementation?" OFF)
option(NXP "Set to ON when building on NXP" OFF)
option(NVIDIA "Set to ON when building on NVIDIA" OFF)

ON_TARGET is derived from NXP / NVIDIA:

set(ON_TARGET FALSE)
# if exactly one of NXP/NVIDIA is ON → ON_TARGET = TRUE

LIBTOFI path setup:

if(${ON_TARGET})
    if(USE_DEPTH_COMPUTE_OPENSOURCE)
        set(LIBTOFI_LIBDIR_PATH "${CMAKE_BINARY_DIR}/sdk/common/adi/depth-compute-opensource")
    else()
        if (NOT DEFINED LIBTOFI_LIBDIR_PATH)
            set(LIBTOFI_LIBDIR_PATH "${CMAKE_SOURCE_DIR}/../libs")
        endif()
    endif()
endif()

4.2 SDK‑level linking

Where: sdk/CMakeLists.txt

set(LIBTOFI_COMPUTE_CLOSED_SOURCE_PATH "${LIBTOFI_LIBDIR_PATH}/libtofi_compute.so")
set(LIBTOFI_CONFIG_CLOSED_SOURCE_PATH "${LIBTOFI_LIBDIR_PATH}/libtofi_config.so")

if ( ON_TARGET AND UNIX )
    if (NOT USE_DEPTH_COMPUTE_OPENSOURCE)
        add_library(libtofi_compute SHARED IMPORTED)
        set_target_properties(libtofi_compute PROPERTIES
            IMPORTED_LOCATION "${LIBTOFI_COMPUTE_CLOSED_SOURCE_PATH}"
            IMPORTED_NO_SONAME 1
        )

        add_library(libtofi_config SHARED IMPORTED)
        set_target_properties(libtofi_config PROPERTIES
            IMPORTED_LOCATION "${LIBTOFI_CONFIG_CLOSED_SOURCE_PATH}"
            IMPORTED_NO_SONAME 1
        )

        target_link_libraries(${PROJECT_NAME} PRIVATE libtofi_compute)
        target_link_libraries(${PROJECT_NAME} PRIVATE libtofi_config)
    else()
        target_link_libraries(${PROJECT_NAME} PRIVATE tofi_compute)
        target_link_libraries(${PROJECT_NAME} PRIVATE tofi_config)
    endif()
endif()

Open‑source depth compute build:

if(USE_DEPTH_COMPUTE_OPENSOURCE AND ON_TARGET)
    add_subdirectory(common/adi/depth-compute-opensource)
endif()

Summary:

  • Used only when building on target (ON_TARGET=TRUE, i.e. NXP or NVIDIA).
  • If USE_DEPTH_COMPUTE_OPENSOURCE=OFF (default on target):
    • SDK links imported shared libraries:
      • libtofi_compute.so
      • libtofi_config.so
    • These are expected under LIBTOFI_LIBDIR_PATH.
  • If USE_DEPTH_COMPUTE_OPENSOURCE=ON:
    • SDK builds and links open‑source tofi_compute and tofi_config from sdk/common/adi/depth-compute-opensource.

5. Python bindings – pybind11

This is only relevant if Python bindings are enabled.

5.1 Enabling Python bindings

Top‑level option:

option(WITH_PYTHON "Build python bindings?" ON)

Bindings CMake: bindings/python/CMakeLists.txt

add_subdirectory(pybind11)

pybind11_add_module(aditofpython aditofpython.cpp)
target_link_libraries(aditofpython PRIVATE aditof)

Summary:

  • When WITH_PYTHON=ON (default), the aditofpython module is built using pybind11 included as a subdirectory under bindings/python/pybind11.
  • This is separate from the C++ SDK library but part of the overall project.

6. Quick Option → Dependency Table

CMake option Default Affects Dependencies / Notes
WITH_GLOG_DEPENDENCY OFF SDK logging Enables glog (USE_GLOG), built from submodule or system glog.
WITH_NETWORK ON Network interface Enables network code and, together with protobuf, ZeroMQ/Protobuf stack.
WITH_PROTOBUF_DEPENDENCY ON Network interface Controls use of Protobuf + ZeroMQ. Adds USE_PROTOBUF when ON.
WITH_SUBMODULES ON glog, libzmq, protobuf When ON and submodules exist, uses in‑tree builds instead of system libs.
USE_DEPTH_COMPUTE_OPENSOURCE OFF Depth compute (ON_TARGET) Switch between closed‑source libtofi_* and open‑source tofi_*.
WITH_PYTHON ON Python bindings Builds aditofpython using embedded pybind11.

Always used by SDK:

  • json-c
  • crc32
  • Optionally libbsd on Unix (non‑macOS).

This page should give you a clear view of which external libraries are used and which CMake options control them, in a format suitable for the GitHub Wiki.