Skip to content

Commit 1e64995

Browse files
committed
find json-c on darwin
1 parent f52833f commit 1e64995

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

library/CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (TARGET json-c::json-c)
5151
set(jsonc_libs json-c::json-c)
5252
else()
5353
pkg_check_modules(JSONC json-c)
54-
if (JSONC_FOUND)
54+
if (JSONC_FOUND AND JSONC_INCLUDE_DIRS AND JSONC_LIBRARIES)
5555
if (NOT TARGET json-c::json-c)
5656
add_library(json-c::json-c INTERFACE IMPORTED)
5757
set_target_properties(json-c::json-c PROPERTIES
@@ -62,11 +62,28 @@ else()
6262
set(jsonc_libs json-c::json-c)
6363
message("json-c [${JSONC_VERSION}] is ${JSONC_LINK_LIBRARIES}")
6464
else()
65-
find_package(json-c REQUIRED)
66-
if (TARGET json-c::json-c)
67-
set(jsonc_libs json-c::json-c)
65+
# Try Homebrew default path on macOS
66+
if(APPLE)
67+
find_path(JSONC_INCLUDE_DIRS json-c/json.h PATHS /opt/homebrew/include /usr/local/include)
68+
find_library(JSONC_LIBRARIES json-c PATHS /opt/homebrew/lib /usr/local/lib)
69+
if(JSONC_INCLUDE_DIRS AND JSONC_LIBRARIES)
70+
add_library(json-c::json-c INTERFACE IMPORTED)
71+
set_target_properties(json-c::json-c PROPERTIES
72+
INTERFACE_INCLUDE_DIRECTORIES "${JSONC_INCLUDE_DIRS}"
73+
INTERFACE_LINK_LIBRARIES "${JSONC_LIBRARIES}"
74+
)
75+
set(jsonc_libs json-c::json-c)
76+
message("json-c (manual Homebrew) is ${JSONC_LIBRARIES}")
77+
else()
78+
message(FATAL_ERROR "Could not find required library [json-c] (tried pkg-config and Homebrew paths)")
79+
endif()
6880
else()
69-
message(FATAL_ERROR "Could not find required library [json-c]")
81+
find_package(json-c REQUIRED)
82+
if (TARGET json-c::json-c)
83+
set(jsonc_libs json-c::json-c)
84+
else()
85+
message(FATAL_ERROR "Could not find required library [json-c]")
86+
endif()
7087
endif()
7188
endif()
7289
endif()

0 commit comments

Comments
 (0)