gtsam/cmake/GtsamTesting.cmake

65 lines
3.0 KiB
CMake

# Build macros for using tests
# Collects all tests in an adjacent tests folder and builds them
macro(gtsam_add_tests subdir libs)
add_custom_target(check.${subdir} COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB tests_srcs "tests/test*.cpp")
foreach(test_src ${tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin ${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.${subdir} ${test_bin})
add_dependencies(check ${test_bin})
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin} )
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${libs} CppUnitLite)
target_link_libraries(${test_bin} ${libs} ${Boost_LIBRARIES} CppUnitLite)
else()
add_dependencies(${test_bin} gtsam-static)
target_link_libraries(${test_bin} ${Boost_LIBRARIES} gtsam-static CppUnitLite)
endif()
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
endmacro()
# Collects all tests in an adjacent tests folder and builds them
# This version forces the use of libs, as necessary for wrap/tests
macro(gtsam_add_external_tests subdir libs)
add_custom_target(check.${subdir} COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB tests_srcs "tests/test*.cpp")
foreach(test_src ${tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin ${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.${subdir} ${test_bin})
add_dependencies(check ${test_bin})
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin} )
add_dependencies(${test_bin} ${libs} CppUnitLite)
target_link_libraries(${test_bin} ${libs} ${Boost_LIBRARIES} CppUnitLite)
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
endmacro()
# Collects timing scripts and builds them
macro(gtsam_add_timing subdir libs)
add_custom_target(timing.${subdir})
file(GLOB base_timing_srcs "tests/time*.cpp")
foreach(time_src ${base_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin ${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.${subdir} ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${libs})
target_link_libraries(${time_bin} ${libs} ${Boost_LIBRARIES} CppUnitLite)
else()
add_dependencies(${time_bin} gtsam-static)
target_link_libraries(${time_bin} ${Boost_LIBRARIES} gtsam-static CppUnitLite)
endif()
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
endmacro()