meson: Use subprojects where possible

Change-Id: Id49b7db21f7f44d5183549430988fd33b9166edb
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/.clang-ignore b/.clang-ignore
new file mode 100644
index 0000000..36f17f2
--- /dev/null
+++ b/.clang-ignore
@@ -0,0 +1 @@
+./subprojects
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..327ea97
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/build*/
+/subprojects/*/
diff --git a/meson.build b/meson.build
index 96ffd96..e25a727 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@
   'phosphor-watchdog',
   'cpp',
   version: '0.1',
-  meson_version: '>=0.49.0',
+  meson_version: '>=0.55.0',
   default_options: [
     'warning_level=3',
     'cpp_std=c++17',
@@ -13,8 +13,8 @@
 watchdog_deps = [
   dependency('phosphor-dbus-interfaces'),
   dependency('phosphor-logging'),
-  dependency('sdbusplus'),
-  dependency('sdeventplus'),
+  dependency('sdbusplus', fallback: ['sdbusplus', 'sdbusplus_dep']),
+  dependency('sdeventplus', fallback: ['sdeventplus', 'sdeventplus_dep']),
 ]
 
 watchdog_lib = static_library(
diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap
new file mode 100644
index 0000000..56da9ef
--- /dev/null
+++ b/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD
diff --git a/subprojects/sdbusplus.wrap b/subprojects/sdbusplus.wrap
new file mode 100644
index 0000000..7f736e7
--- /dev/null
+++ b/subprojects/sdbusplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdbusplus
+revision = HEAD
diff --git a/subprojects/sdeventplus.wrap b/subprojects/sdeventplus.wrap
new file mode 100644
index 0000000..7503664
--- /dev/null
+++ b/subprojects/sdeventplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdeventplus
+revision = HEAD
diff --git a/test/meson.build b/test/meson.build
index 0e4faf0..f5b9fe3 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,5 +1,25 @@
-gtest = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
-gmock = dependency('gmock', disabler: true, required: get_option('tests'))
+gtest = dependency('gtest', main: true, disabler: true, required: false)
+gmock = dependency('gmock', disabler: true, required: false)
+if not gtest.found() or not gmock.found()
+  gtest_opts = import('cmake').subproject_options()
+  gtest_opts.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
+  gtest_proj = import('cmake').subproject(
+    'googletest',
+    options: gtest_opts,
+    required: false)
+  if gtest_proj.found()
+    gtest = declare_dependency(
+      dependencies: [
+        dependency('threads'),
+        gtest_proj.dependency('gtest'),
+        gtest_proj.dependency('gtest_main'),
+      ])
+    gmock = gtest_proj.dependency('gmock')
+  else
+    assert(not build_tests.enabled(), 'Googletest is required')
+  endif
+endif
+
 
 tests = [
   'watchdog',