Skip to content

feat: add USE_VENDORED_JSON option for nlohmann::json - #1212

Open
webzuweb wants to merge 1 commit into
BehaviorTree:masterfrom
webzuweb:feat/use-vendored-json-option
Open

webzuweb wants to merge 1 commit into
BehaviorTree:masterfrom
webzuweb:feat/use-vendored-json-option

Conversation

@webzuweb

Copy link
Copy Markdown
Contributor

Closes #1138.

Adds a USE_VENDORED_JSON CMake option (default ON), mirroring the existing USE_VENDORED_CPPZMQ / USE_VENDORED_FLATBUFFERS / USE_VENDORED_MINICORO / USE_VENDORED_MINITRACE options.

Why: nlohmann::json is header-only, so when an application bundles a different version than the one vendored in include/behaviortree_cpp/contrib/json.hpp, you get ODR/ABI mismatches (duplicate/conflicting nlohmann::json symbols and inconsistent behavior). This lets users opt into an externally provided nlohmann_json package so both sides share the exact same version.

Changes:

  • Move the bundled header to contrib/nlohmann_json.hpp.
  • contrib/json.hpp becomes a thin forwarding header: includes <nlohmann/json.hpp> when BTCPP_USE_EXTERNAL_JSON is defined, otherwise the bundled copy. No call sites change.
  • CMake: USE_VENDORED_JSON option + find_package(nlohmann_json) when disabled, with nlohmann_json::nlohmann_json linked PUBLIC and BTCPP_USE_EXTERNAL_JSON propagated PUBLIC so installed consumers get consistent behavior.

Verified locally:

  • Library builds both with USE_VENDORED_JSON=ON (bundled) and =OFF (system nlohmann-json 3.12.0).
  • Test suite: 529/531 passed. The 2 failures (CoroTest.sequence_child flake, LoggerTest.SqliteLogger_ExecSqlStatement SIGSEGV) reproduce on a clean master and are unrelated to this change.

Add a USE_VENDORED_JSON CMake option (default ON) mirroring the other
USE_VENDORED_* options. When disabled, find_package(nlohmann_json) is
used instead of the bundled header, so the library and the consuming
application can share the exact same nlohmann::json version and avoid
ODR/ABI mismatches (issue BehaviorTree#1138).

The bundled header is moved to contrib/nlohmann_json.hpp and
contrib/json.hpp becomes a thin forwarding header that includes either
the bundled copy or <nlohmann/json.hpp> depending on
BTCPP_USE_EXTERNAL_JSON.

Verified: library builds with USE_VENDORED_JSON=ON (vendored) and =OFF
(system nlohmann-json 3.12.0); test suite 529/531 (2 pre-existing
failures unrelated: CoroTest flake + SqliteLogger SIGSEGV).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add USE_VENDORED_ option for nlohmann::json

1 participant