build: default the tests to the build mode instead of always on

The standalone CMake build is the robot deployment path and must not produce
test executables; a catkin workspace is a development machine and keeps them.
Force with -D<option>=ON to build the tests from a standalone build.
This commit is contained in:
2026-08-15 12:41:31 +07:00
parent 64983bc6f7
commit 081c520b8a

View File

@@ -131,11 +131,17 @@ endif()
# ========================================================
# Test executables
# ========================================================
if(GTest_FOUND OR GTEST_FOUND)
# Tests are a development-machine concern: a catkin workspace is where they run,
# while the standalone CMake build is the robot deployment path and must not
# produce test executables. Force with -DBUILD_VOXEL_GRID_TESTS=ON to build them
# from a standalone build.
option(BUILD_VOXEL_GRID_TESTS "Build the robot_voxel_grid unit tests" ${BUILDING_WITH_CATKIN})
if(BUILD_VOXEL_GRID_TESTS AND (GTest_FOUND OR GTEST_FOUND))
enable_testing()
find_package(Boost REQUIRED COMPONENTS system thread)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/voxel_grid_tests.cpp)
if(BUILD_VOXEL_GRID_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/voxel_grid_tests.cpp)
add_executable(${PROJECT_NAME}_test test/voxel_grid_tests.cpp)
target_link_libraries(${PROJECT_NAME}_test PRIVATE
${PROJECT_NAME}