From 3790a0343ed675a428dbe058bf0f11bf2ac978cc Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Fri, 5 Feb 2021 17:55:51 +0100
Subject: [PATCH] [test] use gtest meson wrap if gtest is not found

The gtest wrap can be updated with the meson wrap command
---
 .gitignore             |  3 +++
 subprojects/gtest.wrap | 10 ++++++++++
 tests/meson.build      |  8 +++++++-
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 subprojects/gtest.wrap

diff --git a/.gitignore b/.gitignore
index 85ff3c44..db1bd34d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,6 @@
 /build-*/
 
 /.cache/
+
+subprojects/packagecache/
+subprojects/googletest*
diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap
new file mode 100644
index 00000000..ca5d699e
--- /dev/null
+++ b/subprojects/gtest.wrap
@@ -0,0 +1,10 @@
+[wrap-file]
+directory = googletest-release-1.10.0
+
+source_url = https://github.com/google/googletest/archive/release-1.10.0.zip
+source_filename = gtest-1.10.0.zip
+source_hash = 94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
+
+patch_url = https://wrapdb.mesonbuild.com/v1/projects/gtest/1.10.0/1/get_zip
+patch_filename = gtest-1.10.0-1-wrap.zip
+patch_hash = 04ff14e8880e4e465f6260221e9dfd56fea6bc7cce4c4aff0dc528e4a2c8f514
diff --git a/tests/meson.build b/tests/meson.build
index a08c6b54..fea6adda 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -170,7 +170,13 @@ parallel_ok = (not io_uring_enabled)
 
 # Meson integration for GTest and GMock
 # See https://mesonbuild.com/Dependencies.html#gtest-and-gmock
-gtest_dep = dependency('gtest', main: true)
+gtest_dep = dependency('gtest', main: true, required: false)
+# If gtest is not available on the system use the meson wrap provided
+# by WrapDB and build it ourself
+if not gtest_dep.found()
+	gtest_sp = subproject('gtest')
+	gtest_dep = gtest_sp.get_variable('gtest_main_dep')
+endif
 
 foreach source, test_dict : tests
   # TODO: Use meson fs (filesystem) module once meson >= 0.53 is in
-- 
GitLab