From 7d856b03047e7bf09ccc9e9878e299493541b468 Mon Sep 17 00:00:00 2001 From: Shuo Chen Date: Wed, 1 May 2019 13:00:10 -0700 Subject: [PATCH] If gtest targets are already defined, use them. (#777) This allows a project to include both googletest and benchmark as top-level git submodule. This allows incorporating Benchmark to an existing CMake project that already incorporates googletest. https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project https://github.com/abseil/abseil-cpp/tree/master/CMake#incorporating-abseil-into-a-cmake-project --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 856bc98..74b9934 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,7 +267,9 @@ add_subdirectory(src) if (BENCHMARK_ENABLE_TESTING) enable_testing() - if (BENCHMARK_ENABLE_GTEST_TESTS) + if (BENCHMARK_ENABLE_GTEST_TESTS AND + NOT (TARGET gtest AND TARGET gtest_main AND + TARGET gmock AND TARGET gmock_main)) include(GoogleTest) endif() add_subdirectory(test)