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) set(ZM_PCRE 1)
endif() 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 # Check for mmap and enable in all components
set(ZM_MEM_MAPPED 0) set(ZM_MEM_MAPPED 0)

View File

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

View File

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