Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

external json & pybind11_json #11587

Merged
merged 6 commits into from
Mar 20, 2023
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
41 changes: 41 additions & 0 deletions CMake/external_json.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.6)
include(ExternalProject)



# We use a function to enforce a scoped variables creation only for the build
# (i.e turn off BUILD_SHARED_LIBS which is used on LRS build as well)
function(get_nlohmann_json)

message( STATUS #CHECK_START
"Fetching nlohmann/json..." )
#list( APPEND CMAKE_MESSAGE_INDENT " " ) # Indent outputs

# We want to clone the pybind repo and build it here, during configuration, so we can use it.
# But ExternalProject_add is limited in that it only does its magic during build.
# This is possible in CMake 3.12+ with FetchContent and FetchContent_MakeAvailable in 3.14+ (meaning Ubuntu 20)
# but we need to adhere to CMake 3.10 (Ubuntu 18).
# So instead, we invoke a new CMake project just to download pybind:
configure_file( CMake/json-download.cmake.in
${CMAKE_BINARY_DIR}/external-projects/json-download/CMakeLists.txt )
execute_process( COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/json-download"
OUTPUT_QUIET
RESULT_VARIABLE configure_ret )
execute_process( COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/json-download"
OUTPUT_QUIET
RESULT_VARIABLE build_ret )

if( configure_ret OR build_ret )
message( FATAL_ERROR "Failed to download nlohmann/json" )
endif()

message( STATUS #CHECK_PASS
"Fetching nlohmann/json - Done" )
#list( POP_BACK CMAKE_MESSAGE_INDENT ) # Unindent outputs (requires cmake 3.15)

endfunction()

# Trigger the build
get_nlohmann_json()
43 changes: 41 additions & 2 deletions CMake/external_pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function(get_pybind11)
RESULT_VARIABLE build_ret )

if( configure_ret OR build_ret )
message( FATAL_ERROR "Failed to build pybind11" )
message( FATAL_ERROR "Failed to download pybind11" )
endif()

# Now that it's available, we can refer to it with an actual ExternalProject_add (but notice we're not
Expand Down Expand Up @@ -85,8 +85,45 @@ function(get_pybind11)

endfunction()


# We also want a json-compatible pybind interface:
function(get_pybind11_json)

message( STATUS #CHECK_START
"Fetching pybind11_json..." )
#list( APPEND CMAKE_MESSAGE_INDENT " " ) # Indent outputs

# We want to clone the pybind repo and build it here, during configuration, so we can use it.
# But ExternalProject_add is limited in that it only does its magic during build.
# This is possible in CMake 3.12+ with FetchContent and FetchContent_MakeAvailable in 3.14+ (meaning Ubuntu 20)
# but we need to adhere to CMake 3.10 (Ubuntu 18).
# So instead, we invoke a new CMake project just to download pybind:
configure_file( CMake/pybind11-json-download.cmake.in
${CMAKE_BINARY_DIR}/external-projects/pybind11-json-download/CMakeLists.txt )
execute_process( COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11-json-download"
OUTPUT_QUIET
RESULT_VARIABLE configure_ret )
execute_process( COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11-json-download"
OUTPUT_QUIET
RESULT_VARIABLE build_ret )

if( configure_ret OR build_ret )
message( FATAL_ERROR "Failed to download pybind11_json" )
endif()

# pybind11_add_module will add the directory automatically (see below)

message( STATUS #CHECK_PASS
"Fetching pybind11_json - Done" )
#list( POP_BACK CMAKE_MESSAGE_INDENT ) # Unindent outputs (requires cmake 3.15)

endfunction()

# Trigger the build
get_pybind11()
get_pybind11_json()

# This function overrides "pybind11_add_module" function, arguments is same as "pybind11_add_module" arguments
# pybind11_add_module(<name> SHARED [file, file2, ...] )
Expand All @@ -103,5 +140,7 @@ function( pybind11_add_module project_name library_type ...)
# (workaround for RS5-10582; see also https://github.com/pybind/pybind11/issues/2898)
# NOTE: this workaround seems to be needed for debug compilations only
target_compile_definitions( ${project_name} PRIVATE -DPYBIND11_COMPILER_TYPE=\"_${project_name}_abi\" )


target_include_directories( ${project_name} PRIVATE "${CMAKE_BINARY_DIR}/third-party/pybind11-json/include" )

endfunction()
19 changes: 19 additions & 0 deletions CMake/json-download.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.6)
project(nlohmann-json-download NONE)

include(ExternalProject)
ExternalProject_Add(
nlohmann_json
PREFIX .
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
#GIT_TAG v3.11.2
GIT_CONFIG advice.detachedHead=false # otherwise we'll get "You are in 'detached HEAD' state..."
SOURCE_DIR "${CMAKE_BINARY_DIR}/third-party/json"
GIT_SHALLOW 1 # No history needed (requires cmake 3.6)
# Override default steps with no action, we just want the clone step.
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)


19 changes: 19 additions & 0 deletions CMake/pybind11-json-download.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.6)
project(pybind11-json-download NONE)

include(ExternalProject)
ExternalProject_Add(
pybind11_json
PREFIX .
GIT_REPOSITORY "https://github.com/pybind/pybind11_json.git"
GIT_TAG 0.2.13
GIT_CONFIG advice.detachedHead=false # otherwise we'll get "You are in 'detached HEAD' state..."
SOURCE_DIR "${CMAKE_BINARY_DIR}/third-party/pybind11-json"
GIT_SHALLOW ON # No history needed (requires cmake 3.6)
# Override default steps with no action, we just want the clone step.
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)


6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ include(src/CMakeLists.txt)
include(third-party/CMakeLists.txt)
include(common/utilities/CMakeLists.txt)

include(CMake/external_json.cmake)
target_include_directories( rsutils
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/third-party/json/include>
)

target_link_libraries( ${LRS_TARGET} PUBLIC rsutils )

if(BUILD_WITH_DDS)
Expand Down
2 changes: 1 addition & 1 deletion common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <set>
#include "notifications.h"
#include "realsense-ui-advanced-mode.h"
#include <json.hpp>
#include <nlohmann/json.hpp>
#include "sw-update/dev-updates-profile.h"
#include <rsutils/time/periodic-timer.h>
#include "updates-model.h"
Expand Down
4 changes: 2 additions & 2 deletions common/rs-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "rs-config.h"

#include "../third-party/json.hpp"
#include <nlohmann/json.hpp>

#include "model-views.h"

Expand Down Expand Up @@ -139,4 +139,4 @@ config_file& config_file::operator=(const config_file& other)
bool config_file::operator==(const config_file& other) const
{
return _values == other._values;
}
}
2 changes: 1 addition & 1 deletion common/subdevice-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <array>
#include <unordered_map>

#include "../third-party/json.hpp"
#include <nlohmann/json.hpp>
#include "objects-in-frame.h"
#include "processing-block-model.h"

Expand Down
2 changes: 1 addition & 1 deletion common/sw-update/versions-db-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <algorithm>
#include <regex>

#include "json.hpp"
#include <nlohmann/json.hpp>
#include "versions-db-manager.h"
#include <types.h>

Expand Down
2 changes: 1 addition & 1 deletion src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "core/streaming.h"

#include <vector>
#include <third-party/json_fwd.hpp>
#include <nlohmann/json_fwd.hpp>
#include "media/playback/playback_device.h"

namespace librealsense
Expand Down
2 changes: 1 addition & 1 deletion src/ds/advanced_mode/json_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <string>
#include <iomanip>

#include "../../../third-party/json.hpp"
#include <nlohmann/json.hpp>
#include <librealsense2/h/rs_advanced_mode_command.h>
#include "types.h"
#include "presets.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-auto-calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright(c) 2016 Intel Corporation. All Rights Reserved.

#include <numeric>
#include "../third-party/json.hpp"
#include <nlohmann/json.hpp>
#include "d400-device.h"
#include "d400-private.h"
#include "d400-thermal-monitor.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "d400-thermal-monitor.h"
#include <common/fw/firmware-version.h>
#include <src/fw-update/fw-update-unsigned.h>
#include <third-party/json.hpp>
#include <nlohmann/json.hpp>

#include <regex>
#include <iterator>
Expand Down
2 changes: 1 addition & 1 deletion src/l500/l500-serializable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <set>
#include "l500-serializable.h"
#include "l500-options.h"
#include <third-party/json.hpp>
#include <nlohmann/json.hpp>
#include <src/serialized-utilities.h>

namespace librealsense
Expand Down
2 changes: 1 addition & 1 deletion src/serialized-utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <map>
#include <types.h>
#include <third-party/json.hpp>
#include <nlohmann/json.hpp>


namespace librealsense
Expand Down
2 changes: 1 addition & 1 deletion src/software-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <rsutils/string/from.h>
#include <rsutils/deferred.h>
#include <third-party/json.hpp>
#include <nlohmann/json.hpp>

using rsutils::deferred;

Expand Down
Loading