Skip to content

Commit f6496d6

Browse files
[SymForce] Remove local Catch2 (instead fetch it)
It's my understanding we only had a local copy because in the past it wasn't possible to fetch from github. This PR: - Deletes the local copy of Catch2 and instead fetches it in our build files - Replaces the old mono-header with the split up headers. This is not strictly necessary, as the new versions of Catch2 still have a mono-header, but the authors of Catch2 recommend this change to speed up compile times. - Does not change the version of Catch2 that we use (v3.0.0-preview3) We don't update to the latest version (v3.0.1) because it does not compile on all the gcc compiler versions we'd like to support (for example gcc-5). As a note, one benefit of v3.0.1 over v3.0.0-preview3 is that v3.0.1 will compile on ubuntu-22.04 (see #132) **Overview of changes** Needed to change the `CMakeLists.txt` to use the `Catch2::Catch2WithMain` target (which we use instead of `Catch2::Catch2` because we don't define a custom main method for any of our tests). Deleted the old `third_party/catch2` because it's being replaced. Most of the work was simply changing the includes to use the appropriate headers instead of `#include "catch.hpp"`. Could have used `#include <catch2/catch_all.hpp>`, but the catch2 docs recomends to not do this, and instead include the specific headers to speed up compilation time (at the cost of convenience) Topic: update_catch2 GitOrigin-RevId: 5e16e149657a7807b8baf7209969a88bf4361dc0
1 parent cdf8560 commit f6496d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+101
-20278
lines changed

CMakeLists.txt

+22-11
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,28 @@ if(SYMFORCE_EIGEN_TARGET STREQUAL "Eigen3::Eigen")
162162
endif()
163163
endif()
164164

165-
# TODO(aaron): This goes away when we upgrade to Catch2 v3
166-
add_library(
167-
symforce_catch2
168-
${SYMFORCE_LIBRARY_TYPE}
169-
EXCLUDE_FROM_ALL # Only build this if something needs it
170-
third_party/catch2/src/catch_amalgamated.cpp test/catch_main.cc
171-
)
172-
target_include_directories(
173-
symforce_catch2
174-
PUBLIC third_party/catch2/include
175-
)
165+
# ------------------------------------------------------------------------------
166+
# catch2
167+
168+
if(SYMFORCE_BUILD_BENCHMARKS OR SYMFORCE_BUILD_TESTS)
169+
find_package(Catch2 3.0.0 QUIET)
170+
if(NOT Catch2_FOUND)
171+
message(STATUS "Catch2 not found, adding with FetchContent")
172+
function(add_catch)
173+
FetchContent_Declare(
174+
Catch2
175+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
176+
GIT_TAG b9853b4b356b83bb580c746c3a1f11101f9af54f # v3.0.0-preview3
177+
)
178+
179+
FetchContent_MakeAvailable(Catch2)
180+
endfunction()
181+
182+
add_catch()
183+
else()
184+
message(STATUS "Catch2 found at ${Catch2_DIR}")
185+
endif()
186+
endif()
176187

177188
# ==============================================================================
178189
# SymForce Targets

LICENSE

-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ and is licensed as described in symforce/opt/cholesky/LICENSE
211211
SymForce bundles several third party libraries, with documentation of
212212
licensing and modifications as follows:
213213

214-
### Catch2: C++ Unit testing framework
215-
216-
- Included unmodified in third_party/catch2
217-
- Licensed under the BSL-1.0 License
218-
219214
### SymEngine: C++ symbolic manipulation library
220215

221216
- Included with modifications in third_party/symengine

symforce/benchmarks/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function(add_matrix_multiplication_benchmark matrix_name)
114114

115115
target_link_libraries(
116116
matrix_multiplication_benchmark_${matrix_name}
117-
symforce_catch2
117+
Catch2::Catch2WithMain
118118
symforce_gen
119119
symforce_opt
120120
)
@@ -142,7 +142,7 @@ find_package(Sophus REQUIRED)
142142
target_link_libraries(
143143
inverse_compose_jacobian_benchmark
144144
gtsam
145-
symforce_catch2
145+
Catch2::Catch2WithMain
146146
symforce_gen
147147
symforce_opt
148148
)
@@ -162,7 +162,7 @@ add_executable(
162162
target_link_libraries(
163163
robot_3d_localization_benchmark
164164
gtsam
165-
symforce_catch2
165+
Catch2::Catch2WithMain
166166
symforce_gen
167167
symforce_opt
168168
symforce_examples

symforce/benchmarks/inverse_compose_jacobian/inverse_compose_jacobian_benchmark.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
#include <Eigen/Dense>
1818
#include <Eigen/Sparse>
19-
#include <catch.hpp>
19+
#include <catch2/catch_template_test_macros.hpp>
20+
#include <catch2/catch_test_macros.hpp>
2021
#include <gtsam/geometry/Pose3.h>
2122
#include <sophus/se3.hpp>
2223
#include <spdlog/spdlog.h>

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_Tina_DisCog.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_Tina_DisCog.h"

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_b1_ss.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_b1_ss.h"

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_bibd_9_3.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_bibd_9_3.h"

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_lp_sc105.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_dense_dynamic_lp_sc105.h"

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_n3c4_b2.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_dense_dynamic_n3c4_b2.h"

symforce/benchmarks/matrix_multiplication/gen/matrix_multiplication_benchmark_rotor1.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include <Eigen/Dense>
2121
#include <Eigen/Sparse>
22+
#include <catch2/catch_template_test_macros.hpp>
23+
#include <catch2/catch_test_macros.hpp>
2224
#include <spdlog/spdlog.h>
2325

2426
#include <symforce/opt/tic_toc.h>
2527
#include <symforce/opt/util.h>
2628

27-
#include "catch.hpp"
28-
2929
using namespace sym;
3030

3131
#include "./compute_a_dense_dynamic_rotor1.h"

symforce/benchmarks/matrix_multiplication/matrix_multiplication_benchmark.cc.jinja

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include <symforce/opt/tic_toc.h>
2424
#include <symforce/opt/util.h>
2525

26-
#include "catch.hpp"
26+
#include <catch2/catch_template_test_macros.hpp>
27+
#include <catch2/catch_test_macros.hpp>
2728

2829
using namespace sym;
2930

symforce/benchmarks/robot_3d_localization/robot_3d_localization_benchmark.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <Eigen/Dense>
2020
#include <Eigen/Sparse>
21+
#include <catch2/catch_template_test_macros.hpp>
22+
#include <catch2/catch_test_macros.hpp>
2123
#include <spdlog/spdlog.h>
2224

2325
#include <sym/rot3.h>
@@ -35,7 +37,6 @@
3537

3638
#include "./robot_3d_localization_ceres.h"
3739
#include "./robot_3d_localization_gtsam.h"
38-
#include "catch.hpp"
3940

4041
using namespace robot_3d_localization;
4142

symforce/codegen/backends/cpp/templates/tests/cam_function_codegen_cpp_test.cc.jinja

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
#include <fmt/ostream.h>
1818
#include <spdlog/spdlog.h>
1919

20+
#include <catch2/catch_template_test_macros.hpp>
21+
#include <catch2/catch_test_macros.hpp>
22+
2023
// TODO(nathan): We just test linear camera for now, but could/should test other types in the future
2124
#include <sym/linear_camera_cal.h>
2225
#include "symforce_function_codegen_test_data/symengine/symforce_gen_codegen_test_data/cam_function_codegen_test/pixel_to_ray_and_back.h"
2326

24-
#include "catch.hpp"
25-
2627
TEMPLATE_TEST_CASE("Test generated function", "[cam_function]", sym::LinearCameraCal<double>,
2728
sym::LinearCameraCal<float>) {
2829
using T = TestType;

symforce/codegen/backends/cpp/templates/tests/cam_package_cpp_test.cc.jinja

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
#include <sym/ops/lie_group_ops.h>
3131
#include <sym/util/epsilon.h>
3232

33-
#include "catch.hpp"
33+
#include <catch2/catch_template_test_macros.hpp>
34+
#include <catch2/catch_test_macros.hpp>
35+
#include <catch2/generators/catch_generators.hpp>
36+
#include <catch2/generators/catch_generators_range.hpp>
3437

3538
template <typename T>
3639
T CalFromData(std::initializer_list<typename T::Scalar> data) {

symforce/codegen/backends/cpp/templates/tests/geo_package_cpp_test.cc.jinja

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#include <sym/util/epsilon.h>
3232
#include <symforce/opt/util.h>
3333

34-
#include "catch.hpp"
34+
#include <catch2/catch_template_test_macros.hpp>
35+
#include <catch2/catch_test_macros.hpp>
3536

3637
TEST_CASE("Test Rot3", "[geo_package]") {
3738
// Make a random rotation

test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ add_library(
1616
${SYMFORCE_TEST_SOURCES}
1717
${SYMFORCE_TEST_HEADERS}
1818
)
19-
target_link_libraries(symforce_test symforce_catch2 symforce_gen symforce_opt)
19+
target_link_libraries(symforce_test Catch2::Catch2WithMain symforce_gen symforce_opt)
2020
target_include_directories(symforce_test
2121
INTERFACE symforce_function_codegen_test_data/symengine/cam_function_codegen_test_data/cpp
2222
INTERFACE symforce_function_codegen_test_data/symengine/codegen_multi_function_test_data/cpp

test/cam_function_codegen_cpp_test.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
#include <Eigen/Dense>
18+
#include <catch2/catch_template_test_macros.hpp>
19+
#include <catch2/catch_test_macros.hpp>
1820
#include <fmt/ostream.h>
1921
#include <spdlog/spdlog.h>
2022

2123
// TODO(nathan): We just test linear camera for now, but could/should test other types in the future
2224
#include <sym/linear_camera_cal.h>
2325

24-
#include "catch.hpp"
2526
#include "symforce_function_codegen_test_data/symengine/symforce_gen_codegen_test_data/cam_function_codegen_test/pixel_to_ray_and_back.h"
2627

2728
TEMPLATE_TEST_CASE("Test generated function", "[cam_function]", sym::LinearCameraCal<double>,

test/cam_package_cpp_test.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include <random>
1818

1919
#include <Eigen/Dense>
20+
#include <catch2/catch_template_test_macros.hpp>
21+
#include <catch2/catch_test_macros.hpp>
22+
#include <catch2/generators/catch_generators.hpp>
23+
#include <catch2/generators/catch_generators_range.hpp>
2024
#include <fmt/ostream.h>
2125
#include <spdlog/spdlog.h>
2226

@@ -34,8 +38,6 @@
3438
#include <sym/spherical_camera_cal.h>
3539
#include <sym/util/epsilon.h>
3640

37-
#include "catch.hpp"
38-
3941
template <typename T>
4042
T CalFromData(std::initializer_list<typename T::Scalar> data) {
4143
Eigen::Matrix<typename T::Scalar, sym::StorageOps<T>::StorageDim(), 1> data_vec;

test/catch_main.cc

-7
This file was deleted.

test/codegen_cpp_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* ---------------------------------------------------------------------------- */
55

66
#include <Eigen/Dense>
7+
#include <catch2/catch_approx.hpp>
8+
#include <catch2/catch_test_macros.hpp>
79

810
#include <lcmtypes/codegen_cpp_test/constants_t.hpp>
911
#include <lcmtypes/codegen_cpp_test/states_t.hpp>
@@ -12,8 +14,6 @@
1214
#include <sym/rot3.h>
1315
#include <symforce/codegen_cpp_test/codegen_cpp_test.h>
1416

15-
#include "catch.hpp"
16-
1717
TEST_CASE("Generated C++ compiles", "[codegen_cpp_test]") {
1818
double x = 2.0;
1919
double y = -5.0;

test/codegen_explicit_template_instantiation_test.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
* ---------------------------------------------------------------------------- */
55

66
#include <Eigen/Dense>
7+
#include <catch2/catch_test_macros.hpp>
78

89
#include <lcmtypes/codegen_explicit_template_instantiation_test/constants_t.hpp>
910
#include <lcmtypes/codegen_explicit_template_instantiation_test/states_t.hpp>
1011
#include <lcmtypes/codegen_explicit_template_instantiation_test/values_vec_t.hpp>
1112

1213
#include <symforce/codegen_explicit_template_instantiation_test/codegen_explicit_template_instantiation_test.h>
1314

14-
#include "catch.hpp"
15-
1615
template <typename Scalar>
1716
void ExplicitTemplateInstantiationTestHelper() {
1817
// Helper function for calling "ExplicitTemplateInstantiationTest" with different scalar types

test/codegen_matrix_order_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* ---------------------------------------------------------------------------- */
55

66
#include <Eigen/Dense>
7+
#include <catch2/catch_test_macros.hpp>
78

8-
#include "catch.hpp"
99
#include "symforce_function_codegen_test_data/symengine/codegen_matrix_order_data/matrix_order.h"
1010

1111
TEST_CASE("Codegened matrix order is correct", "[codegen_matrix_order]") {

test/codegen_multi_function_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* This source code is under the Apache 2.0 license found in the LICENSE file.
44
* ---------------------------------------------------------------------------- */
55

6+
#include <catch2/catch_approx.hpp>
7+
#include <catch2/catch_test_macros.hpp>
8+
69
#include <lcmtypes/codegen_multi_function_test/inputs_constants_t.hpp>
710
#include <lcmtypes/codegen_multi_function_test/inputs_states_t.hpp>
811
#include <lcmtypes/codegen_multi_function_test/inputs_t.hpp>
@@ -13,8 +16,6 @@
1316
#include <symforce/codegen_multi_function_test/codegen_multi_function_test1.h>
1417
#include <symforce/codegen_multi_function_test/codegen_multi_function_test2.h>
1518

16-
#include "catch.hpp"
17-
1819
template <typename T>
1920
void FillChunkOfValues(T& values) {
2021
sym::Rot3<double> rot;

test/codegen_nan_test.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66
#include <math.h>
77

8+
#include <catch2/catch_test_macros.hpp>
89
#include <spdlog/spdlog.h>
910

1011
#include <sym/rot3.h>
1112
#include <symforce/codegen_nan_test/identity_dist_jacobian.h>
1213

13-
#include "catch.hpp"
14-
1514
TEST_CASE("Codegen function does not generate NaN", "[codegen_nan_test]") {
1615
spdlog::info("*** Testing codegen function for NaNs ***");
1716

test/codegen_sparse_matrix_test.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
#include <Eigen/Dense>
99
#include <Eigen/Sparse>
10+
#include <catch2/catch_test_macros.hpp>
1011
#include <spdlog/spdlog.h>
1112

1213
#include <symforce/codegen_sparse_matrix_test/get_diagonal_sparse.h>
1314
#include <symforce/codegen_sparse_matrix_test/get_multiple_dense_and_sparse.h>
1415
#include <symforce/codegen_sparse_matrix_test/update_sparse_mat.h>
1516

16-
#include "catch.hpp"
17-
1817
const int DIM = 100;
1918

2019
TEST_CASE("Sparse Matrix codegen works", "[codegen_sparse_matrix]") {

0 commit comments

Comments
 (0)