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
@@ -29,6 +29,8 @@
// Author: sameeragarwal@google.com (Sameer Agarwal)
// tbennun@gmail.com (Tal Ben-Nun)
#ifdef CERES_HAS_GTEST
#include "ceres/numeric_diff_test_utils.h"
#include <algorithm>
@@ -255,3 +257,5 @@ void RandomizedFunctor::ExpectCostFunctionEvaluationIsNearlyCorrect(
}
} // namespace ceres::internal
#endif // CERES_HAS_GTEST