Skip to content

Commit 28786d2

Browse files
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]>
1 parent 93f3907 commit 28786d2

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

CMakeLists.txt

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,47 @@ endif()
6868
if (NOT DEFINED USE_SYSTEM_DEPS)
6969
find_package(cJSON)
7070
if (NOT cJSON_FOUND)
71-
add_subdirectory(cjson)
71+
if (NOT NO_NETWORK)
72+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
73+
set(CJSON_BUILD_SHARED_LIBS OFF)
74+
include(FetchContent)
75+
FetchContent_Declare(
76+
cjson
77+
# FIXME: change back to DaveGamble/cJSON if upstream fix it
78+
# https://github.com/DaveGamble/cJSON/pull/949
79+
# https://github.com/DaveGamble/cJSON/pull/955
80+
GIT_REPOSITORY https://github.com/CoelacanthusHex/cJSON
81+
GIT_TAG 4818f043bda624b5738384eae3a0189b2bd1f5e1
82+
GIT_PROGRESS ON
83+
SOURCE_DIR cjson
84+
)
85+
FetchContent_MakeAvailable(cjson)
86+
set(CJSON_LIBRARY cjson)
87+
else()
88+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
89+
endif()
7290
endif()
7391
else()
7492
if (USE_SYSTEM_DEPS)
7593
find_package(cJSON REQUIRED)
94+
elseif(NOT NO_NETWORK)
95+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
96+
set(CJSON_BUILD_SHARED_LIBS OFF)
97+
include(FetchContent)
98+
FetchContent_Declare(
99+
cjson
100+
# FIXME: change back to DaveGamble/cJSON if upstream fix it
101+
# https://github.com/DaveGamble/cJSON/pull/949
102+
# https://github.com/DaveGamble/cJSON/pull/955
103+
GIT_REPOSITORY https://github.com/CoelacanthusHex/cJSON
104+
GIT_TAG 4818f043bda624b5738384eae3a0189b2bd1f5e1
105+
GIT_PROGRESS ON
106+
SOURCE_DIR cjson
107+
)
108+
FetchContent_MakeAvailable(cjson)
109+
set(CJSON_LIBRARY cjson)
76110
else()
77-
add_subdirectory(cjson)
111+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
78112
endif()
79113
endif()
80114
add_subdirectory(cjson-ext)

0 commit comments

Comments
 (0)