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/.gitignore b/.gitignore
index 547b6ed..59f76fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.sw*
/build
+/subprojects/googletest
diff --git a/meson.build b/meson.build
index 02cd994..202f6d2 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
# OpenBMC openpower-libhei project, see README.md for details.
project('openpower-libhei', 'cpp',
- version: '0.1', meson_version: '>=0.50.0',
+ version: '0.1', meson_version: '>=0.51.0',
default_options: [
'warning_level=3',
'werror=true',
diff --git a/subprojects/googletest.wrap b/subprojects/googletest.wrap
new file mode 100644
index 0000000..56da9ef
--- /dev/null
+++ b/subprojects/googletest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD
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, '.' ]))