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).
| CMake | configure.sh | Behavior |
|---|---|---|
-DOPT_OSDP_CRYPTO_BACKEND=auto (default) | --crypto auto | Pick OpenSSL → MbedTLS → TinyAES (warn on TinyAES fallback) |
-DOPT_OSDP_CRYPTO_BACKEND=openssl | --crypto openssl | Require OpenSSL; hard fail if absent |
-DOPT_OSDP_CRYPTO_BACKEND=mbedtls | --crypto mbedtls | Require MbedTLS; hard fail if absent |
-DOPT_OSDP_CRYPTO_BACKEND=tinyaes | --crypto tinyaes | Force 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 flag | CMake option | Default | Description |
|---|---|---|---|
--packet-trace | OPT_OSDP_PACKET_TRACE | OFF | Enable raw packet trace for diagnostics |
--data-trace | OPT_OSDP_DATA_TRACE | OFF | Enable command/reply data buffer tracing |
--skip-mark | OPT_OSDP_SKIP_MARK_BYTE | OFF | Don't send the leading mark byte (0xFF) |
--zero-copy | OPT_OSDP_RX_ZERO_COPY | OFF | Enable zero-copy RX (recv_pkt/release_pkt) |
--log-minimal | OPT_OSDP_LOG_MINIMAL | OFF | Minimize logger RAM/stack (embedded) |
--no-colours | OPT_DISABLE_PRETTY_LOGGING | OFF | Don't colorize log outputs |
--static | OPT_OSDP_STATIC | OFF | Build without dynamic memory allocation |
--lib-only | OPT_OSDP_LIB_ONLY | OFF | Only build the library |
--crypto LIB | OPT_OSDP_CRYPTO_BACKEND | auto | Crypto backend (auto/openssl/mbedtls/tinyaes) |
| N/A | OPT_BUILD_SANITIZER | OFF | Enable ASan/UBSan/LSan |
| N/A | OPT_BUILD_SHARED | ON | Build shared library |
| N/A | OPT_BUILD_STATIC | ON | Build static library |
--bare-metal | OPT_BUILD_BARE_METAL | OFF | Build for bare-metal targets |
--use-32bit-tick-t | OPT_USE_32BIT_TICK_T | OFF | Use uint32_t tick_t; requires bare-metal |
Add LibOSDP to Your CMake Project
find_package (recommended)
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.