diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bf9af5..721a01b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ option (BUILDSWIGJAVA "Build Java API." OFF) option (USBPLAT "Detection USB platform." OFF) option (FIRMATA "Add Firmata support to mraa." OFF) option (ONEWIRE "Add Onewire support to mraa." ON) +option (JSONPLAT "Add Platform loading via a json file." ON) option (IMRAA "Add Imraa support to mraa." OFF) option (FTDI4222 "Build with FTDI FT4222 subplatform support." OFF) option (IPK "Generate IPK using CPack" OFF) diff --git a/cmake/modules/FindJSON-C.cmake b/cmake/modules/FindJSON-C.cmake index dd8a418..f96701e 100644 --- a/cmake/modules/FindJSON-C.cmake +++ b/cmake/modules/FindJSON-C.cmake @@ -3,7 +3,7 @@ # JSON-C_LIBRARIES - library directories find_package (PkgConfig) -pkg_check_modules (PC_JSON-C QUIET json-c) +pkg_search_module (PC_JSON-C QUIET json-c json) find_path (JSON-C_INCLUDE_DIR json.h HINTS ${PC_JSON-C_INCLUDEDIR} ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ac11bd..6b7a9f8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,8 +92,19 @@ set (mraa_LIB_MOCK_SRCS_NOAUTO ${PROJECT_SOURCE_DIR}/src/mock/mock_board_i2c.c ) +if (JSONPLAT) + find_package (JSON-C QUIET) + if (${JSON-C_FOUND}) + set (mraa_LIB_SRCS_NOAUTO + ${mraa_LIB_SRCS_NOAUTO} + ${PROJECT_SOURCE_DIR}/src/json/jsonplatform.c + ) + endif () +endif () + set (mraa_LIBS ${CMAKE_THREAD_LIBS_INIT}) + if (X86PLAT) add_subdirectory(x86) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DX86PLAT=1") @@ -136,11 +147,24 @@ if (USBPLAT) add_subdirectory(usb) endif () -if (IMRAA) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1") - find_package (JSON-C REQUIRED) - include_directories (${JSON-C_INCLUDE_DIR}) - set (mraa_LIBS ${mraa_LIBS} ${JSON-C_LIBRARIES}) +if (JSONPLAT OR IMRAA) + find_package (JSON-C QUIET) + if (NOT ${JSON-C_FOUND}) + if (IMRAA) + message (FATAL_ERROR "Enabled IMRAA but JSON-C library not found") + elseif (JSONPLAT) + message (WARNING "Enabled JSONPLAT but JSON-C library not found: Ignoring JSONPLAT") + endif () + else () + if (JSONPLAT) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DJSONPLAT=1") + endif () + if (IMRAA) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIMRAA=1") + endif () + include_directories (${JSON-C_INCLUDE_DIR}) + set (mraa_LIBS ${mraa_LIBS} ${JSON-C_LIBRARIES}) + endif () endif () set (mraa_LIB_SRCS