Blob Blame History Raw
From e8619813072f8eb7cf2d0e30b331c791405f5fef Mon Sep 17 00:00:00 2001
From: Vitaly Zaitsev <vitaly@easycoding.org>
Date: Wed, 8 Sep 2021 19:41:07 +0200
Subject: [PATCH] Added support of packaged GTest for running unit tests.

Signed-off-by: Vitaly Zaitsev <vitaly@easycoding.org>
---
 CMakeLists.txt | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 49f2ae2a0..0570d050d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -307,7 +307,15 @@ if (BENCHMARK_ENABLE_TESTING)
   if (BENCHMARK_ENABLE_GTEST_TESTS AND
       NOT (TARGET gtest AND TARGET gtest_main AND
            TARGET gmock AND TARGET gmock_main))
-    include(GoogleTest)
+    find_package(GTest QUIET)
+    if (GTEST_FOUND)
+      add_library(gtest ALIAS GTest::gtest)
+      add_library(gtest_main ALIAS GTest::gtest_main)
+      add_library(gmock ALIAS GTest::gmock)
+      add_library(gmock_main ALIAS GTest::gmock_main)
+    else()
+      include(GoogleTest)
+    endif()
   endif()
   add_subdirectory(test)
 endif()