Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
cmake support for json-c
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperOptimizer committed Nov 19, 2024
1 parent e8c9c21 commit 2e826e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
33 changes: 33 additions & 0 deletions cmake/FindJsonC.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2e826e2

Please sign in to comment.