Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/cmake_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ jobs:
- name: run test (Linux)
run: ctest --test-dir build/${{env.BUILD_TYPE}}

# USE_VENDORED_JSON=OFF, with the oldest supported nlohmann_json (3.10.5 on 22.04)
system-json:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v7

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y nlohmann-json3-dev libzmq3-dev libsqlite3-dev libgtest-dev

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUSE_VENDORED_JSON=OFF

- name: Build
run: cmake --build build --parallel $(nproc)

- name: run test
run: ctest --test-dir build --output-on-failure

coverage:
runs-on: ubuntu-24.04

Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(FORCE_STATIC_LINKING "Force static linking of all dependencies" OFF)

option(USE_VENDORED_CPPZMQ "Use the bundled version of cppzmq" ON)
option(USE_VENDORED_FLATBUFFERS "Use the bundled version of flatbuffers" ON)
option(USE_VENDORED_JSON "Use the bundled version of nlohmann/json" ON)
option(USE_VENDORED_MINICORO "Use the bundled version of minicoro" ON)
option(USE_VENDORED_MINITRACE "Use the bundled version of minitrace" ON)

Expand Down Expand Up @@ -133,6 +134,10 @@ else()
find_package(flatbuffers REQUIRED)
endif()

if(NOT USE_VENDORED_JSON)
find_package(nlohmann_json 3.10 REQUIRED)
endif()

if(USE_VENDORED_MINICORO)
add_subdirectory(3rdparty/minicoro)
else()
Expand Down Expand Up @@ -259,6 +264,12 @@ target_include_directories(${BTCPP_LIBRARY}

target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_LIBRARY_VERSION="${PROJECT_VERSION}")

if(NOT USE_VENDORED_JSON)
# The public headers include <nlohmann/json.hpp> instead of the bundled copy
target_compile_definitions(${BTCPP_LIBRARY} PUBLIC BTCPP_SYSTEM_JSON)
target_link_libraries(${BTCPP_LIBRARY} PUBLIC nlohmann_json::nlohmann_json)
endif()

target_compile_features(${BTCPP_LIBRARY} PUBLIC cxx_std_17)

if(MSVC)
Expand Down Expand Up @@ -327,8 +338,14 @@ INSTALL(TARGETS ${BTCPP_LIBRARY}
INCLUDES DESTINATION ${BTCPP_INCLUDE_DESTINATION}
)

if(NOT USE_VENDORED_JSON)
# Don't install the bundled copy: a user that doesn't get BTCPP_SYSTEM_JSON
# must fail to compile, rather than mix two versions of nlohmann::json
set(BTCPP_INSTALL_EXCLUDE REGEX "contrib/json\\.hpp$" EXCLUDE)
endif()

INSTALL( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${BTCPP_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h*")
FILES_MATCHING PATTERN "*.h*" ${BTCPP_INSTALL_EXCLUDE})

export_btcpp_package()
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ cmake -S . -B build_release
cmake --build build_release --parallel
```

BT.CPP includes its own copy of [nlohmann/json](https://github.com/nlohmann/json).
To use the one installed in your system instead (version 3.10 or newer), add `-DUSE_VENDORED_JSON=OFF`.
Since `nlohmann::json` is part of the public API, everything that links BT.CPP must then be
compiled with that same version.

If you want to build in a [pixi](https://pixi.sh/) project (conda virtual environment).
```
pixi run build
Expand Down
5 changes: 5 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@PACKAGE_INIT@

if(NOT "@USE_VENDORED_JSON@")
include(CMakeFindDependencyMacro)
find_dependency(nlohmann_json 3.10)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

set(@PROJECT_NAME@_TARGETS "BT::@PROJECT_NAME@")
Expand Down
3 changes: 3 additions & 0 deletions cmake/ament_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ set( BTCPP_EXTRA_LIBRARIES
)

ament_export_dependencies(ament_index_cpp)
if(NOT USE_VENDORED_JSON)
ament_export_dependencies(nlohmann_json)
endif()

# The ROS build farm (bloom/debhelper) configures with
# -DCMAKE_INSTALL_LIBDIR=lib/<multiarch-triplet>, but ament tooling
Expand Down
4 changes: 4 additions & 0 deletions include/behaviortree_cpp/blackboard.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

#include "behaviortree_cpp/basic_types.h"
#ifdef BTCPP_SYSTEM_JSON
#include <nlohmann/json.hpp>
#else
#include "behaviortree_cpp/contrib/json.hpp"
#endif
#include "behaviortree_cpp/exceptions.h"
#include "behaviortree_cpp/utils/locked_reference.hpp"
#include "behaviortree_cpp/utils/polymorphic_cast_registry.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/behaviortree_cpp/bt_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#define BT_FACTORY_H

#include "behaviortree_cpp/behavior_tree.h"
#ifdef BTCPP_SYSTEM_JSON
#include <nlohmann/json.hpp>
#else
#include "behaviortree_cpp/contrib/json.hpp"
#endif
#include "behaviortree_cpp/contrib/magic_enum.hpp"
#include "behaviortree_cpp/utils/polymorphic_cast_registry.hpp"

Expand Down
7 changes: 6 additions & 1 deletion include/behaviortree_cpp/json_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
#include "behaviortree_cpp/basic_types.h"
#include "behaviortree_cpp/utils/safe_any.hpp"

// Use the version nlohmann::json embedded in BT.CPP
// Use the version of nlohmann::json embedded in BT.CPP,
// or the system one if BT.CPP was built with USE_VENDORED_JSON=OFF
#ifdef BTCPP_SYSTEM_JSON
#include <nlohmann/json.hpp>
#else
#include "behaviortree_cpp/contrib/json.hpp"
#endif

namespace BT
{
Expand Down
4 changes: 4 additions & 0 deletions include/behaviortree_cpp/loggers/groot2_protocol.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#pragma once

#include "behaviortree_cpp/basic_types.h"
#ifdef BTCPP_SYSTEM_JSON
#include <nlohmann/json.hpp>
#else
#include "behaviortree_cpp/contrib/json.hpp"
#endif

#include <array>
#include <condition_variable>
Expand Down
1 change: 0 additions & 1 deletion tests/groot2_test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <behaviortree_cpp/loggers/groot2_protocol.h>
#include <behaviortree_cpp/loggers/groot2_publisher.h>

#include <behaviortree_cpp/contrib/json.hpp>
#include <zmq_addon.hpp>

namespace Groot2Test
Expand Down
2 changes: 0 additions & 2 deletions tests/gtest_groot2_publisher_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <behaviortree_cpp/bt_factory.h>
#include <gtest/gtest.h>

#include <behaviortree_cpp/contrib/json.hpp>

namespace
{
constexpr auto kHookTreeXml = R"(
Expand Down
Loading