meson: Explicitly check for CLI11 dependency

Change-Id: Ifaf6e5aba783285c16e8aae278e34dde6aa9d52c
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meson.build b/meson.build
index 19dfc62..47cee55 100644
--- a/meson.build
+++ b/meson.build
@@ -73,12 +73,28 @@
     include_directories: hwmon_headers,
     link_with: hwmon_lib)
 
+# CLI11 might not have a pkg-config. It is header only so just make
+# sure we can access the needed symbols from the header.
+cli11_dep = dependency('cli11', required: false)
+has_cli11 = meson.get_compiler('cpp').has_header_symbol(
+    'CLI/CLI.hpp',
+    'CLI::App',
+    dependencies: cli11_dep,
+    required: false)
+if not has_cli11
+    cli11_proj = subproject('cli11', required: false)
+    assert(cli11_proj.found(), 'CLI11 is required')
+    cli11_dep = cli11_proj.get_variable('CLI11_dep')
+endif
+
 executable(
     'phosphor-hwmon-readd',
     'readd.cpp',
-    dependencies: hwmon_dep,
-    install: true,
-)
+    dependencies: [
+        cli11_dep,
+        hwmon_dep,
+    ],
+    install: true)
 
 subdir('msl')
 subdir('test')