From 3427f292ed430984a144c278bef7f4614e5c62ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Sture?= Date: Wed, 18 Feb 2026 12:33:10 +0000 Subject: [PATCH] Allow use of non-vendored Zenoh if present (#908) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Øystein Sture (cherry picked from commit a8714a2bbbe3e6e2a55699e082a291c1346c7b26) --- README.md | 2 + zenoh_cpp_vendor/CMakeLists.txt | 82 ++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 5037cc94..da32fce7 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ sudo apt update && sudo apt install ros--rmw-zenoh-cpp # replace [!NOTE] > By default, we vendor and compile `zenoh-cpp` with a subset of `zenoh` features. The `ZENOHC_CARGO_FLAGS` CMake argument may be overwritten with other features included if required. +The `USE_SYSTEM_ZENOH` CMake argument can be used to use non-vendored system libraries instead. +The user must ensure that the non-vendored libraries are found by CMake and provide the necessary features (e.g., shared-memory support). See [zenoh_cpp_vendor/CMakeLists.txt](./zenoh_cpp_vendor/CMakeLists.txt) for more details. ```bash diff --git a/zenoh_cpp_vendor/CMakeLists.txt b/zenoh_cpp_vendor/CMakeLists.txt index 64707cec..a1be3589 100644 --- a/zenoh_cpp_vendor/CMakeLists.txt +++ b/zenoh_cpp_vendor/CMakeLists.txt @@ -10,45 +10,53 @@ endif() find_package(ament_cmake REQUIRED) find_package(ament_cmake_vendor_package REQUIRED) -# Add a set of usefull features that are not enabled by default in zenoh-c. -# For a complete list of features see: https://github.com/eclipse-zenoh/zenoh/blob/main/zenoh/Cargo.toml -# Note: the list of features are separated with whitespaces. -# However, if you want to add other cargo build flags, use "$" as separator and not ";" as the -# latter is a list separater in cmake and hence the string will be split into two when expanded. -set(ZENOHC_CARGO_FLAGS "--features=shared-memory zenoh/transport_serial") - -# Set VCS_VERSION to 1.7.1 commits of zenoh/zenoh-c/zenoh-cpp to benefit from: -# * Query cancellation -# - https://github.com/eclipse-zenoh/zenoh/pull/2223 -# - https://github.com/eclipse-zenoh/zenoh-c/pull/1134 -# - https://github.com/eclipse-zenoh/zenoh-cpp/pull/663 -# * Access to transport optimization SHM provider -# - https://github.com/eclipse-zenoh/zenoh/pull/2221 -# - https://github.com/eclipse-zenoh/zenoh-c/pull/1132 -# - https://github.com/eclipse-zenoh/zenoh-cpp/pull/654 -# * Metrics per key (requires to add "zenoh/stats" feature to ZENOHC_CARGO_FLAGS for build) -# - https://github.com/eclipse-zenoh/zenoh/pull/2284 -ament_vendor(zenoh_c_vendor - VCS_URL https://github.com/eclipse-zenoh/zenoh-c.git - VCS_VERSION 73e7a0bdcf78b8263a02b7aee453ee6de8187589 - CMAKE_ARGS - "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}" - "-DZENOHC_BUILD_WITH_UNSTABLE_API=TRUE" - "-DZENOHC_CUSTOM_TARGET=${ZENOHC_CUSTOM_TARGET}" - PATCHES ${CMAKE_CURRENT_SOURCE_DIR}/pin-rust-1.75.0.patch -) +option(USE_SYSTEM_ZENOH "Use non-vendored zenoh from the system" OFF) + +if(USE_SYSTEM_ZENOH) + find_package(zenohc REQUIRED) + find_package(zenohcxx REQUIRED) + message(STATUS "Using system zenohc version: ${zenohc_VERSION}") + message(STATUS "Using system zenohcxx version: ${zenohcxx_VERSION}") +else() + # Add a set of usefull features that are not enabled by default in zenoh-c. + # For a complete list of features see: https://github.com/eclipse-zenoh/zenoh/blob/main/zenoh/Cargo.toml + # Note: the list of features are separated with whitespaces. + # However, if you want to add other cargo build flags, use "$" as separator and not ";" as the + # latter is a list separater in cmake and hence the string will be split into two when expanded. + set(ZENOHC_CARGO_FLAGS "--features=shared-memory zenoh/transport_serial") + + # Set VCS_VERSION to 1.7.1 commits of zenoh/zenoh-c/zenoh-cpp to benefit from: + # * Query cancellation + # - https://github.com/eclipse-zenoh/zenoh/pull/2223 + # - https://github.com/eclipse-zenoh/zenoh-c/pull/1134 + # - https://github.com/eclipse-zenoh/zenoh-cpp/pull/663 + # * Access to transport optimization SHM provider + # - https://github.com/eclipse-zenoh/zenoh/pull/2221 + # - https://github.com/eclipse-zenoh/zenoh-c/pull/1132 + # - https://github.com/eclipse-zenoh/zenoh-cpp/pull/654 + # * Metrics per key (requires to add "zenoh/stats" feature to ZENOHC_CARGO_FLAGS for build) + # - https://github.com/eclipse-zenoh/zenoh/pull/2284 + ament_vendor(zenoh_c_vendor + VCS_URL https://github.com/eclipse-zenoh/zenoh-c.git + VCS_VERSION 73e7a0bdcf78b8263a02b7aee453ee6de8187589 + CMAKE_ARGS + "-DZENOHC_CARGO_FLAGS=${ZENOHC_CARGO_FLAGS}" + "-DZENOHC_BUILD_WITH_UNSTABLE_API=TRUE" + "-DZENOHC_CUSTOM_TARGET=${ZENOHC_CUSTOM_TARGET}" + PATCHES ${CMAKE_CURRENT_SOURCE_DIR}/pin-rust-1.75.0.patch + ) + + ament_vendor(zenoh_cpp_vendor + VCS_URL https://github.com/eclipse-zenoh/zenoh-cpp + VCS_VERSION 47a80d345d74ebef16f3783423bf3bbd89cd6c30 + CMAKE_ARGS + -DZENOHCXX_ZENOHC=OFF + ) + + externalproject_add_stepdependencies(zenoh_cpp_vendor configure zenoh_c_vendor) +endif() ament_export_dependencies(zenohc) - -ament_vendor(zenoh_cpp_vendor - VCS_URL https://github.com/eclipse-zenoh/zenoh-cpp - VCS_VERSION 47a80d345d74ebef16f3783423bf3bbd89cd6c30 - CMAKE_ARGS - -DZENOHCXX_ZENOHC=OFF -) - -externalproject_add_stepdependencies(zenoh_cpp_vendor configure zenoh_c_vendor) - ament_export_dependencies(zenohcxx) ament_package()