From a4bfc7fb366adc88931f662c20208dff8bc2899d Mon Sep 17 00:00:00 2001 From: William Robinet Date: Thu, 10 Aug 2023 09:36:12 +0200 Subject: [PATCH] Add FindJSONC.cmake module + fix CMakeLists.txt --- CMakeLists.txt | 12 ++++----- cmake/modules/FindJSONC.cmake | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 cmake/modules/FindJSONC.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e3dcaa8..777b306 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,12 +34,12 @@ set(SOURCES pcap/sys.c ) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules/") +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/" ${CMAKE_MODULE_PATH}) find_package(OpenSSL REQUIRED) find_package(PCAP REQUIRED) find_package(LIBNET REQUIRED) -find_package(json-c REQUIRED) +find_package(JSONC REQUIRED) add_executable(${PROJECT_NAME} ${SOURCES}) @@ -63,14 +63,14 @@ target_include_directories(ssldump ${OPENSSL_INCLUDE_DIR} ${PCAP_INCLUDE_DIR} ${LIBNET_INCLUDE_DIR} - ${json-c_INCLUDE_DIR} + ${JSONC_INCLUDE_DIRS} ) target_link_libraries(ssldump PRIVATE ${OPENSSL_LIBRARIES} - pcap - net - json-c + ${PCAP_LIBRARY} + ${LIBNET_LIBRARY} + ${JSONC_LIBRARIES} ) diff --git a/cmake/modules/FindJSONC.cmake b/cmake/modules/FindJSONC.cmake new file mode 100644 index 0000000..69b792f --- /dev/null +++ b/cmake/modules/FindJSONC.cmake @@ -0,0 +1,49 @@ +# From https://github.com/fastogt/cmake/blob/master/FindJSON-C.cmake +# Copyright (c) 2018, FastoGT +# License: BSD 3-Clause +# Modified by: Micah Snyder + +# JSONC_FOUND - true if library and headers were found +# JSONC_INCLUDE_DIRS - include directories +# JSONC_LIBRARIES - library directories + +if(JSONC_USE_STATIC) + add_library(jsonc STATIC IMPORTED GLOBAL) +else() + add_library(jsonc SHARED IMPORTED GLOBAL) +endif(JSONC_USE_STATIC) + +find_package(PkgConfig QUIET) +PKG_CHECK_MODULES(PC_JSONC QUIET json-c) + +find_path(JSONC_INCLUDE_DIR json.h + HINTS ${PC_JSONC_INCLUDEDIR} ${PC_JSONC_INCLUDE_DIRS} PATH_SUFFIXES json-c json) + +if(JSONC_USE_STATIC) + find_library(JSONC_LIBRARY NAMES libjson-c.a libjson-c-static.a + HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS}) +else() + find_library(JSONC_LIBRARY NAMES json-c libjson-c + HINTS ${PC_JSONC_LIBDIR} ${PC_JSONC_LIBRARY_DIRS}) +endif(JSONC_USE_STATIC) + +set(JSONC_LIBRARIES ${JSONC_LIBRARY}) +set(JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(JSONC DEFAULT_MSG JSONC_LIBRARIES JSONC_INCLUDE_DIRS) + +if(JSONC_FOUND AND NOT TARGET JSONC::jsonc) + add_library(JSONC::jsonc UNKNOWN IMPORTED) + set_target_properties(JSONC::jsonc PROPERTIES + IMPORTED_LOCATION "${JSONC_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_JSONC_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}" + ) +endif() + +mark_as_advanced( + JSONC_INCLUDE_DIR + JSONC_LIBRARY +) +