|
1 | 1 |
|
2 |
| -if(ENABLE_UNIT_TESTS) |
3 | 2 |
|
4 |
| - # Gimbal controller plugin |
5 |
| - add_executable(gazebo_gimbal_controller_plugin_test gazebo_gimbal_controller_plugin_test.cpp) |
| 3 | +if(ENABLE_UNIT_TESTS OR CATKIN_ENABLE_TESTING) |
6 | 4 |
|
7 |
| - target_link_libraries(gazebo_gimbal_controller_plugin_test |
8 |
| - PRIVATE gazebo_gimbal_controller_plugin |
9 |
| - ${GTEST_BOTH_LIBRARIES} |
10 |
| - ${CMAKE_THREAD_LIBS_INIT}) |
| 5 | +# Uniform way to add unit tests. This works with catkin and with plain CMake. |
| 6 | +function(add_unit_test target) # add sources as ARGN |
11 | 7 |
|
12 |
| - add_test(gazebo_gimbal_controller_plugin_test gazebo_gimbal_controller_plugin_test) |
| 8 | + if(ENABLE_UNIT_TESTS) |
13 | 9 |
|
14 |
| - # GPS plugin |
15 |
| - add_executable(gazebo_gps_plugin_test gazebo_gps_plugin_test.cpp) |
| 10 | + # Plain CMake to add google test |
| 11 | + add_executable(${target} ${ARGN}) |
| 12 | + add_test(${target} ${target}) |
| 13 | + |
| 14 | + elseif(CATKIN_ENABLE_TESTING) |
| 15 | + |
| 16 | + # Catkin google test facilities |
| 17 | + catkin_add_gtest(${target} ${ARGN}) |
| 18 | + |
| 19 | + endif(ENABLE_UNIT_TESTS) |
| 20 | + |
| 21 | + # Link the gtest libraries in any case |
| 22 | + target_link_libraries(${target} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) |
| 23 | + |
| 24 | +endfunction(add_unit_test) |
16 | 25 |
|
17 |
| - target_link_libraries(gazebo_gps_plugin_test |
18 |
| - PRIVATE gazebo_gps_plugin |
19 |
| - ${GTEST_BOTH_LIBRARIES} |
20 |
| - ${CMAKE_THREAD_LIBS_INIT}) |
21 | 26 |
|
22 |
| - add_test(gazebo_gps_plugin_test gazebo_gps_plugin_test) |
| 27 | +# Add the tests |
| 28 | + |
| 29 | + |
| 30 | + # Gimbal controller plugin |
| 31 | + add_unit_test(gazebo_gimbal_controller_plugin_test gazebo_gimbal_controller_plugin_test.cpp) |
| 32 | + target_link_libraries(gazebo_gimbal_controller_plugin_test gazebo_gimbal_controller_plugin) |
| 33 | + |
| 34 | + # GPS plugin |
| 35 | + add_unit_test(gazebo_gps_plugin_test gazebo_gps_plugin_test.cpp) |
| 36 | + target_link_libraries(gazebo_gps_plugin_test gazebo_gps_plugin) |
| 37 | + |
23 | 38 |
|
24 |
| -endif(ENABLE_UNIT_TESTS) |
| 39 | +endif(ENABLE_UNIT_TESTS OR CATKIN_ENABLE_TESTING) |
0 commit comments