Make test_util GTest-optional to fix benchmark builds with BUILD_TESTING=OFF

When Ceres is configured with BUILD_TESTING=OFF and BUILD_BENCHMARKS=ON,
benchmarks failed to compile and link due to an unconditional dependency on the
test_util library, which requires Googletest (GTest). This commit addresses the issue
by introducing the CERES_HAS_GTEST macro and making the test utility library
GTest-optional.

Fixes: https://github.com/ceres-solver/ceres-solver/issues/1081

Change-Id: I615c37eb6f21d36a4b87b2d24632016944eda3bd
This commit is contained in:
Sameer Agarwal
2026-03-13 08:47:37 -07:00
parent 084b3e3b83
commit ccd1198d72
8 changed files with 35 additions and 18 deletions
+4
View File
@@ -28,6 +28,8 @@
//
// Author: sameeragarwal@google.com (Sameer Agarwal)
#ifdef CERES_HAS_GTEST
#ifndef CERES_INTERNAL_NUMERIC_DIFF_TEST_UTILS_H_
#define CERES_INTERNAL_NUMERIC_DIFF_TEST_UTILS_H_
@@ -153,3 +155,5 @@ class CERES_NO_EXPORT RandomizedCostFunction : public SizedCostFunction<1, 1> {
} // namespace ceres::internal
#endif // CERES_INTERNAL_NUMERIC_DIFF_TEST_UTILS_H_
#endif // CERES_HAS_GTEST