From 26f0d8fa0aa57aff65cf38ee69ee001be64e5416 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 22 Jul 2025 12:23:59 +0200 Subject: [PATCH 1/2] Add support to use system provided nlohmann_json library if requested The use of the library provided by the system is activated with the cmake option -DUSE_EXTERNAL_NLOHMANN_JSON=ON. --- CMake/lrs_options.cmake | 1 + third-party/CMakeLists.txt | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMake/lrs_options.cmake b/CMake/lrs_options.cmake index 3dbc633b918..cf5eb2d9d31 100644 --- a/CMake/lrs_options.cmake +++ b/CMake/lrs_options.cmake @@ -57,3 +57,4 @@ option(ENABLE_SECURITY_FLAGS "Enable additional compiler security flags to enhan option(USE_EXTERNAL_LZ4 "Use externally build LZ4 library instead of building and using the in this repo provided version" OFF) option(BUILD_ASAN "Enable AddressSanitizer" OFF) mark_as_advanced(BUILD_ASAN) +option(USE_EXTERNAL_NLOHMANN_JSON "Use external build nlohmann_json library instead of building and using the in this repo provided version" OFF) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index c28e66c84d3..23f81ea5c56 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -5,7 +5,11 @@ add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/rsutils" ) pop_security_flags() # remove security flags for third party, as we cannot guarantee their security enforcment -include(CMake/external_json.cmake) +if(USE_EXTERNAL_NLOHMANN_JSON) + find_package(nlohmann_json 3.11.3 REQUIRED) +else() + include(CMake/external_json.cmake) +endif() # Add additional include directories to allow file to include rosbag headers include(${_rel_path}/realsense-file/config.cmake) From 115f12ea2f9ebac5510685715ee6add39930c23c Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 23 Jul 2025 17:06:50 +0200 Subject: [PATCH 2/2] Fix bug that linking to nlohmann_json library was not possible The problem was caused by the target rsutils being added before the library nlohmann_json. --- third-party/CMakeLists.txt | 6 +++--- third-party/rsutils/CMakeLists.txt | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 23f81ea5c56..7e99e049dd7 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -1,8 +1,5 @@ string(REPLACE ${PROJECT_SOURCE_DIR}/ "" _rel_path ${CMAKE_CURRENT_LIST_DIR}) - -add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/rsutils" ) - pop_security_flags() # remove security flags for third party, as we cannot guarantee their security enforcment if(USE_EXTERNAL_NLOHMANN_JSON) @@ -10,6 +7,9 @@ if(USE_EXTERNAL_NLOHMANN_JSON) else() include(CMake/external_json.cmake) endif() + +add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/rsutils" ) + # Add additional include directories to allow file to include rosbag headers include(${_rel_path}/realsense-file/config.cmake) diff --git a/third-party/rsutils/CMakeLists.txt b/third-party/rsutils/CMakeLists.txt index b0fc310497a..a5a5b7608af 100644 --- a/third-party/rsutils/CMakeLists.txt +++ b/third-party/rsutils/CMakeLists.txt @@ -4,15 +4,13 @@ cmake_minimum_required(VERSION 3.8.0) # source_group(TREE) project( rsutils ) add_library( ${PROJECT_NAME} STATIC "" ) -# We cannot directly interface with nlohmann_json (doesn't work on bionic) -#target_link_libraries( ${PROJECT_NAME} PUBLIC nlohmann_json ) +target_link_libraries( ${PROJECT_NAME} PRIVATE nlohmann_json ) target_compile_features( ${PROJECT_NAME} PUBLIC cxx_std_14 ) set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Library ) target_include_directories( ${PROJECT_NAME} PUBLIC $ - $ ) # Headers -----------------------------------------------------------------------------------