@@ -77,6 +77,54 @@ endif()
7777
7878set (VIX_NET_TARGET vix::net)
7979
80+ # --------------------------------------------------------------------
81+ # JSON dependency (required by src/FileStore.cpp -> <nlohmann/json.hpp>)
82+ # Policy:
83+ # - Umbrella: must provide nlohmann_json::nlohmann_json already (or via system).
84+ # - Standalone: try CONFIG package, optionally FetchContent if allowed.
85+ # --------------------------------------------------------------------
86+ option (VIX_CACHE_FETCH_NLOHMANN "Fetch nlohmann/json if missing (standalone only)" ON )
87+
88+ if (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD)
89+ set (VIX_CACHE_FETCH_NLOHMANN OFF CACHE BOOL "Fetch nlohmann/json if missing (standalone only)" FORCE )
90+ endif ()
91+
92+ set (VIX_NLOHMANN_TARGET "" )
93+
94+ # First try CONFIG package
95+ find_package (nlohmann_json CONFIG QUIET )
96+ if (TARGET nlohmann_json::nlohmann_json)
97+ set (VIX_NLOHMANN_TARGET nlohmann_json::nlohmann_json)
98+ endif ()
99+
100+ # Standalone fallback: FetchContent
101+ if (NOT VIX_NLOHMANN_TARGET)
102+ if (NOT (DEFINED VIX_UMBRELLA_BUILD AND VIX_UMBRELLA_BUILD) AND VIX_CACHE_FETCH_NLOHMANN)
103+ include (FetchContent )
104+ message (STATUS "[cache] Fetching nlohmann/json via FetchContent" )
105+ FetchContent_Declare (nlohmann_json
106+ GIT_REPOSITORY https://github.com/nlohmann/json.git
107+ GIT_TAG v3.11.3
108+ )
109+ FetchContent_MakeAvailable (nlohmann_json)
110+
111+ if (TARGET nlohmann_json::nlohmann_json)
112+ set (VIX_NLOHMANN_TARGET nlohmann_json::nlohmann_json)
113+ endif ()
114+ endif ()
115+ endif ()
116+
117+ if (NOT VIX_NLOHMANN_TARGET)
118+ message (FATAL_ERROR
119+ "[cache] Missing dependency: nlohmann_json::nlohmann_json.\n "
120+ "Reason: src/FileStore.cpp includes <nlohmann/json.hpp>.\n "
121+ "Fix:\n "
122+ " - Umbrella: ensure nlohmann_json is available before adding cache (system package or umbrella fallback).\n "
123+ " - Standalone: install nlohmann_json or set VIX_CACHE_FETCH_NLOHMANN=ON.\n "
124+ )
125+ endif ()
126+
127+
80128# STATIC
81129if (CACHE_SOURCES)
82130 message (STATUS "[cache] Building STATIC library with detected sources." )
@@ -92,11 +140,13 @@ if (CACHE_SOURCES)
92140 $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
93141 )
94142
95- target_link_libraries (vix_cache
143+ target_link_libraries (vix_cache
96144 PUBLIC
97145 ${VIX_NET_TARGET}
146+ ${VIX_NLOHMANN_TARGET}
98147 )
99148
149+
100150 if (TARGET vix_warnings)
101151 target_link_libraries (vix_cache PUBLIC vix_warnings )
102152 endif ()
@@ -140,8 +190,9 @@ else()
140190 $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
141191 )
142192
143- target_link_libraries (vix_cache INTERFACE
193+ target_link_libraries (vix_cache INTERFACE
144194 ${VIX_NET_TARGET}
195+ ${VIX_NLOHMANN_TARGET}
145196 )
146197
147198 if (VIX_ENABLE_SANITIZERS AND TARGET vix_sanitizers)
@@ -177,6 +228,7 @@ if (CACHE_SOURCES)
177228else ()
178229 message (STATUS "Mode: HEADER-ONLY / no sources" )
179230endif ()
231+ message (STATUS "JSON target: ${VIX_NLOHMANN_TARGET} " )
180232message (STATUS "Net target: ${VIX_NET_TARGET} " )
181233message (STATUS "Include dir: ${CMAKE_CURRENT_SOURCE_DIR} /include (for <vix/cache/...>)" )
182234message (STATUS "Build type: ${CMAKE_BUILD_TYPE} " )
0 commit comments