build: Allow for vendored googletest
This makes it easier to run the test suite outside of the CI
environment but still attempts to use the system version of googletest
first.
Change-Id: I32193f08243db2177b8200b0ff7e3e47ef01691f
Signed-off-by: William A. Kennington III <wak@google.com>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/test/meson.build b/test/meson.build
index 1784e4c..374dada 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,5 +1,23 @@
-gtest_dep = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
-gmock_dep = dependency('gmock', disabler: true, required: get_option('tests'))
+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
tests = [
'bus/list_names',