Skip to content
Snippets Groups Projects
Commit 7cc273ea authored by René Paris's avatar René Paris
Browse files

feat(JSON for modern C++): Integrate nlohmann_json library

Integrates the commonly used JSON library for convenient parsing
of custom properites, carring object data encoded as string.
parent 6e9f25c7
No related branches found
No related tags found
1 merge request!228feat(JSON for modern C++): Integrate nlohmann_json library
Pipeline #67031 failed
Showing
with 186 additions and 25 deletions
......@@ -78,6 +78,12 @@ Yase
units_nhh
* License: MIT
nlohmann (JSON for Modern C++)
* License: MIT License
* Homepage: https://nlohmann.github.io/json/
* Repository: https://github.com/nlohmann/json
* Version: 3.9.1
MantleAPI
* License: EPL 2.0
......
......@@ -254,13 +254,14 @@ Converts `NET_ASAM_OPENSCENARIO::v1_3::ITransitionDynamics` object type to [mant
| Dependency | Commit | Version | License |
| ---------- | ------ | ------- | ------- |
| [CPM](https://github.com/cpm-cmake/CPM.cmake) | 03705fc | 0.36.0 | MIT License |
| [googletest](https://github.com/google/googletest) | f8d7d77 | 1.14.0 | BSD-3-Clause License |
| [JSON for Modern C++](https://github.com/nlohmann/json) | db78ac1 | 3.9.1 | MIT License |
| [MantleAPI](https://gitlab.eclipse.org/eclipse/openpass/mantle-api) | ce2a378d | 11.0.0 | EPL 2.0 |
| [openpass/stochastics-library](https://gitlab.eclipse.org/eclipse/openpass/stochastics-library) | 6c9dde71 | 0.11.0 | EPL 2.0 |
| [OpenSCENARIO API](https://github.com/RA-Consulting-GmbH/openscenario.api.test/) | 5980e88 | 1.4.0 | Apache 2.0 |
| [YASE](https://gitlab.eclipse.org/eclipse/openpass/yase) | d0c0e58d | | EPL 2.0 |
| [Units](https://github.com/nholthaus/units) | e27eed9 | 2.3.4 | MIT License |
| [googletest](https://github.com/google/googletest) | f8d7d77 | 1.14.0 | BSD-3-Clause License |
| [CPM](https://github.com/cpm-cmake/CPM.cmake) | 03705fc | 0.36.0 | MIT License |
| [openpass/stochastics-library](https://gitlab.eclipse.org/eclipse/openpass/stochastics-library) | 6c9dde71 | 0.11.0 | EPL 2.0 |
| [YASE](https://gitlab.eclipse.org/eclipse/openpass/yase) | d0c0e58d | | EPL 2.0 |
# Issues
......
......@@ -29,6 +29,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"@mantle_api",
"@nlohmann_json",
"@open_scenario_parser",
"@stochastics_library",
"@units_nhh",
......@@ -183,6 +184,7 @@ cc_test(
":open_scenario_engine_test_utils",
"@googletest//:gtest_main",
"@mantle_api//:test_utils",
"@nlohmann_json",
],
)
......
......@@ -23,11 +23,11 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# YASE
find_package(Yase REQUIRED)
# units https://github.com/nholthaus/units (dependency of MantleAPI)
find_package(MantleAPI REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(Stochastics REQUIRED)
find_package(units REQUIRED)
find_package(Yase REQUIRED)
# googlemock
include(CPM)
......@@ -39,12 +39,6 @@ CPMAddPackage(
OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt ON"
)
# MantleAPI https://gitlab.eclipse.org/eclipse/simopenpass/scenario_api
find_package(MantleAPI REQUIRED)
find_package(Stochastics REQUIRED)
# see https://stackoverflow.com/a/58495612
set(CMAKE_INSTALL_RPATH $ORIGIN)
......@@ -70,12 +64,17 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
)
target_link_libraries(${PROJECT_NAME} PUBLIC openscenario_api::shared
antlr4_runtime::shared
Yase::agnostic_behavior_tree
units::units
MantleAPI::MantleAPI
PRIVATE Stochastics::Stochastics)
target_link_libraries(${PROJECT_NAME}
PUBLIC
antlr4_runtime::shared
MantleAPI::MantleAPI
units::units
Yase::agnostic_behavior_tree
openscenario_api::shared
PRIVATE
Stochastics::Stochastics
nlohmann_json::nlohmann_json
)
if(USE_CCACHE)
find_program(CCACHE_FOUND ccache)
......@@ -246,11 +245,13 @@ target_include_directories(
target_link_libraries(
${PROJECT_NAME}Test
PRIVATE ${PROJECT_NAME}
Stochastics::Stochastics
antlr4_runtime::shared
GTest::gmock_main
pthread
PRIVATE
${PROJECT_NAME}
antlr4_runtime::shared
GTest::gmock_main
nlohmann_json::nlohmann_json
pthread
Stochastics::Stochastics
)
add_test(NAME ${PROJECT_NAME}Test COMMAND ${PROJECT_NAME}Test)
......
load("@//third_party/boost:boost.bzl", "boost_deps")
load("@//third_party/mantle_api:mantle_api.bzl", "mantle_api")
load("@//third_party/nlohmann_json:nlohmann_json.bzl", "nlohmann_json")
load("@//third_party/open_scenario_parser:open_scenario_parser.bzl", "open_scenario_parser")
load("@//third_party/stochastics_library:stochastics_library.bzl", "stochastics_library")
load("@//third_party/units:units.bzl", "units_nhh")
......@@ -11,6 +12,7 @@ def osc_engine_deps():
"""Load dependencies"""
boost_deps()
mantle_api()
nlohmann_json()
open_scenario_parser()
stochastics_library()
units_nhh()
......
cc_library(
name = "nlohmann_json",
hdrs = ["single_include/nlohmann/json.hpp"],
includes = ["single_include"],
visibility = ["//visibility:public"],
)
"""
This module contains rule to pull nlohmann json
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:nlohmann_json.bzl", "maybe")
_TAG = "3.9.1"
def nlohmann_json():
maybe(
http_archive,
name = "nlohmann_json",
build_file = Label("//:third_party/nlohmann_json/nlohmann_json.BUILD"),
url = "https://github.com/nlohmann/json/releases/download/v{version}/include.zip".format(version = _VERSION),
sha256 = "6bea5877b1541d353bd77bdfbdb2696333ae5ed8f9e8cc22df657192218cad91"
)
cc_library(
name = "nlohmann_json",
hdrs = ["single_include/nlohmann/json.hpp"],
includes = ["single_include"],
visibility = ["//visibility:public"],
)
"""
This module contains rule to pull nlohmann json
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
_VERSION = "3.9.1"
def nlohmann_json():
maybe(
http_archive,
name = "nlohmann_json",
build_file = Label("//:third_party/nlohmann_json/nlohmann_json.BUILD"),
url = "https://github.com/nlohmann/json/releases/download/v{version}/include.zip".format(version = _VERSION),
sha256 = "6bea5877b1541d353bd77bdfbdb2696333ae5ed8f9e8cc22df657192218cad91"
)
[requires]
units/2.3.4@openscenarioengine/testing
mantleapi/v11.0.0@openscenarioengine/testing
nlohmann_json/v3.9.1@openscenarioengine/testing
yase/d0c0e58d17358044cc9018c74308b45f6097ecfb@openscenarioengine/testing
openscenario_api/v1.4.0@openscenarioengine/testing
stochastics/0.11.0@openscenarioengine/testing
......
################################################################################
# Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
################################################################################
################################################################################
# conan data file for building nlohmann_json with Conan
################################################################################
sources:
"v3.9.1":
url: https://github.com/nlohmann/json/archive/refs/tags/v3.9.1.tar.gz
sha256: "4cf0df69731494668bdd6460ed8cb269b68de9c19ad8c27abc24cd72605b2d5b"
"v3.11.3":
url: https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.tar.gz
sha256: "0d8ef5af7f9794e3263480193c491549b2ba6cc74bb018906202ada498a79406"
################################################################################
# Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
################################################################################
################################################################################
# Install file for building nlohmann_json with Conan
################################################################################
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.files import rm, copy, rmdir
from conan.tools.files import get, copy
import os
required_conan_version = ">=1.53"
class NlohmannJSONConan(ConanFile):
name = "nlohmann_json"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False],
"fPIC": [True, False]}
default_options = {"shared": False,
"fPIC": True}
exports_sources = "*"
no_copy_source = False
short_paths = True
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def generate(self):
tc = CMakeToolchain(self)
tc.generate()
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def build(self):
cmake = CMake(self)
cmake.configure()
def package(self):
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "none")
################################################################################
# Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
################################################################################
################################################################################
# config file for building nlohmann_json with Conan
################################################################################
versions:
"v3.9.1":
folder: "all"
"v3.11.3":
folder: "all"
......@@ -31,6 +31,7 @@ mkdir -p "$MYDIR/../../../../build"
cd "$MYDIR/../../../../build" || exit 1
DEPS=(
"$PWD/../deps/direct_deploy/nlohmann_json"
"$PWD/../deps/direct_deploy/units"
"$PWD/../deps/direct_deploy/mantleapi"
"$PWD/../deps/direct_deploy/stochastics"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment