Documentation

Build and Install

To build libosdp you need a C compiler and CMake 3.14 or newer. The buildproduces a static library (libosdpstatic.a) and a shared library(libosdp.so / .dylib / .dll). See examples/ for how to consume themfrom your application.

This project supports two build systems: CMake (recommended) and a thinMake-based "lean" build for cross-compile-only situations.

CMake Build

cmake -B build
cmake --build build --parallel

To install to a prefix:

cmake --build build --target install
# or:
cmake --install build --prefix /usr/local

The install lays down:

${prefix}/lib(64)/libosdp.so*           # shared library + soname symlinks
${prefix}/lib(64)/libosdpstatic.a       # static library
${prefix}/include/libosdp/osdp.h        # C API
${prefix}/include/libosdp/osdp.hpp      # C++ wrapper
${prefix}/include/libosdp/osdp_export.h # visibility macros
${prefix}/lib(64)/pkgconfig/libosdp.pc  # pkg-config metadata
${prefix}/lib(64)/cmake/libosdp/        # CMake package config (find_package)

To build only one variant, set OPT_BUILD_SHARED=OFF orOPT_BUILD_STATIC=OFF. At least one must remain enabled.

cmake -B build -DOPT_BUILD_SHARED=OFF   # static-only
cmake -B build -DOPT_BUILD_STATIC=OFF   # shared-only

Make Build

The Make build is a stripped-down alternative for cross-compile orembedded scenarios where pulling in CMake is undesirable. It builds thestatic library only.

./configure.sh
make
make install        # installs libosdp.a, headers, libosdp.pc
make check          # runs unit tests

See ./configure.sh --help for all flags.

Crypto Backend Selection

LibOSDP's Secure Channel needs an AES implementation. Three backends aresupported; the default auto mode probes for OpenSSL, then MbedTLS, andfalls back to the bundled TinyAES if neither is found (with a warning,since TinyAES is not hardened to the same degree as OpenSSL/MbedTLS).

CMakeconfigure.shBehavior
-DOPT_OSDP_CRYPTO_BACKEND=auto (default)--crypto autoPick OpenSSL → MbedTLS → TinyAES (warn on TinyAES fallback)
-DOPT_OSDP_CRYPTO_BACKEND=openssl--crypto opensslRequire OpenSSL; hard fail if absent
-DOPT_OSDP_CRYPTO_BACKEND=mbedtls--crypto mbedtlsRequire MbedTLS; hard fail if absent
-DOPT_OSDP_CRYPTO_BACKEND=tinyaes--crypto tinyaesForce the bundled implementation; no probe, no warning

Running the Test Suite

The full release-style test suite (PyTest + unit tests for both buildsystems) is wrapped in:

./scripts/run_tests.sh

For just the C unit tests under CMake:

cmake --build build --target check  # convenience wrapper
ctest --test-dir build               # native CTest entry point (also works in IDEs)

For the lean Make build:

make check

Compile-time Configuration Options

LibOSDP can be configured by passing -DOPT_XXX=ON/OFF flags to CMake.The same options are exposed by configure.sh flags for the lean build.

configure.sh flagCMake optionDefaultDescription
--packet-traceOPT_OSDP_PACKET_TRACEOFFEnable raw packet trace for diagnostics
--data-traceOPT_OSDP_DATA_TRACEOFFEnable command/reply data buffer tracing
--skip-markOPT_OSDP_SKIP_MARK_BYTEOFFDon't send the leading mark byte (0xFF)
--zero-copyOPT_OSDP_RX_ZERO_COPYOFFEnable zero-copy RX (recv_pkt/release_pkt)
--log-minimalOPT_OSDP_LOG_MINIMALOFFMinimize logger RAM/stack (embedded)
--no-coloursOPT_DISABLE_PRETTY_LOGGINGOFFDon't colorize log outputs
--staticOPT_OSDP_STATICOFFBuild without dynamic memory allocation
--lib-onlyOPT_OSDP_LIB_ONLYOFFOnly build the library
--crypto LIBOPT_OSDP_CRYPTO_BACKENDautoCrypto backend (auto/openssl/mbedtls/tinyaes)
N/AOPT_BUILD_SANITIZEROFFEnable ASan/UBSan/LSan
N/AOPT_BUILD_SHAREDONBuild shared library
N/AOPT_BUILD_STATICONBuild static library
--bare-metalOPT_BUILD_BARE_METALOFFBuild for bare-metal targets
--use-32bit-tick-tOPT_USE_32BIT_TICK_TOFFUse uint32_t tick_t; requires bare-metal

Add LibOSDP to Your CMake Project

Build and install LibOSDP, then in your project's CMakeLists.txt:

find_package(libosdp CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE libosdp::libosdp)

libosdp::libosdp is an alias that resolves to the shared library whenboth variants were installed, falling back to the static library whenonly static was built. If you specifically want one or the other, uselibosdp::osdp (shared) or libosdp::osdpstatic (static) directly.

The package config carries the crypto backend dependency throughfind_dependency(), so a static-link consumer of an OpenSSL-builtLibOSDP automatically picks up OpenSSL::Crypto without further setup.

add_subdirectory

You can also embed LibOSDP directly in your build:

add_subdirectory(third_party/libosdp)
target_link_libraries(my_app PRIVATE libosdp::libosdp)

The same libosdp::libosdp / libosdp::osdp / libosdp::osdpstaticaliases are defined in the build tree, so consumer code is identicalwhether LibOSDP is installed or vendored.

FetchContent

include(FetchContent)
FetchContent_Declare(libosdp
    GIT_REPOSITORY https://github.com/goToMain/libosdp.git
    GIT_TAG        v3.2.0  # update to latest release
)
FetchContent_MakeAvailable(libosdp)
target_link_libraries(my_app PRIVATE libosdp::libosdp)

Using pkg-config

LibOSDP installs a libosdp.pc file alongside the library. Withpkg-config on your PKG_CONFIG_PATH:

gcc my_app.c $(pkg-config --cflags --libs libosdp) -o my_app

The Cflags adds -I${includedir}/libosdp, so #include <osdp.h>works as written. For static linking, pkg-config --static adds thecrypto backend (-lcrypto or -lmbedcrypto) declared viaRequires.private.

Using vcpkg

A port for LibOSDP is available in vcpkg upstream. Follow thegetting started guideto set up vcpkg, then:

mkdir osdp_app && cd osdp_app
vcpkg new --application
vcpkg add port libosdp

Build with the vcpkg toolchain file:

cmake -DCMAKE_TOOLCHAIN_FILE="%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" -B build .
cmake --build build

Note: vcpkg is the recommended method to consume LibOSDP on Windows.