meson: Make googletest vendorable
This is a quality of life improvement so that users trying to work with
the project don't need to have an external install of the googletest
dependency for the tests to build.
Change-Id: I44b4cbae14c5006eaef0a5b42a1f6b753b07b405
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/meson.build b/test/meson.build
index 15e5e7b..51993de 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 = [
'chip',