build: add wrapfile for gtest/gmock
Copy support from sdbusplus for loading googletest and gmock as
a meson subproject, if it is not found in the host distribution.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I4aa1f6cdc97dc5db038950d81e551113463b1ffb
diff --git a/test/meson.build b/test/meson.build
index e9290f7..c218b5f 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -12,8 +12,27 @@
dynamic_linker = []
endif
-gtest = dependency('gtest', main: true, disabler: true, required: true)
-gmock = dependency('gmock', disabler: true, required: true)
+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 get_option('tests').enabled(),
+ 'Googletest is required if tests are enabled'
+ )
+ endif
+endif
+
pldmd = declare_dependency(
sources: [
'../pldmd/instance_id.cpp',