diff --git a/CMakeLists.txt b/CMakeLists.txt index 3537507..7c05ee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries(vesuvius_tests_sanitizer PUBLIC -lm) find_package(Blosc2 REQUIRED) find_package(CURL REQUIRED) +find_package(JsonC REQUIRED) if(Blosc2_FOUND) target_link_libraries(vesuvius_example PUBLIC Blosc2::Blosc2) @@ -47,5 +48,14 @@ else() message(FATAL_ERROR "CURL not found, please install curl") endif() +if(JsonC_FOUND) + target_link_libraries(vesuvius_example PUBLIC JsonC::JsonC) + target_link_libraries(vesuvius_example2 PUBLIC JsonC::JsonC) + target_link_libraries(vesuvius_tests PUBLIC JsonC::JsonC) + target_link_libraries(vesuvius_tests_sanitizer PUBLIC JsonC::JsonC) +else() + message(FATAL_ERROR "json-c not found, please install json-c: https://github.com/json-c/json-c") +endif() + target_compile_options(vesuvius_tests_sanitizer PUBLIC -fsanitize=address -fno-omit-frame-pointer) target_link_options(vesuvius_tests_sanitizer PUBLIC -fsanitize=address) diff --git a/cmake/FindJsonC.cmake b/cmake/FindJsonC.cmake new file mode 100644 index 0000000..c29e364 --- /dev/null +++ b/cmake/FindJsonC.cmake @@ -0,0 +1,33 @@ +# FindJsonC.cmake +# Defines: +# JSONC_FOUND - System has json-c +# JSONC_INCLUDE_DIRS - json-c include directories +# JSONC_LIBRARY - json-c library +# JsonC::JsonC - Imported target + +find_path(JSONC_INCLUDE_DIRS + NAMES json-c/json.h + PATHS ${JSONC_ROOT_DIR} + PATH_SUFFIXES include +) + +find_library(JSONC_LIBRARY + NAMES json-c + PATHS ${JSONC_ROOT_DIR} + PATH_SUFFIXES lib lib64 +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(JsonC + REQUIRED_VARS JSONC_LIBRARY 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_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}" + ) +endif() + +mark_as_advanced(JSONC_INCLUDE_DIRS JSONC_LIBRARY) \ No newline at end of file