build: Support building with system cJSON.

Fixes #62.
This commit is contained in:
Ryan Pavlik 2020-03-31 14:58:04 -05:00 committed by Jakob Bornecrantz
parent a11f5cc429
commit 7fab448cf0
4 changed files with 80 additions and 1 deletions

View file

@ -34,6 +34,7 @@ find_package(realsense2)
find_package(SDL2)
find_package(Threads)
find_package(ZLIB)
find_package(cJSON)
# @TODO Turn into a find_package LIBUVC file.
pkg_check_modules(LIBUVC libuvc)
@ -94,6 +95,8 @@ cmake_dependent_option(BUILD_WITH_SDL2 "Enable SDL2 based test application" ON "
cmake_dependent_option(BUILD_WITH_DAYDREAM "Enable Bluetooth LE via DBUS" ON "BUILD_WITH_DBUS" OFF)
cmake_dependent_option(BUILD_WITH_ARDUINO "Enable Arduino input device with BLE via DBUS" ON "BUILD_WITH_DBUS" OFF)
cmake_dependent_option(BUILD_WITH_SYSTEM_CJSON "Enable cJSON from system, instead of bundled source" ON "CJSON_FOUND" OFF)
# These all use the Monado internal hid wrapper which is assumed to be available.
option(BUILD_WITH_HDK "Enable HDK driver" ON)
option(BUILD_WITH_PSMV "Enable Playstation Move driver" ON)

69
cmake/FindcJSON.cmake Normal file
View file

@ -0,0 +1,69 @@
# Copyright 2019-2020, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Original Author:
# 2019-2020 Ryan Pavlik <ryan.pavlik@collabora.com>
#.rst:
# FindcJSON
# ---------------
#
# Find the cJSON lightweight JSON parser
#
# Targets
# ^^^^^^^
#
# If successful, the following import target is created.
#
# ``cJSON::cJSON``
#
# Cache variables
# ^^^^^^^^^^^^^^^
#
# The following cache variable may also be set to assist/control the operation of this module:
#
# ``CJSON_ROOT_DIR``
# The root to search for cJSON.
set(CJSON_ROOT_DIR "${CJSON_ROOT_DIR}" CACHE PATH "Root to search for cJSON")
find_path(CJSON_INCLUDE_DIR
NAMES
cjson/cJSON.h
PATHS
${CJSON_ROOT_DIR}
PATH_SUFFIXES
include
)
find_library(CJSON_LIBRARY
NAMES
cjson
PATHS
${CJSON_ROOT_DIR}
PATH_SUFFIXES
lib
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cJSON
REQUIRED_VARS
CJSON_INCLUDE_DIR
CJSON_LIBRARY
)
if(CJSON_FOUND)
set(CJSON_INCLUDE_DIRS "${CJSON_INCLUDE_DIR}")
set(CJSON_LIBRARIES "${CJSON_LIBRARY}")
if(NOT TARGET cJSON::cJSON)
add_library(cJSON::cJSON UNKNOWN IMPORTED)
endif()
set_target_properties(cJSON::cJSON PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CJSON_INCLUDE_DIR}")
set_target_properties(cJSON::cJSON PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${CJSON_LIBRARY}")
mark_as_advanced(CJSON_INCLUDE_DIR CJSON_LIBRARY)
endif()
mark_as_advanced(CJSON_ROOT_DIR)

View file

@ -141,13 +141,17 @@ target_include_directories(aux_math SYSTEM
# Util library.
add_library(aux_util STATIC ${UTIL_SOURCE_FILES})
target_link_libraries(aux_util PUBLIC aux-includes)
# for cJSON
target_link_libraries(aux_util PUBLIC xrt-external-headers)
# for u_device
target_link_libraries(aux_util PUBLIC aux_math)
if(BUILD_WITH_JPEG)
target_link_libraries(aux_util PRIVATE ${JPEG_LIBRARIES})
endif()
# for cJSON
if(BUILD_WITH_SYSTEM_CJSON)
target_link_libraries(aux_util PUBLIC cJSON::cJSON)
target_compile_definitions(aux_util PRIVATE XRT_USE_SYSTEM_CJSON)
endif()
# Tracking library.
add_library(aux_tracking STATIC ${TRACKING_SOURCE_FILES})

View file

@ -10,9 +10,12 @@
#include "u_json.h"
#include <assert.h>
#include <stdio.h>
#ifndef XRT_USE_SYSTEM_CJSON
// This includes the c file completely.
#include "cjson/cJSON.c"
#endif
/*!