Skip to content

Commit b387106

Browse files
committed
troubleshoot macos json-c discovery
1 parent 1e64995 commit b387106

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

library/CMakeLists.txt

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ 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 AND JSONC_INCLUDE_DIRS AND JSONC_LIBRARIES)
54+
if (JSONC_FOUND AND JSONC_INCLUDE_DIRS)
55+
# Ensure we have the full path to the library, not just 'json-c'
56+
find_library(JSONC_LIB NAMES json-c PATHS ${JSONC_LIBRARY_DIRS} /usr/lib/x86_64-linux-gnu /usr/lib /lib)
57+
if (JSONC_LIB)
58+
set(JSONC_LIBRARIES "${JSONC_LIB}")
59+
endif()
5560
if (NOT TARGET json-c::json-c)
5661
add_library(json-c::json-c INTERFACE IMPORTED)
5762
set_target_properties(json-c::json-c PROPERTIES
@@ -60,31 +65,15 @@ else()
6065
)
6166
endif()
6267
set(jsonc_libs json-c::json-c)
63-
message("json-c [${JSONC_VERSION}] is ${JSONC_LINK_LIBRARIES}")
68+
message("json-c [${JSONC_VERSION}] is ${JSONC_LIBRARIES}")
6469
else()
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()
70+
find_package(json-c REQUIRED)
71+
if (TARGET json-c::json-c)
72+
set(jsonc_libs json-c::json-c)
8073
else()
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()
74+
message(FATAL_ERROR "Could not find required library [json-c]")
8775
endif()
76+
8877
endif()
8978
endif()
9079
if (NOT jsonc_libs)

0 commit comments

Comments
 (0)