Skip to content

Commit ef7d985

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 <uwu@coelacanthus.name>
1 parent 4476765 commit ef7d985

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

CMakeLists.txt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,45 @@ 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+
GIT_REPOSITORY https://github.com/p1k0chu/cJSON
80+
GIT_TAG 887642c0a93bd8a6616bf90daacac0ea7d4b095e
81+
GIT_PROGRESS ON
82+
SOURCE_DIR cjson
83+
)
84+
FetchContent_MakeAvailable(cJSON)
85+
set(CJSON_LIBRARY cJSON)
86+
else()
87+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
88+
endif()
7289
endif()
7390
else()
7491
if (USE_SYSTEM_DEPS)
7592
find_package(cJSON REQUIRED)
93+
elseif(NOT NO_NETWORK)
94+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
95+
set(CJSON_BUILD_SHARED_LIBS OFF)
96+
include(FetchContent)
97+
FetchContent_Declare(
98+
cjson
99+
# FIXME: change back to DaveGamble/cJSON if upstream fix it
100+
# https://github.com/DaveGamble/cJSON/pull/949
101+
GIT_REPOSITORY https://github.com/p1k0chu/cJSON
102+
GIT_TAG 887642c0a93bd8a6616bf90daacac0ea7d4b095e
103+
GIT_PROGRESS ON
104+
SOURCE_DIR cjson
105+
)
106+
FetchContent_MakeAvailable(cjson)
107+
set(CJSON_LIBRARY cjson)
76108
else()
77-
add_subdirectory(cjson)
109+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
78110
endif()
79111
endif()
80112
add_subdirectory(cjson-ext)

0 commit comments

Comments
 (0)