@@ -48,19 +48,37 @@ endif()
4848# Find and link jsoncpp
4949set (JSONCPP_FOUND FALSE )
5050
51- # Try pkg-config first (works on Linux and Homebrew macOS)
52- find_package (PkgConfig QUIET )
53- if (PkgConfig_FOUND)
54- pkg_check_modules (JSONCPP jsoncpp )
55- if (JSONCPP_FOUND)
56- target_include_directories (netmgr PRIVATE ${JSONCPP_INCLUDE_DIRS} )
57- target_link_libraries (netmgr ${JSONCPP_LIBRARIES} )
58- target_compile_options (netmgr PRIVATE ${JSONCPP_CFLAGS_OTHER} )
59- message (STATUS "Found jsoncpp via pkg-config" )
51+ # On macOS with vcpkg, try vcpkg's find_package first
52+ if (APPLE AND DEFINED CMAKE_TOOLCHAIN_FILE )
53+ find_package (jsoncpp CONFIG QUIET )
54+ if (jsoncpp_FOUND)
55+ target_link_libraries (netmgr jsoncpp_lib )
56+ set (JSONCPP_FOUND TRUE )
57+ message (STATUS "Found jsoncpp via vcpkg find_package" )
58+ endif ()
59+ endif ()
60+
61+ # Try pkg-config if vcpkg didn't work
62+ if (NOT JSONCPP_FOUND)
63+ find_package (PkgConfig QUIET )
64+ if (PkgConfig_FOUND)
65+ pkg_check_modules (JSONCPP jsoncpp )
66+ if (JSONCPP_FOUND)
67+ # Debug: Print what pkg-config found
68+ message (STATUS "pkg-config jsoncpp libraries: ${JSONCPP_LIBRARIES} " )
69+ message (STATUS "pkg-config jsoncpp library dirs: ${JSONCPP_LIBRARY_DIRS} " )
70+ message (STATUS "pkg-config jsoncpp include dirs: ${JSONCPP_INCLUDE_DIRS} "
71+
72+ target_include_directories(netmgr PRIVATE ${JSONCPP_INCLUDE_DIRS} )
73+ target_link_directories(netmgr PRIVATE ${JSONCPP_LIBRARY_DIRS} )
74+ target_link_libraries(netmgr ${JSONCPP_LIBRARIES} )
75+ target_compile_options(netmgr PRIVATE ${JSONCPP_CFLAGS_OTHER} )
76+ message(STATUS "Found jsoncpp via pkg-config" )
77+ endif()
6078 endif()
6179endif()
6280
63- # Fallback to find_path/find_library (works with vcpkg and manual installs)
81+ # Fallback to manual search
6482if(NOT JSONCPP_FOUND)
6583 find_path(JSONCPP_INCLUDE_DIR json/json.h
6684 PATHS
@@ -82,17 +100,7 @@ if(NOT JSONCPP_FOUND)
82100 target_include_directories(netmgr PRIVATE ${JSONCPP_INCLUDE_DIR} )
83101 target_link_libraries(netmgr ${JSONCPP_LIBRARY} )
84102 set(JSONCPP_FOUND TRUE )
85- message (STATUS "Found jsoncpp at ${JSONCPP_LIBRARY} " )
86- endif ()
87- endif ()
88-
89- # Final fallback using find_package (for vcpkg and modern CMake)
90- if (NOT JSONCPP_FOUND)
91- find_package (jsoncpp CONFIG QUIET )
92- if (jsoncpp_FOUND)
93- target_link_libraries (netmgr jsoncpp_lib )
94- set (JSONCPP_FOUND TRUE )
95- message (STATUS "Found jsoncpp via find_package" )
103+ message(STATUS "Found jsoncpp manually at ${JSONCPP_LIBRARY} " )
96104 endif()
97105endif()
98106
0 commit comments