From e3eba16c137f69292ae12e74c6fa998fca39fa9b Mon Sep 17 00:00:00 2001
From: Enrico Seiler <enrico.seiler@hotmail.de>
Date: Tue, 1 Nov 2022 13:02:59 +0100
Subject: [PATCH] [INFRA] google dependencies
--- seqan3.orig/test/cmake/seqan3_require_benchmark.cmake
+++ seqan3/test/cmake/seqan3_require_benchmark.cmake
@@ -60,13 +60,18 @@
 
 endmacro ()
 
+# Exposes the google-benchmark target `benchmark` and `benchmark_main`.
+# CMake 3.24: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_TRY_FIND_PACKAGE_MODE
 macro (seqan3_require_benchmark)
     enable_testing ()
 
-    set (gbenchmark_git_tag "v1.6.1")
+    set (benchmark_version "1.7.0")
+    set (gbenchmark_git_tag "v${benchmark_version}")
 
-    if (NOT CMAKE_VERSION VERSION_LESS 3.14)
-        message (STATUS "Fetch Google Benchmark:")
+    find_package (benchmark QUIET)
+
+    if (NOT benchmark_FOUND)
+        message (STATUS "Fetching Google Benchmark ${benchmark_version}")
 
         include (FetchContent)
         FetchContent_Declare (
@@ -75,15 +80,14 @@
             GIT_TAG "${gbenchmark_git_tag}")
         option (BENCHMARK_ENABLE_TESTING "" OFF)
         option (BENCHMARK_ENABLE_WERROR "" OFF) # Does not apply to Debug builds.
+	option (BENCHMARK_ENABLE_INSTALL "" OFF)
         FetchContent_MakeAvailable (gbenchmark_fetch_content)
-
-        # NOTE: google benchmark's CMakeLists.txt already defines Shlwapi
-        add_library (gbenchmark ALIAS benchmark_main)
     else ()
-        message (STATUS "Use Google Benchmark as external project:")
-
-        seqan3_require_benchmark_old ("${gbenchmark_git_tag}")
+        message (STATUS "Found Google Benchmark")
     endif ()
 
-    add_custom_target (gbenchmark_build DEPENDS gbenchmark)
+    # NOTE: google benchmark's CMakeLists.txt already defines Shlwapi
+    if (NOT TARGET gbenchmark_build)
+        add_custom_target (gbenchmark_build DEPENDS benchmark_main benchmark)
+    endif ()
 endmacro ()
--- seqan3.orig/test/cmake/seqan3_require_test.cmake
+++ seqan3/test/cmake/seqan3_require_test.cmake
@@ -64,13 +64,18 @@
     unset (gtest_path)
 endmacro ()
 
+# Exposes the google-test targets `gtest` and `gtest_main`.
+# CMake 3.24: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_TRY_FIND_PACKAGE_MODE
 macro (seqan3_require_test)
     enable_testing ()
 
-    set (gtest_git_tag "release-1.11.0")
+    set (gtest_version "1.12.1")
+    set (gtest_git_tag "release-${gtest_version}")
 
-    if (NOT CMAKE_VERSION VERSION_LESS 3.14)
-        message (STATUS "Fetch Google Test:")
+    find_package (GTest QUIET)
+
+    if (NOT GTest_FOUND)
+        message (STATUS "Fetching Google Test ${gtest_version}")
 
         include (FetchContent)
         FetchContent_Declare (
@@ -78,11 +83,10 @@
             GIT_REPOSITORY "https://github.com/google/googletest.git"
             GIT_TAG "${gtest_git_tag}")
         option (BUILD_GMOCK "" OFF)
+	option (INSTALL_GTEST "" OFF)
         FetchContent_MakeAvailable (gtest_fetch_content)
     else ()
-        message (STATUS "Use Google Test as external project:")
-
-        seqan3_require_test_old ("${gtest_git_tag}")
+        message (STATUS "Found Google Test")
     endif ()
 
     if (NOT TARGET gtest_build)
--- seqan3.orig/test/seqan3-test.cmake
+++ seqan3/test/seqan3-test.cmake
@@ -79,7 +79,7 @@
 # needed for performance test cases in seqan3/test/performance
 if (NOT TARGET seqan3::test::performance)
     add_library (seqan3_test_performance INTERFACE)
-    target_link_libraries (seqan3_test_performance INTERFACE "seqan3::test" "gbenchmark")
+    target_link_libraries (seqan3_test_performance INTERFACE "seqan3::test" "benchmark_main" "benchmark")
 
     if (SEQAN3_BENCHMARK_ALIGN_LOOPS)
         target_compile_options (seqan3_test_performance INTERFACE "-falign-loops=32")
