From a129d472abc454091fe257d88520313bf8a0c2c7 Mon Sep 17 00:00:00 2001 From: Mattia Verga Date: Sun, 3 Dec 2023 09:34:33 +0100 Subject: [PATCH] Allow using system provided json library Signed-off-by: Mattia Verga --- cmake_modules/FindINDI.cmake | 16 ++++++++++++++++ indi-avalonud/CMakeLists.txt | 16 +++++++++++++--- indi-avalonud/indi_avalonud_aux.cpp | 6 +++++- indi-avalonud/indi_avalonud_focuser.cpp | 6 +++++- indi-avalonud/indi_avalonud_telescope.cpp | 6 +++++- indi-weewx-json/CMakeLists.txt | 12 +++++++++++- indi-weewx-json/indi_weewx_json.h | 6 +++++- 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/cmake_modules/FindINDI.cmake b/cmake_modules/FindINDI.cmake index b18991f60..3297a9015 100644 --- a/cmake_modules/FindINDI.cmake +++ b/cmake_modules/FindINDI.cmake @@ -16,6 +16,7 @@ # The following variables will be defined for your use: # - INDI_FOUND : were all of your specified components found (include dependencies)? # - INDI_WEBSOCKET : was INDI compiled with websocket support? +# - INDI_JSONLIB : was INDI compiled with bundled json library? # - INDI_INCLUDE_DIR : INDI include directory # - INDI_DATA_DIR : INDI include directory # - INDI_LIBRARIES : INDI libraries @@ -199,6 +200,21 @@ else() SET(INDI_WEBSOCKET FALSE) endif() +find_path( + BUNDLED_JSONLIB + indijson.cpp + PATH_SUFFIXES libindi + ${PC_INDI_INCLUDE_DIR} + ${_obIncDir} + ${GNUWIN32_DIR}/include +) + +if (BUNDLED_JSONLIB) + SET(INDI_JSONLIB TRUE) +else() + SET(INDI_JSONLIB FALSE) +endif() + find_path(${INDI_PUBLIC_VAR_NS}_DATA_DIR drivers.xml PATH_SUFFIXES share/indi diff --git a/indi-avalonud/CMakeLists.txt b/indi-avalonud/CMakeLists.txt index 4b6c0a4ae..d0df185b7 100644 --- a/indi-avalonud/CMakeLists.txt +++ b/indi-avalonud/CMakeLists.txt @@ -13,6 +13,16 @@ find_package(INDI REQUIRED) find_package(Threads REQUIRED) find_package(ZMQ REQUIRED) +if(INDI_JSONLIB) + set(JSONLIB "") + message(STATUS "Using indi bundled json library") +else(INDI_JSONLIB) + find_package(nlohmann_json REQUIRED) + add_definitions(-D_USE_SYSTEM_JSONLIB) + set(JSONLIB nlohmann_json::nlohmann_json) + message(STATUS "Using system provided Niels Lohmann's json library") +endif(INDI_JSONLIB) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h @@ -37,7 +47,7 @@ add_executable( indi_avalonud_telescope ${CMAKE_CURRENT_SOURCE_DIR}/indi_avalonud_telescope.cpp ) -target_link_libraries(indi_avalonud_telescope ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES}) +target_link_libraries(indi_avalonud_telescope ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES} ${JSONLIB}) install(TARGETS indi_avalonud_telescope RUNTIME DESTINATION bin) @@ -47,7 +57,7 @@ add_executable( indi_avalonud_focuser ${CMAKE_CURRENT_SOURCE_DIR}/indi_avalonud_focuser.cpp ) -target_link_libraries(indi_avalonud_focuser ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES}) +target_link_libraries(indi_avalonud_focuser ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES} ${JSONLIB}) install(TARGETS indi_avalonud_focuser RUNTIME DESTINATION bin) @@ -57,7 +67,7 @@ add_executable( indi_avalonud_aux ${CMAKE_CURRENT_SOURCE_DIR}/indi_avalonud_aux.cpp ) -target_link_libraries(indi_avalonud_aux ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES}) +target_link_libraries(indi_avalonud_aux ${INDI_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ZMQ_LIBRARIES} ${JSONLIB}) install(TARGETS indi_avalonud_aux RUNTIME DESTINATION bin) diff --git a/indi-avalonud/indi_avalonud_aux.cpp b/indi-avalonud/indi_avalonud_aux.cpp index 751c5f862..e9fa7d571 100644 --- a/indi-avalonud/indi_avalonud_aux.cpp +++ b/indi-avalonud/indi_avalonud_aux.cpp @@ -25,7 +25,11 @@ #include #include #include -#include +#ifdef _USE_SYSTEM_JSONLIB +#include +#else +#include +#endif #include #include #include diff --git a/indi-avalonud/indi_avalonud_focuser.cpp b/indi-avalonud/indi_avalonud_focuser.cpp index 99a349d81..22caf1636 100644 --- a/indi-avalonud/indi_avalonud_focuser.cpp +++ b/indi-avalonud/indi_avalonud_focuser.cpp @@ -25,7 +25,11 @@ #include #include #include -#include +#ifdef _USE_SYSTEM_JSONLIB +#include +#else +#include +#endif #include #include #include diff --git a/indi-avalonud/indi_avalonud_telescope.cpp b/indi-avalonud/indi_avalonud_telescope.cpp index d12bd2347..d76a211dc 100644 --- a/indi-avalonud/indi_avalonud_telescope.cpp +++ b/indi-avalonud/indi_avalonud_telescope.cpp @@ -34,7 +34,11 @@ #include #include #include -#include +#ifdef _USE_SYSTEM_JSONLIB +#include +#else +#include +#endif #include #include #include diff --git a/indi-weewx-json/CMakeLists.txt b/indi-weewx-json/CMakeLists.txt index 5abe47d87..f65bd227b 100644 --- a/indi-weewx-json/CMakeLists.txt +++ b/indi-weewx-json/CMakeLists.txt @@ -15,6 +15,16 @@ set(CMAKE_CXX_FLAGS "-g -std=c++0x ${CMAKE_CXX_FLAGS}") find_package(INDI REQUIRED) find_package(CURL REQUIRED) +if(INDI_JSONLIB) + set(JSONLIB "") + message(STATUS "Using indi bundled json library") +else(INDI_JSONLIB) + find_package(nlohmann_json REQUIRED) + add_definitions(-D_USE_SYSTEM_JSONLIB) + set(JSONLIB nlohmann_json::nlohmann_json) + message(STATUS "Using system provided Niels Lohmann's json library") +endif(INDI_JSONLIB) + if (CMAKE_VERSION VERSION_LESS 3.12.0) set(CURL ${CURL_LIBRARIES}) else() @@ -38,7 +48,7 @@ set(weewx_SRCS add_executable(indi_weewx_json ${weewx_SRCS}) -target_link_libraries(indi_weewx_json ${INDI_LIBRARIES} ${INDI_DRIVER_LIBRARIES} ${CURL}) +target_link_libraries(indi_weewx_json ${INDI_LIBRARIES} ${INDI_DRIVER_LIBRARIES} ${CURL} ${JSONLIB}) install(TARGETS indi_weewx_json RUNTIME DESTINATION bin ) diff --git a/indi-weewx-json/indi_weewx_json.h b/indi-weewx-json/indi_weewx_json.h index 8be04b8dd..b26a51bad 100644 --- a/indi-weewx-json/indi_weewx_json.h +++ b/indi-weewx-json/indi_weewx_json.h @@ -27,7 +27,11 @@ #include #include -#include +#ifdef _USE_SYSTEM_JSONLIB +#include +#else +#include +#endif using json = nlohmann::json;