meson: Add googletest as a subproject

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I1a8088721006a3434606ec15324f84670581302e
diff --git a/tests/meson.build b/tests/meson.build
index b63d437..50eaf0e 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,6 +1,25 @@
-gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
-have_boost_dbus = meson.get_compiler('cpp').has_header('dbus/connection.hpp')
+gtest_dep = dependency('gtest', main: true, disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+if not gtest_dep.found() or not gmock_dep.found()
+    gtest_proj = import('cmake').subproject('googletest', required: false)
+    if gtest_proj.found()
+        gtest_dep = declare_dependency(
+            dependencies: [
+                dependency('threads'),
+                gtest_proj.dependency('gtest'),
+                gtest_proj.dependency('gtest_main'),
+            ]
+        )
+        gmock_dep = gtest_proj.dependency('gmock')
+    else
+        assert(
+            not get_option('tests').enabled(),
+            'Googletest is required if tests are enabled'
+        )
+    endif
+endif
 
+have_boost_dbus = meson.get_compiler('cpp').has_header('dbus/connection.hpp')
 if have_boost_dbus
 test(
     'test_hwmon_temp_sensor',