@@ -13,6 +13,7 @@ option(LOGIT_WITH_OTLP "Enable OTLP/HTTP log export via optional kurlyk dependen
1313option (LOGIT_WITH_PROMETHEUS "Enable Prometheus text payload support" OFF )
1414option (LOGIT_WITH_PROMETHEUS_SERVER "Enable Prometheus HTTP server backend" OFF )
1515option (LOGIT_WITH_MDBX "Enable MDBX structured log storage backend" OFF )
16+ option (LOGIT_WITH_JSON_CONFIG "Enable the optional nlohmann::json configuration frontend" OFF )
1617option (LOGIT_USE_SUBMODULES "Allow bundled optional dependency fallback" OFF )
1718option (LOGIT_WITH_SYSLOG "Enable POSIX syslog backend" ON )
1819option (LOGIT_WITH_WIN_EVENT_LOG "Enable Windows Event Log backend" ON )
@@ -103,6 +104,25 @@ if(LOGIT_WITH_FMT)
103104 target_link_libraries (log -it-cpp INTERFACE fmt::fmt )
104105endif ()
105106
107+ # ---------- JSON configuration frontend ----------
108+ if (LOGIT_WITH_JSON_CONFIG)
109+ if (NOT TARGET nlohmann_json::nlohmann_json)
110+ find_package (nlohmann_json 3.11 QUIET CONFIG )
111+ endif ()
112+ if (NOT TARGET nlohmann_json::nlohmann_json AND LOGIT_USE_SUBMODULES)
113+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /external/kurlyk/external/json/CMakeLists.txt" )
114+ set (JSON_BuildTests OFF CACHE BOOL "Disable bundled nlohmann/json tests" FORCE )
115+ add_subdirectory (external/kurlyk/external/json EXCLUDE_FROM_ALL )
116+ endif ()
117+ endif ()
118+ if (NOT TARGET nlohmann_json::nlohmann_json)
119+ message (FATAL_ERROR
120+ "nlohmann_json not found. Install nlohmann_json or enable LOGIT_USE_SUBMODULES with the kurlyk submodule present." )
121+ endif ()
122+ target_compile_definitions (log -it-cpp INTERFACE LOGIT_WITH_JSON_CONFIG=1 )
123+ target_link_libraries (log -it-cpp INTERFACE nlohmann_json::nlohmann_json )
124+ endif ()
125+
106126# ---------- OTLP/HTTP (kurlyk) ----------
107127if (LOGIT_WITH_OTLP)
108128 if (EMSCRIPTEN)
@@ -329,6 +349,18 @@ if(LOGIT_WITH_FMT AND TARGET fmt::fmt)
329349 endif ()
330350endif ()
331351
352+ if (LOGIT_WITH_JSON_CONFIG AND TARGET nlohmann_json::nlohmann_json)
353+ get_target_property (_nlohmann_json_imported nlohmann_json::nlohmann_json IMPORTED )
354+ if (NOT _nlohmann_json_imported)
355+ set (_logit_install_export_supported OFF )
356+ install (CODE [[
357+ message(FATAL_ERROR
358+ "log-it-cpp: Installing with bundled nlohmann_json is not supported. "
359+ "Install nlohmann_json separately and use find_package(nlohmann_json), or disable LOGIT_WITH_JSON_CONFIG.")
360+ ]] )
361+ endif ()
362+ endif ()
363+
332364if (LOGIT_WITH_PROMETHEUS_SERVER)
333365 set (_logit_install_export_supported OFF )
334366 install (CODE [[
@@ -393,6 +425,13 @@ write_basic_package_version_file(
393425 INSTALL_DESTINATION lib/cmake/log-it-cpp
394426 )
395427
428+ set (LOGIT_PC_REQUIRES "time-shield >= 2.0.0, time-shield < 2.1.0" )
429+ set (LOGIT_PC_CFLAGS "" )
430+ if (LOGIT_WITH_JSON_CONFIG)
431+ string (APPEND LOGIT_PC_REQUIRES ", nlohmann_json >= 3.11" )
432+ string (APPEND LOGIT_PC_CFLAGS " -DLOGIT_WITH_JSON_CONFIG=1" )
433+ endif ()
434+
396435 configure_file (
397436 cmake/log-it-cpp.pc.in
398437 "${CMAKE_CURRENT_BINARY_DIR } /log-it-cpp.pc"
0 commit comments