create fallback gtest subproject dependency
Allows project to be built and tested locally.
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I0965581e5b2bc006a0edfcd05a6fea996f3f6ec2
diff --git a/test/meson.build b/test/meson.build
index e780a2e..cbe7fbc 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,3 +1,25 @@
+# Get the gtest/gmock dependencies.
+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()
+ cmake = import('cmake')
+ gtest_proj = 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
+
# build simulator
subdir('simulator')
@@ -12,13 +34,9 @@
'operator_register_test',
]
-gtest = dependency('gtest', main : true, required : false, method : 'system')
-
-if gtest.found()
- foreach g : gtests
- test(g, executable(g.underscorify(), g + '.cpp', test_src, \
- dependencies : gtest, \
- include_directories : incdir))
- endforeach
-endif
+foreach g : gtests
+ test(g, executable(g.underscorify(), g + '.cpp', test_src,
+ dependencies : gtest_dep,
+ include_directories : incdir))
+endforeach
diff --git a/test/simulator/meson.build b/test/simulator/meson.build
index 82e2336..87b2d80 100644
--- a/test/simulator/meson.build
+++ b/test/simulator/meson.build
@@ -7,13 +7,9 @@
subdir('testcases')
-gtest = dependency('gtest', main : true, required : false, method : 'system')
-
# Build simulator linked locally
-if gtest.found()
- test('simulator',
- executable('simulator', sim_src, test_src,
- dependencies : gtest,
- link_with : libhei_static,
- include_directories: [ incdir, '.' ]))
-endif
+test('simulator',
+ executable('simulator', sim_src, test_src,
+ dependencies : gtest_dep,
+ link_with : libhei_static,
+ include_directories: [ incdir, '.' ]))