Skip to content

Commit b26c919

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 93f3907 commit b26c919

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,41 @@ if(CPACK_GENERATOR)
6565
include(CPack)
6666
endif()
6767

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+
)
6879
if (NOT DEFINED USE_SYSTEM_DEPS)
6980
find_package(cJSON)
7081
if (NOT cJSON_FOUND)
71-
add_subdirectory(cjson)
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+
FetchContent_MakeAvailable(cjson)
87+
set(CJSON_LIBRARY cjson)
88+
else()
89+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
90+
endif()
7291
endif()
7392
else()
7493
if (USE_SYSTEM_DEPS)
7594
find_package(cJSON REQUIRED)
95+
elseif(NOT NO_NETWORK)
96+
set(CJSON_OVERRIDE_BUILD_SHARED_LIBS ON)
97+
set(CJSON_BUILD_SHARED_LIBS OFF)
98+
set(ENABLE_CJSON_TEST OFF)
99+
FetchContent_MakeAvailable(cjson)
100+
set(CJSON_LIBRARY cjson)
76101
else()
77-
add_subdirectory(cjson)
102+
message(FATAL_ERROR "System cJSON is not found and network access is not permitted!")
78103
endif()
79104
endif()
80105
add_subdirectory(cjson-ext)

0 commit comments

Comments
 (0)