From d66dc63a14d69fc980fe63a4ce03d0bca3ec7d4b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Wed, 15 Feb 2023 15:11:25 -0700 Subject: [PATCH] feat: Utilize globally installed benchmark if available --- cpp/cmake/benchmark.cmake | 14 +++++++++----- cpp/cmake/module.cmake | 4 ++-- cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt | 2 +- cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cpp/cmake/benchmark.cmake b/cpp/cmake/benchmark.cmake index abcdb7875e..d38a9dacf4 100644 --- a/cpp/cmake/benchmark.cmake +++ b/cpp/cmake/benchmark.cmake @@ -9,12 +9,16 @@ if(BENCHMARKS) benchmark GIT_REPOSITORY https://github.com/google/benchmark GIT_TAG v1.7.1 + FIND_PACKAGE_ARGS ) - FetchContent_GetProperties(benchmark) - if(NOT benchmark_POPULATED) - fetchcontent_populate(benchmark) - set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") - add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL) + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Benchmark tests off") + + FetchContent_MakeAvailable(benchmark) + if(NOT benchmark_FOUND) + # FetchContent_MakeAvailable calls FetchContent_Populate if `find_package` is unsuccessful + # so these variables will be available if we reach this case + set_property(DIRECTORY ${benchmark_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL) + set_property(DIRECTORY ${benchmark_BINARY_DIR} PROPERTY EXCLUDE_FROM_ALL) endif() endif() diff --git a/cpp/cmake/module.cmake b/cpp/cmake/module.cmake index 6980b1b3ee..a7ca4890f3 100644 --- a/cpp/cmake/module.cmake +++ b/cpp/cmake/module.cmake @@ -147,7 +147,7 @@ function(barretenberg_module MODULE_NAME) target_link_libraries( ${MODULE_NAME}_bench_objects PRIVATE - benchmark + benchmark::benchmark ${TBB_IMPORTED_TARGETS} ) @@ -162,7 +162,7 @@ function(barretenberg_module MODULE_NAME) PRIVATE ${MODULE_LINK_NAME} ${ARGN} - benchmark + benchmark::benchmark ${TBB_IMPORTED_TARGETS} ) diff --git a/cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt b/cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt index 42f004e792..f8b6536f8f 100644 --- a/cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt +++ b/cpp/src/aztec/benchmark/honk_bench/CMakeLists.txt @@ -4,7 +4,7 @@ target_link_libraries( honk_bench stdlib_primitives env - benchmark + benchmark::benchmark ) add_custom_target( diff --git a/cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt b/cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt index 5752a3cdb0..a5a0a53d62 100644 --- a/cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt +++ b/cpp/src/aztec/benchmark/plonk_bench/CMakeLists.txt @@ -4,7 +4,7 @@ target_link_libraries( plonk_bench stdlib_primitives env - benchmark + benchmark::benchmark ) add_custom_target(