Skip to content

Commit 1cc9090

Browse files
refactor: make use system cJSON library possible (#314)
* refactor: move cJSON_ex.* to a new object library Signed-off-by: Coelacanthus <[email protected]> * refactor: make use system cJSON library possible * When USE_SYSTEM_DEPS is set, follow it. * When USE_SYSTEM_DEPS is unset, try use system cJSON first, and fallback to vendor one if not found. Signed-off-by: Coelacanthus <[email protected]> * refactor: use FetchContent to download cJSON instead of vendor GIT_REPOSITORY and GIT_TAG SHALL be changed back if [1] was merged and upstream released new version. [1]: DaveGamble/cJSON#949 Signed-off-by: Coelacanthus <[email protected]> * chore: remove unneeded vendor version cJSON Signed-off-by: Coelacanthus <[email protected]> * chore(ci): more robust license file copy... Signed-off-by: Coelacanthus <[email protected]> --------- Signed-off-by: Coelacanthus <[email protected]>
1 parent d009e29 commit 1cc9090

File tree

23 files changed

+74
-3479
lines changed

23 files changed

+74
-3479
lines changed

.github/scripts/functions.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ function download {
4343
function copy-license {
4444
local OUTPUT="$1"
4545

46-
cp "$WORKSPACE/src/LICENSE" "$OUTPUT/LICENSE-lpac"
47-
cp "$WORKSPACE/euicc/LICENSE" "$OUTPUT/LICENSE-libeuicc"
48-
cp "$WORKSPACE/cjson/LICENSE" "$OUTPUT/LICENSE-cjson"
49-
cp "$WORKSPACE/dlfcn-win32/LICENSE" "$OUTPUT/LICENSE-dlfcn-win32"
46+
mkdir "$OUTPUT/LICENSES"
47+
cp -r "$WORKSPACE/LICENSES" "$OUTPUT/LICENSES"
5048
}
5149

5250
function copy-curl-woa {

CMakeLists.txt

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,46 @@ if(CPACK_GENERATOR)
6565
include(CPack)
6666
endif()
6767

68-
add_subdirectory(cjson)
68+
include(FetchContent)
69+
FetchContent_Declare(
70+
cjson
71+
# FIXME: change back to DaveGamble/cJSON if upstream fix it
72+
# https://github.com/DaveGamble/cJSON/pull/949
73+
# https://github.com/DaveGamble/cJSON/pull/955
74+
GIT_REPOSITORY https://github.com/CoelacanthusHex/cJSON
75+
GIT_TAG 4818f043bda624b5738384eae3a0189b2bd1f5e1
76+
GIT_PROGRESS ON
77+
SOURCE_DIR cjson
78+
)
79+
if (NOT DEFINED USE_SYSTEM_DEPS)
80+
find_package(cJSON)
81+
if (NOT cJSON_FOUND)
82+
if (NOT NO_NETWORK)
83+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
84+
set(CJSON_BUILD_SHARED_LIBS OFF)
85+
set(ENABLE_CJSON_TEST OFF)
86+
set(ENABLE_CUSTOM_COMPILER_FLAGS OFF)
87+
FetchContent_MakeAvailable(cjson)
88+
set(CJSON_LIBRARY cjson)
89+
else()
90+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
91+
endif()
92+
endif()
93+
else()
94+
if (USE_SYSTEM_DEPS)
95+
find_package(cJSON REQUIRED)
96+
elseif(NOT NO_NETWORK)
97+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
98+
set(CJSON_BUILD_SHARED_LIBS OFF)
99+
set(ENABLE_CJSON_TEST OFF)
100+
set(ENABLE_CUSTOM_COMPILER_FLAGS OFF)
101+
FetchContent_MakeAvailable(cjson)
102+
set(CJSON_LIBRARY cjson)
103+
else()
104+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
105+
endif()
106+
endif()
107+
add_subdirectory(cjson-ext)
69108
add_subdirectory(euicc)
70109
add_subdirectory(utils)
71110
add_subdirectory(driver)

REUSE.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ SPDX-FileCopyrightText = "2023-2025 ESTKME TECHNOLOGY LIMITED, Hong Kong"
3434
SPDX-License-Identifier = "MIT"
3535

3636
[[annotations]]
37-
path = ["cjson/**"]
38-
SPDX-FileCopyrightText = "2009-2017 Dave Gamble and cJSON contributors"
37+
path = ["cjson-ext/**"]
38+
SPDX-FileCopyrightText = "2023-2025 ESTKME TECHNOLOGY LIMITED, Hong Kong"
3939
SPDX-FileContributor = [
40-
"ESTKME TECHNOLOGY LIMITED, Hong Kong",
41-
"Celeste Liu"
40+
"Celeste Liu",
4241
]
4342
SPDX-License-Identifier = "MIT"
4443

cjson-ext/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_library(cjson-ext OBJECT cjson-ext/cJSON_ex.c)
2+
target_include_directories(cjson-ext PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
3+
target_link_libraries(cjson-ext PRIVATE ${CJSON_LIBRARY})
4+
target_compile_options(cjson-ext PRIVATE -Wall -Wextra)

cjson-ext/cjson-ext/cJSON_ex.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "cJSON_ex.h"
2+
3+
cJSON *cJSON_AddStringOrNullToObject(cJSON *const object, const char *const name, const char *const string) {
4+
if (string) {
5+
return cJSON_AddStringToObject(object, name, string);
6+
} else {
7+
return cJSON_AddNullToObject(object, name);
8+
}
9+
}

cjson-ext/cjson-ext/cJSON_ex.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <cjson/cJSON.h>
4+
5+
cJSON *cJSON_AddStringOrNullToObject(cJSON *const object, const char *const name, const char *const string);

cjson/CMakeLists.txt

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

cjson/LICENSE

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

0 commit comments

Comments
 (0)