From 045e2901c9a370d5874b71697dee408ac5118171 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Fri, 14 Feb 2025 11:07:06 +0100 Subject: [PATCH] cmake: add a path to fetchcontent google benchmark. add flag MDSPAN_USE_SYSTEM_BENCHMARK defaulted to On (to preserve previous behavior) to use a system-provided library instead --- CMakeLists.txt | 1 + benchmarks/CMakeLists.txt | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ddff1a5a..82e791fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ option(MDSPAN_ENABLE_SYCL "Enable SYCL tests/benchmarks/examples if tests/benchm option(MDSPAN_ENABLE_HIP "Enable HIP tests/benchmarks/examples if tests/benchmarks/examples are enabled." Off) option(MDSPAN_ENABLE_OPENMP "Enable OpenMP benchmarks if benchmarks are enabled." On) option(MDSPAN_USE_SYSTEM_GTEST "Use system-installed GoogleTest library for tests." Off) +option(MDSPAN_USE_SYSTEM_BENCHMARK "Use system-installed Google Benchmark library for benchmarks." On) option(MDSPAN_INSTALL_STDMODE_HEADERS "Whether to install headers to emulate standard library headers and namespaces" Off) # Option to override which C++ standard to use diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index ce0b7453..eafde599 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -9,7 +9,20 @@ function(mdspan_add_benchmark EXENAME) target_compile_definitions(${EXENAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1) endfunction() -find_package(benchmark REQUIRED) +if(MDSPAN_USE_SYSTEM_BENCHMARK) + find_package(benchmark REQUIRED) +else() + set(BENCHMARK_ENABLE_TESTING OFF) + include(FetchContent) + + fetchcontent_declare( + benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG v1.9.1 + ) + + fetchcontent_makeavailable(benchmark) +endif() function(mdspan_add_cuda_benchmark EXENAME) add_executable(${EXENAME} ${EXENAME}.cu)