test: Allow optional usage of vendored googletest

Change-Id: I7011edb826b11762f1eb49e8bbc3a19c8006f8c5
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/meson.build b/test/meson.build
index 3b8f167..e520f8b 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,5 +1,19 @@
-gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
-gmock = dependency('gmock', disabler: true, required: build_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_proj = import('cmake').subproject('googletest', 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 = [
   'clock',