From c079019a124365fcde6ddcc5d770a94033220dda Mon Sep 17 00:00:00 2001 From: yangjie01 Date: Mon, 20 Jul 2026 11:59:01 +0800 Subject: [PATCH] build: move GTest and Google Benchmark setup into IcebergThirdpartyToolchain Move the GoogleTest and Google Benchmark FetchContent setup from the test and benchmark subdirectories into cmake_modules/IcebergThirdpartyToolchain.cmake, so all third-party dependency resolution stays in one place. Add resolve_gtest_dependency() and resolve_benchmark_dependency(), gated by ICEBERG_BUILD_TESTS and ICEBERG_BUILD_BENCHMARKS. Version pins are unchanged and only CMake is affected. Fixes #829. --- .../IcebergThirdpartyToolchain.cmake | 65 +++++++++++++++++++ src/iceberg/benchmark/CMakeLists.txt | 19 +----- src/iceberg/test/CMakeLists.txt | 13 +--- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/cmake_modules/IcebergThirdpartyToolchain.cmake b/cmake_modules/IcebergThirdpartyToolchain.cmake index 86e840097..00f34d11c 100644 --- a/cmake_modules/IcebergThirdpartyToolchain.cmake +++ b/cmake_modules/IcebergThirdpartyToolchain.cmake @@ -801,6 +801,57 @@ function(resolve_zstd_dependency) endif() endfunction() +# ---------------------------------------------------------------------- +# GoogleTest (tests only) +# +# GTest is only consumed by the unit tests; it is neither installed nor exported +# as a system dependency, so it does not touch ICEBERG_SYSTEM_DEPENDENCIES. + +function(resolve_gtest_dependency) + prepare_fetchcontent() + + set(INSTALL_GTEST + OFF + CACHE BOOL "" FORCE) + + fetchcontent_declare(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2 + FIND_PACKAGE_ARGS + NAMES + GTest) + fetchcontent_makeavailable(googletest) +endfunction() + +# ---------------------------------------------------------------------- +# Google Benchmark (benchmarks only) +# +# Like GTest, benchmark is only consumed by the benchmark targets and is neither +# installed nor exported as a system dependency. + +function(resolve_benchmark_dependency) + prepare_fetchcontent() + + set(BENCHMARK_ENABLE_GTEST_TESTS + OFF + CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_INSTALL + OFF + CACHE BOOL "" FORCE) + set(BENCHMARK_ENABLE_TESTING + OFF + CACHE BOOL "" FORCE) + + fetchcontent_declare(google_benchmark + GIT_REPOSITORY https://github.com/google/benchmark.git + GIT_TAG a4cf155615c63e019ae549e31703bf367df5b471 # v1.8.4 + FIND_PACKAGE_ARGS + NAMES + benchmark + CONFIG) + fetchcontent_makeavailable(google_benchmark) +endfunction() + resolve_zlib_dependency() resolve_nanoarrow_dependency() resolve_croaring_dependency() @@ -864,3 +915,17 @@ endfunction() if(ICEBERG_BUILD_HIVE) resolve_thrift_dependency() endif() + +# ---------------------------------------------------------------------- +# Test and benchmark dependencies +# +# These are build-only tools, pulled in after the library dependencies and only +# when the corresponding build option is enabled. + +if(ICEBERG_BUILD_TESTS) + resolve_gtest_dependency() +endif() + +if(ICEBERG_BUILD_BENCHMARKS) + resolve_benchmark_dependency() +endif() diff --git a/src/iceberg/benchmark/CMakeLists.txt b/src/iceberg/benchmark/CMakeLists.txt index 0227c3871..5d3c19d0f 100644 --- a/src/iceberg/benchmark/CMakeLists.txt +++ b/src/iceberg/benchmark/CMakeLists.txt @@ -15,24 +15,7 @@ # specific language governing permissions and limitations # under the License. -set(BENCHMARK_ENABLE_GTEST_TESTS - OFF - CACHE BOOL "" FORCE) -set(BENCHMARK_ENABLE_INSTALL - OFF - CACHE BOOL "" FORCE) -set(BENCHMARK_ENABLE_TESTING - OFF - CACHE BOOL "" FORCE) - -fetchcontent_declare(google_benchmark - GIT_REPOSITORY https://github.com/google/benchmark.git - GIT_TAG a4cf155615c63e019ae549e31703bf367df5b471 # v1.8.4 - FIND_PACKAGE_ARGS - NAMES - benchmark - CONFIG) -fetchcontent_makeavailable(google_benchmark) +# Google Benchmark is resolved in cmake_modules/IcebergThirdpartyToolchain.cmake. add_executable(benchmark_smoke benchmark_smoke.cc) target_link_libraries(benchmark_smoke diff --git a/src/iceberg/test/CMakeLists.txt b/src/iceberg/test/CMakeLists.txt index 98129a6d2..66148211d 100644 --- a/src/iceberg/test/CMakeLists.txt +++ b/src/iceberg/test/CMakeLists.txt @@ -15,18 +15,7 @@ # specific language governing permissions and limitations # under the License. -set(INSTALL_GTEST - OFF - CACHE BOOL "" FORCE) - -fetchcontent_declare(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2 - FIND_PACKAGE_ARGS - NAMES - GTest) - -fetchcontent_makeavailable(googletest) +# GoogleTest is resolved in cmake_modules/IcebergThirdpartyToolchain.cmake. set(ICEBERG_TEST_RESOURCES "${CMAKE_SOURCE_DIR}/src/iceberg/test/resources")