Skip to content

Commit 814ca70

Browse files
authored
Add BUILD_TESTING option, tests target (#235)
- Add `BUILD_TESTING` option - ON by default - Test targets are only added if it is ON - Why this name (instead of `BUILD_TESTS`)? It seems to be a standard CMake name, used by CTest - Add `tests` target - `make tests` builds the tests but does not run them. By the way, `make test` runs them. - Why this name in particular? Because catkin uses it
1 parent 5878ac9 commit 814ca70

File tree

11 files changed

+124
-106
lines changed

11 files changed

+124
-106
lines changed

CMakeLists.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ OPTION(BUILD_SHARED_LIBS "Build shared instead of static libraries" OFF)
2929
OPTION(EXPORT_BUILD
3030
"Add this build directory to CMake's user package registry.\
3131
Allows the package to be found without install." OFF)
32+
OPTION(BUILD_TESTING "Build tests" ON)
3233
OPTION(BUILD_BENCHMARKS
3334
"Build benchmarks for some components. Requires google benchmark package."
3435
OFF)
@@ -52,6 +53,17 @@ INCLUDE(cmake/ImportBoost.cmake)
5253
INCLUDE(cmake/ImportPCL.cmake)
5354
INCLUDE(cmake/ImportKindr.cmake)
5455

56+
# Optionally build tests. `gtest` is included with this project
57+
IF(BUILD_TESTING)
58+
# Build gtest from source
59+
ADD_SUBDIRECTORY(deps/googletest EXCLUDE_FROM_ALL)
60+
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include/ ${gtest_SOURCE_DIR})
61+
62+
# This target is used to build all tests, without running them
63+
ADD_CUSTOM_TARGET(tests)
64+
MESSAGE(STATUS "Building tests")
65+
ENDIF(BUILD_TESTING)
66+
5567
# Optionally build benchmarks (requires `benchmark` package to be installed)
5668
IF(BUILD_BENCHMARKS)
5769
FIND_PACKAGE(benchmark REQUIRED)
@@ -68,6 +80,7 @@ IF(BUILD_BENCHMARKS)
6880
# It runs all tests labelled "benchmark" by WAVE_ADD_BENCHMARK helper.
6981
ADD_CUSTOM_TARGET(benchmark
7082
COMMAND ${CMAKE_CTEST_COMMAND} -C benchmark -L benchmark)
83+
MESSAGE(STATUS "Building benchmarks")
7184
ENDIF(BUILD_BENCHMARKS)
7285

7386
# Add a special "wave" target including all modules
@@ -88,10 +101,6 @@ ADD_SUBDIRECTORY(wave_matching)
88101
ADD_SUBDIRECTORY(wave_vision)
89102
ADD_SUBDIRECTORY(wave_optimization)
90103

91-
# gtest
92-
ADD_SUBDIRECTORY(deps/googletest EXCLUDE_FROM_ALL)
93-
INCLUDE_DIRECTORIES(${gtest_SOURCE_DIR}/include/ ${gtest_SOURCE_DIR})
94-
95104
# Documentation
96105
SET(WAVE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
97106
SET(WAVE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

cmake/WaveHelpers.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ FUNCTION(WAVE_ADD_TEST NAME)
3030
SET_TARGET_PROPERTIES(${NAME} PROPERTIES
3131
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
3232

33+
# Build this test on "make tests"
34+
ADD_DEPENDENCIES(tests ${NAME})
35+
3336
IF(NOT WAVE_ADD_TEST_DISABLED)
3437
# Add the executable as a test, so it runs with "make test"
3538
ADD_TEST(NAME ${NAME} COMMAND ${NAME})

wave_benchmark/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
1010
src/trajectory_compare.cpp)
1111

1212
# Unit tests
13-
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
13+
IF(BUILD_TESTING)
14+
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/tests)
1415

15-
WAVE_ADD_TEST(
16-
${PROJECT_NAME}_tests
17-
tests/benchmark/benchmark_tests.cpp
18-
)
19-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
16+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
17+
tests/benchmark/benchmark_tests.cpp)
18+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
19+
ENDIF(BUILD_TESTING)

wave_containers/CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
66
Boost::boost)
77

88
# Unit tests
9-
WAVE_ADD_TEST(${PROJECT_NAME}_tests
10-
tests/measurement_test.cpp
11-
tests/landmark_measurement_test.cpp)
9+
IF(BUILD_TESTING)
10+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
11+
tests/measurement_test.cpp
12+
tests/landmark_measurement_test.cpp)
1213

13-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
14+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
15+
ENDIF(BUILD_TESTING)
1416

1517
IF(BUILD_BENCHMARKS)
1618
WAVE_ADD_BENCHMARK(${PROJECT_NAME}_benchmark

wave_controls/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
77
src/pid.cpp)
88

99
# Unit tests
10-
WAVE_ADD_TEST(${PROJECT_NAME}_tests tests/pid_test.cpp)
11-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
10+
IF(BUILD_TESTING)
11+
WAVE_ADD_TEST(${PROJECT_NAME}_tests tests/pid_test.cpp)
12+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
13+
ENDIF(BUILD_TESTING)

wave_geometry/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
99
src/rotation.cpp)
1010

1111
# Unit tests
12-
WAVE_ADD_TEST(${PROJECT_NAME}_tests tests/rotation_test.cpp)
13-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
12+
IF(BUILD_TESTING)
13+
WAVE_ADD_TEST(${PROJECT_NAME}_tests tests/rotation_test.cpp)
14+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
15+
ENDIF(BUILD_TESTING)

wave_kinematics/CMakeLists.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
1212
src/two_wheel.cpp)
1313

1414
# Unit tests
15-
WAVE_ADD_TEST(
16-
${PROJECT_NAME}_tests
17-
tests/gimbal_test.cpp
18-
tests/pose_test.cpp
19-
tests/quadrotor_test.cpp
20-
tests/two_wheel_test.cpp
21-
)
22-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
15+
IF(BUILD_TESTING)
16+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
17+
tests/gimbal_test.cpp
18+
tests/pose_test.cpp
19+
tests/quadrotor_test.cpp
20+
tests/two_wheel_test.cpp)
21+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
22+
ENDIF(BUILD_TESTING)

wave_matching/CMakeLists.txt

+15-16
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
1313
src/pointcloud_display.cpp)
1414

1515
# Unit tests
16-
WAVE_ADD_TEST(
17-
${PROJECT_NAME}_tests
18-
tests/icp_tests.cpp
19-
tests/ndt_tests.cpp
20-
tests/gicp_tests.cpp
21-
tests/multi_matcher_tests.cpp
22-
)
16+
IF(BUILD_TESTING)
17+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
18+
tests/icp_tests.cpp
19+
tests/ndt_tests.cpp
20+
tests/gicp_tests.cpp
21+
tests/multi_matcher_tests.cpp)
2322

24-
WAVE_ADD_TEST(
25-
${PROJECT_NAME}_viz_tests
26-
tests/pointcloud_display_tests.cpp
27-
DISABLED # probably requires display to work properly
28-
)
29-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
23+
WAVE_ADD_TEST(${PROJECT_NAME}_viz_tests
24+
tests/pointcloud_display_tests.cpp
25+
DISABLED) # probably requires display to work properly
3026

31-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_viz_tests ${PROJECT_NAME})
27+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
3228

33-
# Copy the test data
34-
file(COPY tests/data tests/config DESTINATION ${PROJECT_BINARY_DIR}/tests)
29+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_viz_tests ${PROJECT_NAME})
30+
31+
# Copy the test data
32+
file(COPY tests/data tests/config DESTINATION ${PROJECT_BINARY_DIR}/tests)
33+
ENDIF(BUILD_TESTING)

wave_optimization/CMakeLists.txt

+30-28
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,33 @@ WAVE_ADD_MODULE(${PROJECT_NAME} DEPENDS
1515
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} SYSTEM PUBLIC ${CERES_INCLUDE_DIRS})
1616

1717
# Unit tests
18-
WAVE_ADD_TEST(${PROJECT_NAME}_tests
19-
tests/ceres/ba_test.cpp
20-
tests/ceres/ceres_examples_test.cpp)
21-
22-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
23-
24-
IF(GTSAM_FOUND)
25-
# Set for consistency, since GTSAM's config file does not
26-
SET(GTSAM_LIBRARIES gtsam)
27-
INCLUDE_DIRECTORIES(${GTSAM_INCLUDE_DIR})
28-
29-
WAVE_ADD_TEST(vo_gtsam_offline_example
30-
tests/gtsam/gtsam_offline_example.cpp)
31-
TARGET_LINK_LIBRARIES(vo_gtsam_offline_example
32-
${PROJECT_NAME}
33-
wave::vision
34-
${GTSAM_LIBRARIES})
35-
36-
WAVE_ADD_TEST(vo_gtsam_offline_kitti_example
37-
tests/gtsam/gtsam_offline_kitti_example.cpp)
38-
TARGET_LINK_LIBRARIES(vo_gtsam_offline_kitti_example
39-
${PROJECT_NAME}
40-
wave::vision
41-
${GTSAM_LIBRARIES})
42-
ENDIF()
43-
44-
# COPY TEST DATA
45-
FILE(COPY tests/data DESTINATION ${PROJECT_BINARY_DIR}/tests)
18+
IF(BUILD_TESTING)
19+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
20+
tests/ceres/ba_test.cpp
21+
tests/ceres/ceres_examples_test.cpp)
22+
23+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
24+
25+
IF(GTSAM_FOUND)
26+
# Set for consistency, since GTSAM's config file does not
27+
SET(GTSAM_LIBRARIES gtsam)
28+
INCLUDE_DIRECTORIES(${GTSAM_INCLUDE_DIR})
29+
30+
WAVE_ADD_TEST(vo_gtsam_offline_example
31+
tests/gtsam/gtsam_offline_example.cpp)
32+
TARGET_LINK_LIBRARIES(vo_gtsam_offline_example
33+
${PROJECT_NAME}
34+
wave::vision
35+
${GTSAM_LIBRARIES})
36+
37+
WAVE_ADD_TEST(vo_gtsam_offline_kitti_example
38+
tests/gtsam/gtsam_offline_kitti_example.cpp)
39+
TARGET_LINK_LIBRARIES(vo_gtsam_offline_kitti_example
40+
${PROJECT_NAME}
41+
wave::vision
42+
${GTSAM_LIBRARIES})
43+
ENDIF()
44+
45+
# COPY TEST DATA
46+
FILE(COPY tests/data DESTINATION ${PROJECT_BINARY_DIR}/tests)
47+
ENDIF(BUILD_TESTING)

wave_utils/CMakeLists.txt

+12-14
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
1313
src/time.cpp)
1414

1515
# Unit tests
16-
WAVE_ADD_TEST(
17-
${PROJECT_NAME}_tests
18-
tests/utils/config_test.cpp
19-
tests/utils/data_test.cpp
20-
tests/utils/file_test.cpp
21-
tests/utils/math_test.cpp
22-
tests/utils/time_test.cpp
23-
)
24-
TARGET_LINK_LIBRARIES(
25-
${PROJECT_NAME}_tests
26-
${PROJECT_NAME}
27-
)
16+
IF(BUILD_TESTING)
17+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
18+
tests/utils/config_test.cpp
19+
tests/utils/data_test.cpp
20+
tests/utils/file_test.cpp
21+
tests/utils/math_test.cpp
22+
tests/utils/time_test.cpp)
2823

29-
# COPY TEST DATA
30-
FILE(COPY tests/data DESTINATION ${PROJECT_BINARY_DIR}/tests)
24+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
25+
26+
# COPY TEST DATA
27+
FILE(COPY tests/data DESTINATION ${PROJECT_BINARY_DIR}/tests)
28+
ENDIF(BUILD_TESTING)

wave_vision/CMakeLists.txt

+23-22
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@ WAVE_ADD_MODULE(${PROJECT_NAME}
2020
src/matcher/flann_matcher.cpp)
2121

2222
# Unit tests
23-
WAVE_ADD_TEST(${PROJECT_NAME}_tests
24-
tests/detector_tests/fast_tests.cpp
25-
tests/detector_tests/orb_tests.cpp
26-
tests/descriptor_tests/brisk_tests.cpp
27-
tests/descriptor_tests/orb_tests.cpp
28-
tests/matcher_tests/brute_force_tests.cpp
29-
tests/matcher_tests/flann_tests.cpp
30-
tests/tracker_tests/tracker_tests.cpp
31-
tests/dataset_tests/vo_dataset_tests.cpp
32-
tests/utils_tests.cpp)
33-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
23+
IF(BUILD_TESTING)
24+
WAVE_ADD_TEST(${PROJECT_NAME}_tests
25+
tests/detector_tests/fast_tests.cpp
26+
tests/detector_tests/orb_tests.cpp
27+
tests/descriptor_tests/brisk_tests.cpp
28+
tests/descriptor_tests/orb_tests.cpp
29+
tests/matcher_tests/brute_force_tests.cpp
30+
tests/matcher_tests/flann_tests.cpp
31+
tests/tracker_tests/tracker_tests.cpp
32+
tests/dataset_tests/vo_dataset_tests.cpp
33+
tests/utils_tests.cpp)
34+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_tests ${PROJECT_NAME})
3435

35-
WAVE_ADD_TEST(
36-
${PROJECT_NAME}_viz_tests
37-
tests/viz_tests/detector_viz_tests.cpp
38-
tests/viz_tests/descriptor_viz_tests.cpp
39-
tests/viz_tests/matcher_viz_tests.cpp
40-
tests/viz_tests/tracker_viz_tests.cpp
41-
DISABLED # Requires display to run
42-
)
43-
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_viz_tests ${PROJECT_NAME})
36+
WAVE_ADD_TEST(${PROJECT_NAME}_viz_tests
37+
tests/viz_tests/detector_viz_tests.cpp
38+
tests/viz_tests/descriptor_viz_tests.cpp
39+
tests/viz_tests/matcher_viz_tests.cpp
40+
tests/viz_tests/tracker_viz_tests.cpp
41+
DISABLED) # Requires display to run
4442

45-
# COPY TEST DATA
46-
FILE(COPY tests/data tests/config DESTINATION ${PROJECT_BINARY_DIR}/tests)
43+
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_viz_tests ${PROJECT_NAME})
44+
45+
# COPY TEST DATA
46+
FILE(COPY tests/data tests/config DESTINATION ${PROJECT_BINARY_DIR}/tests)
47+
ENDIF(BUILD_TESTING)

0 commit comments

Comments
 (0)