meson: add nlohmann-json wrapper and deps

A number of locations within the repository do not appropriately
specify the dependency on nlohmann-json.  Fix up the wrap file,
add appropriate dependency detection in the root meson, and add the
library as a dependency when needed.  This gets closer to allowing
full subproject-based builds.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: If70888c6de5651ca355f84616e41408ddde9fc08
diff --git a/meson.build b/meson.build
index a7064a6..0aa7e91 100644
--- a/meson.build
+++ b/meson.build
@@ -92,6 +92,15 @@
 std_cpp_fs = cpp.find_library('stdc++fs', required: true)
 sdbusplus_dep = dependency('sdbusplus')
 
+if cpp.has_header_symbol(
+        'nlohmann/json.hpp',
+        'nlohmann::json::string_t',
+        required:false)
+    nlohmann_json_dep = declare_dependency()
+else
+    nlohmann_json_dep = dependency('nlohmann-json')
+endif
+
 # Subfolders
 subdir('libipmid')
 subdir('libipmid-host')
@@ -189,7 +198,7 @@
   'entity_map_json',
   'entity_map_json.cpp',
   include_directories: root_inc,
-  dependencies: [ipmid_dep],
+  dependencies: [ipmid_dep, nlohmann_json_dep],
   implicit_include_directories: false)
 
 entity_map_json_dep = declare_dependency(link_with: entity_map_json_lib)
@@ -221,7 +230,7 @@
 ipmi20_lib = library(
   'ipmi20',
   libipmi20_src,
-  dependencies: [ipmid_pre, entity_map_json_dep],
+  dependencies: [ipmid_pre, entity_map_json_dep, nlohmann_json_dep],
   include_directories: root_inc,
   install: true,
   install_dir: get_option('libdir') / 'ipmid-providers',
diff --git a/subprojects/nlohmann-json.wrap b/subprojects/nlohmann-json.wrap
new file mode 100644
index 0000000..a2884b1
--- /dev/null
+++ b/subprojects/nlohmann-json.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+url = https://github.com/nlohmann/json
+revision = HEAD
+
+[provide]
+nlohmann-json = nlohmann_json_dep
diff --git a/subprojects/nlohmann_json.wrap b/subprojects/nlohmann_json.wrap
deleted file mode 100644
index 0ba9c03..0000000
--- a/subprojects/nlohmann_json.wrap
+++ /dev/null
@@ -1,3 +0,0 @@
-[wrap-git]
-url = https://github.com/nlohmann/json
-revision = HEAD
diff --git a/test/meson.build b/test/meson.build
index 3306a91..3fb652b 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -27,7 +27,7 @@
     include_directories: root_inc,
     build_by_default: false,
     implicit_include_directories: false,
-    dependencies: [entity_map_json_dep, gtest, gmock]
+    dependencies: [entity_map_json_dep, gtest, gmock, nlohmann_json_dep]
   ))
 
 # Build/add oemrouter_unittest to test suite
diff --git a/user_channel/meson.build b/user_channel/meson.build
index 36ea83b..eec8b82 100644
--- a/user_channel/meson.build
+++ b/user_channel/meson.build
@@ -5,6 +5,7 @@
   dependencies: [
     crypto,
     ipmid_dep,
+    nlohmann_json_dep,
     phosphor_dbus_interfaces_dep,
     phosphor_logging_dep,
     std_cpp_fs,
@@ -38,9 +39,10 @@
       channellayer_dep,
       crypto,
       ipmid_dep,
+      nlohmann_json_dep,
+      pam,
       phosphor_dbus_interfaces_dep,
       phosphor_logging_dep,
-      pam,
       std_cpp_fs,
       systemd,
     ])