Skip to content

Commit 97b4151

Browse files
authored
[DLStreamer] Update JSON dependencies with FetchContent (#1530)
1 parent cff797d commit 97b4151

File tree

11 files changed

+31
-123
lines changed

11 files changed

+31
-123
lines changed

libraries/dl-streamer/CMakeLists.txt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,6 @@ function (set_compile_flags TARGET)
6767
endif()
6868
endfunction(set_compile_flags)
6969

70-
# FIXME: replace with file(SIZE ...) when cmake version >= 3.14
71-
function(file_size FILE SIZE)
72-
file(READ "${FILE}" CONTENT HEX)
73-
string(LENGTH "${CONTENT}" CONTENT_LENGTH)
74-
set(${SIZE} ${CONTENT_LENGTH} PARENT_SCOPE)
75-
endfunction(file_size)
76-
77-
function(download_and_verify URL TARGET TARGET_NAME)
78-
if(NOT EXISTS ${TARGET})
79-
file(DOWNLOAD ${URL} ${TARGET} SHOW_PROGRESS STATUS DOWNLOAD_STATUS)
80-
list(GET DOWNLOAD_STATUS 0 RETURN_CODE)
81-
list(GET DOWNLOAD_STATUS 1 MESSAGE)
82-
if(NOT ${RETURN_CODE} EQUAL 0)
83-
file(REMOVE ${TARGET})
84-
message(FATAL_ERROR "Unable to download ${TARGET_NAME}: ${MESSAGE}")
85-
endif()
86-
endif()
87-
88-
file_size(${TARGET} FILE_SIZE)
89-
if(${FILE_SIZE} EQUAL 0)
90-
file(REMOVE ${TARGET})
91-
message(FATAL_ERROR "Invalid ${TARGET_NAME} downloaded")
92-
endif()
93-
94-
message(STATUS "Download of ${TARGET_NAME} is successful")
95-
endfunction(download_and_verify)
96-
9770
# Set output paths
9871
if (NOT(BIN_FOLDER))
9972
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")

libraries/dl-streamer/src/gst/bins/model_proc/json_reader.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
******************************************************************************/
@@ -96,6 +96,13 @@ GValue JsonReader::convertToGValue(const nlohmann::json::reference value, const
9696
// }
9797
break;
9898
}
99+
case nlohmann::json::value_t::binary: {
100+
g_value_init(&gvalue, G_TYPE_BYTES);
101+
const auto &binary_data = value.get_binary();
102+
GBytes *bytes = g_bytes_new(binary_data.data(), binary_data.size());
103+
g_value_take_boxed(&gvalue, bytes);
104+
break;
105+
}
99106
case nlohmann::json::value_t::discarded:
100107
case nlohmann::json::value_t::null:
101108
break;

libraries/dl-streamer/src/gst/bins/model_proc/json_reader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (C) 2020-2022 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
******************************************************************************/
@@ -8,7 +8,7 @@
88

99
#include <fstream>
1010
#include <gst/gst.h>
11-
#include <json-schema.hpp>
11+
#include <nlohmann/json-schema.hpp>
1212
#include <nlohmann/json.hpp>
1313
#include <string>
1414

libraries/dl-streamer/src/monolithic/gst/elements/gvametapublish/mqtt/gvametapublishmqtt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* SPDX-License-Identifier: MIT
55
******************************************************************************/
66

7-
#include "../../../../../../thirdparty/json/nlohmann/json.hpp"
87
#include <fstream>
98
#include <iostream>
9+
#include <nlohmann/json.hpp>
1010
using json = nlohmann::json;
1111

1212
#include "gvametapublishmqtt.hpp"

libraries/dl-streamer/thirdparty/CMakeLists.txt

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
# SPDX-License-Identifier: MIT
55
# ==============================================================================
66

7+
include(FetchContent)
8+
9+
# Support DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
10+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
11+
cmake_policy(SET CMP0135 NEW)
12+
endif()
13+
714
add_subdirectory(itt)
815

916
if(${ENABLE_TESTS})
@@ -21,40 +28,22 @@ if(${ENABLE_TESTS})
2128
endif()
2229
endif()
2330

24-
add_subdirectory(fff)
25-
set(FFF_SOURCE "https://raw.githubusercontent.com/meekrosoft/fff/v1.0/fff.h")
26-
set(FFF_PATH "${CMAKE_CURRENT_SOURCE_DIR}/fff/include/")
27-
set(FFF_HEADER "${FFF_PATH}/fff.h")
28-
29-
download_and_verify(${FFF_SOURCE} ${FFF_HEADER} "fff header")
30-
endif()
31-
32-
# Populate thirdparty/json dependency
33-
set(JSONCONVERT_SOURCE "https://github.com/nlohmann/json/releases/download/v3.7.3/json.hpp")
34-
set(JSONCONVERT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/json/nlohmann")
35-
set(JSONCONVERT_HEADER "${JSONCONVERT_PATH}/json.hpp")
36-
set(JSONVALIDATOR_SOURCE "https://github.com/pboettch/json-schema-validator/archive/2.0.0.tar.gz")
37-
set(JSONVALIDATOR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/json/pboettch")
38-
set(JSONVALIDATOR_TAR "${JSONVALIDATOR_PATH}/jsonvalidator.tar.gz")
39-
set(JSONVALIDATOR_HEADER "${JSONVALIDATOR_PATH}/json-schema-validator-2.0.0/src/json-schema.hpp")
40-
41-
download_and_verify(${JSONCONVERT_SOURCE} ${JSONCONVERT_HEADER} "JSON header")
42-
43-
if(NOT EXISTS ${JSONVALIDATOR_HEADER})
44-
download_and_verify(${JSONVALIDATOR_SOURCE} ${JSONVALIDATOR_TAR} "JSON validator")
45-
46-
execute_process(
47-
COMMAND ${CMAKE_COMMAND} -E tar xzf ${JSONVALIDATOR_TAR}
48-
WORKING_DIRECTORY ${JSONVALIDATOR_PATH}
49-
)
50-
# fix build issue
51-
execute_process(
52-
COMMAND sed -i "s/&c : s/c : s/g" json-schema-validator-2.0.0/src/json-validator.cpp
53-
WORKING_DIRECTORY ${JSONVALIDATOR_PATH}
31+
FetchContent_Declare(
32+
fff
33+
URL https://github.com/meekrosoft/fff/archive/5111c61e1ef7848e3afd3550044a8cf4405f4199.zip
5434
)
35+
FetchContent_MakeAvailable(fff)
5536
endif()
5637

57-
add_subdirectory(json)
38+
# Populate json dependency
39+
set(nlohmann_json_VERSION v3.12.0)
40+
FetchContent_Declare(
41+
json_schema_validator
42+
URL https://github.com/pboettch/json-schema-validator/archive/2.4.0.tar.gz
43+
)
44+
FetchContent_MakeAvailable(json_schema_validator)
45+
add_library(json-hpp ALIAS nlohmann_json)
46+
add_library(json-schema-validator ALIAS nlohmann_json_schema_validator)
5847

5948
# Hint compiler about location of the header file generated.
6049
include_directories(${CMAKE_CURRENT_BINARY_DIR})

libraries/dl-streamer/thirdparty/fff/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

libraries/dl-streamer/thirdparty/fff/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

libraries/dl-streamer/thirdparty/json/.gitignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

libraries/dl-streamer/thirdparty/json/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

libraries/dl-streamer/thirdparty/json/nlohmann/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)