Make nlohmann_json optional

This commit is contained in:
Isaac Connor
2025-07-19 19:00:17 -04:00
parent d5e81d3c4a
commit 4c5bae17d7
3 changed files with 12 additions and 1 deletions

View File

@@ -591,7 +591,13 @@ if(HAVE_LIBPCRE AND HAVE_PCRE_H)
set(ZM_PCRE 1)
endif()
find_package(nlohmann_json)
find_package(nlohmann_json CONFIG)
if(nlohmann_json_FOUND)
set(ZM_HAS_NLOHMANN_JSON 1)
else()
set(ZM_HAS_NLOHMANN_JSON 0)
message(AUTHOR_WARNING "nlohmann_json headers weren't found - AI results will not be available")
endif()
# Check for mmap and enable in all components
set(ZM_MEM_MAPPED 0)

View File

@@ -29,7 +29,9 @@
#include <mutex>
#include <vector>
#if HAS_NLOHMANN_JSON
#include <nlohmann/json.hpp>
#endif
extern "C" {
#include <libavformat/avformat.h>
@@ -61,7 +63,9 @@ class ZMPacket {
bool decoded;
std::vector<ZoneStats> zone_stats;
std::string alarm_cause;
#if HAS_NLOHMANN_JSON
nlohmann::json detections;
#endif
public:
AVPacket *av_packet() { return packet.get(); }

View File

@@ -47,6 +47,7 @@
/* Few ZM options that are needed by the source code */
#cmakedefine ZM_MEM_MAPPED 1
#cmakedefine ZM_HAS_V4L2 1
#cmakedefine ZM_HAS_NLOHMANN_JSON 1
/* Its safe to assume that signal return type is void. This is a fix for zm_signal.h */
#define RETSIGTYPE void