From b0093868b390f89818ad41ac97011332379b4c77 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 13 Feb 2021 15:10:48 +0100 Subject: [PATCH] eliminate cJSON submodule --- .gitmodules | 3 -- CMakeLists.txt | 2 +- cJSON | 1 - cmake/Modules/FindCJSON.cmake | 59 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 12 +++---- src/json.c | 3 +- src/util/crypto/CMakeLists.txt | 2 +- 7 files changed, 67 insertions(+), 15 deletions(-) delete mode 160000 cJSON create mode 100644 cmake/Modules/FindCJSON.cmake diff --git a/.gitmodules b/.gitmodules index 7a89a17be..306652a59 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "cJSON"] - path = cJSON - url = https://github.com/ennorehling/cJSON.git [submodule "storage"] path = storage url = https://github.com/ennorehling/storage.git diff --git a/CMakeLists.txt b/CMakeLists.txt index b9c5c7818..4447944f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ endif (NOT CURSES_FOUND) find_package (SQLite3 REQUIRED) find_package (IniParser REQUIRED) +find_package (CJSON REQUIRED) find_package (EXPAT REQUIRED) find_package (ToLua REQUIRED) if (TOLUA_FOUND) @@ -53,7 +54,6 @@ endif(TOLUA_FOUND) enable_testing() -add_subdirectory (cJSON) add_subdirectory (storage) add_subdirectory (clibs) add_subdirectory (process) diff --git a/cJSON b/cJSON deleted file mode 160000 index 460207f9c..000000000 --- a/cJSON +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 460207f9c09d501a2e302e5313b2f67dca0d6d63 diff --git a/cmake/Modules/FindCJSON.cmake b/cmake/Modules/FindCJSON.cmake new file mode 100644 index 000000000..83b924930 --- /dev/null +++ b/cmake/Modules/FindCJSON.cmake @@ -0,0 +1,59 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindCJSON +----------- + +.. versionadded:: 3.20 + +Find the cJSON libraries, v3 + +IMPORTED targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` target: + +``DaveGamble::CJSON`` + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables if found: + +``CJSON_INCLUDE_DIRS`` + where to find sqlite3.h, etc. +``CJSON_LIBRARIES`` + the libraries to link against to use CJSON. +``CJSON_VERSION`` + version of the CJSON library found +``CJSON_FOUND`` + TRUE if found + +#]=======================================================================] + +# Look for the necessary header +find_path(CJSON_INCLUDE_DIR cJSON.h PATH_SUFFIXES cjson) +mark_as_advanced(CJSON_INCLUDE_DIR) + +# Look for the necessary library +find_library(CJSON_LIBRARY cjson) +mark_as_advanced(CJSON_LIBRARY) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CJSON + REQUIRED_VARS CJSON_INCLUDE_DIR CJSON_LIBRARY + VERSION_VAR CJSON_VERSION) + +# Create the imported target +if(CJSON_FOUND) + set(CJSON_INCLUDE_DIRS ${CJSON_INCLUDE_DIR}) + set(CJSON_LIBRARIES ${CJSON_LIBRARY}) + if(NOT TARGET DaveGamble::CJSON) + add_library(DaveGamble::CJSON UNKNOWN IMPORTED) + set_target_properties(DaveGamble::CJSON PROPERTIES + IMPORTED_LOCATION "${CJSON_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${CJSON_INCLUDE_DIR}") + endif() +endif() + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ec49bf09..afb619f8c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) -include_directories (${CJSON_INCLUDE_DIR}) include_directories (${CRYPTO_INCLUDE_DIR}) include_directories (${CLIBS_INCLUDE_DIR}) include_directories (${STORAGE_INCLUDE_DIR}) @@ -209,7 +208,7 @@ target_link_libraries(eressea ${LUA_LIBRARIES} ${STORAGE_LIBRARIES} ${CJSON_LIBRARIES} - ${INIPARSER_LIBRARIES} + ${IniParser_LIBRARIES} ) set(TESTS_SRC @@ -268,7 +267,7 @@ target_link_libraries(test_eressea ${CLIBS_LIBRARIES} ${STORAGE_LIBRARIES} ${CJSON_LIBRARIES} - ${INIPARSER_LIBRARIES} + ${IniParser_LIBRARIES} ) add_test(server test_eressea) @@ -301,11 +300,8 @@ if (HAVE_LIBBSD) target_link_libraries(parser bsd) endif (HAVE_LIBBSD) -if (IniParser_FOUND) -target_include_directories(game PUBLIC ${IniParser_INCLUDE_DIRS}) -target_link_libraries(eressea ${IniParser_LIBRARIES}) -target_link_libraries(test_eressea ${IniParser_LIBRARIES}) -endif (IniParser_FOUND) +target_include_directories (game PUBLIC ${CJSON_INCLUDE_DIRS}) +target_include_directories (game PUBLIC ${IniParser_INCLUDE_DIRS}) if (SQLite3_FOUND) target_include_directories (game PRIVATE ${SQLite3_INCLUDE_DIRS}) diff --git a/src/json.c b/src/json.c index 127d74f70..f25970af0 100644 --- a/src/json.c +++ b/src/json.c @@ -9,7 +9,8 @@ #include #include #include -#include "cJSON.h" + +#include #include #include diff --git a/src/util/crypto/CMakeLists.txt b/src/util/crypto/CMakeLists.txt index 9a82ff926..735dabc0a 100644 --- a/src/util/crypto/CMakeLists.txt +++ b/src/util/crypto/CMakeLists.txt @@ -13,7 +13,7 @@ SET (LIB_SRC ) ADD_LIBRARY (crypto ${LIB_SRC}) -set (CRYPTO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "cJSON headers") +set (CRYPTO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "crypto headers") set (CRYPTO_LIBRARIES crypto CACHE INTERNAL "crypto libraries") IF(WIN32)