Skip to content

Commit

Permalink
Allow using system provided json library
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <[email protected]>
  • Loading branch information
mattiaverga committed Dec 25, 2023
1 parent 56f87ed commit a129d47
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
16 changes: 16 additions & 0 deletions cmake_modules/FindINDI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions indi-avalonud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion indi-avalonud/indi_avalonud_aux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <cstring>
#include <termios.h>
#include <stdarg.h>
#include <json.h>
#ifdef _USE_SYSTEM_JSONLIB
#include <nlohmann/json.hpp>
#else
#include <indijson.hpp>
#endif
#include <memory>
#include <time.h>
#include <chrono>
Expand Down
6 changes: 5 additions & 1 deletion indi-avalonud/indi_avalonud_focuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <cstring>
#include <termios.h>
#include <stdarg.h>
#include <json.h>
#ifdef _USE_SYSTEM_JSONLIB
#include <nlohmann/json.hpp>
#else
#include <indijson.hpp>
#endif
#include <memory>
#include <chrono>
#include <pthread.h>
Expand Down
6 changes: 5 additions & 1 deletion indi-avalonud/indi_avalonud_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <memory>
#include <json.h>
#ifdef _USE_SYSTEM_JSONLIB
#include <nlohmann/json.hpp>
#else
#include <indijson.hpp>
#endif
#include <chrono>
#include <pthread.h>
#include <zmq.h>
Expand Down
12 changes: 11 additions & 1 deletion indi-weewx-json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 )

Expand Down
6 changes: 5 additions & 1 deletion indi-weewx-json/indi_weewx_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

#include <libindi/indiweather.h>
#include <libindi/indipropertytext.h>
#include <libindi/json.h>
#ifdef _USE_SYSTEM_JSONLIB
#include <nlohmann/json.hpp>
#else
#include <indijson.hpp>
#endif

using json = nlohmann::json;

Expand Down

0 comments on commit a129d47

Please sign in to comment.