Added macros to remove copy/paste in cmake. Added support for building without convenience libraries.

release/4.3a0
Alex Cunningham 2012-02-14 20:00:42 +00:00
parent 0409c1c7ee
commit 23971aa044
10 changed files with 135 additions and 302 deletions

View File

@ -54,6 +54,10 @@ if (GTSAM_BUILD_TESTS)
include(CTest)
endif()
# Use macros for creating tests/timing scripts
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(GtsamTesting)
# Enable make check (http://www.cmake.org/Wiki/CMakeEmulateMakeCheck)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_custom_target(timing)

65
cmake/GtsamTesting.cmake Normal file
View File

@ -0,0 +1,65 @@
# 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 ${subdir}.${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 ${subdir}.${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 ${subdir}.${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()

View File

@ -15,10 +15,3 @@ foreach(eigen_dir ${eigen_dir_headers_all})
install(FILES Eigen/Eigen/${filename} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/gtsam/3rdparty/Eigen/Eigen)
endif()
endforeach(eigen_dir)
## build convenience library
#set (3rdparty_srcs
# CCOLAMD/Source/ccolamd.c
# CCOLAMD/Source/ccolamd_global.c
# UFconfig/UFconfig.c)
#add_library(ccolamd STATIC ${3rdparty_srcs})

View File

@ -3,52 +3,17 @@ file(GLOB base_headers "*.h")
install(FILES ${base_headers} DESTINATION include/gtsam/base)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(base_local_libs
CppUnitLite
base)
else()
set(base_local_libs
CppUnitLite
gtsam-static)
endif()
base
)
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.base COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB base_tests_srcs "tests/test*.cpp")
foreach(test_src ${base_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin base.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.base ${test_bin})
add_dependencies(check ${test_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${base_local_libs})
endif()
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin} )
target_link_libraries(${test_bin} ${base_local_libs} ${Boost_LIBRARIES})
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(base "${base_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.base)
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 base.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.base ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${base_local_libs})
endif()
target_link_libraries(${time_bin} ${base_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(base "${base_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -3,58 +3,18 @@ file(GLOB geometry_headers "*.h")
install(FILES ${geometry_headers} DESTINATION include/gtsam/geometry)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(geometry_local_libs
geometry
base
CppUnitLite
geometry
)
# link back to base
add_dependencies(geometry base)
else()
set(geometry_local_libs
CppUnitLite
gtsam-static
)
endif()
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.geometry COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB geometry_tests_srcs "tests/test*.cpp")
foreach(test_src ${geometry_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin geometry.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.geometry ${test_bin})
add_dependencies(check ${test_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} gtsam-static)
endif()
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
target_link_libraries(${test_bin} ${geometry_local_libs} ${Boost_LIBRARIES})
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(geometry "${geometry_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.geometry)
file(GLOB geometry_timing_srcs "tests/time*.cpp")
foreach(time_src ${geometry_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin geometry.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.geometry ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} gtsam-static)
endif()
target_link_libraries(${time_bin} ${geometry_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(geometry "${geometry_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -3,58 +3,20 @@ file(GLOB inference_headers "*.h")
install(FILES ${inference_headers} DESTINATION include/gtsam/inference)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(inference_local_libs
inference
geometry
base
ccolamd
CppUnitLite)
# link back to previous convenience library
add_dependencies(inference base)
else()
set(inference_local_libs
CppUnitLite
gtsam-static
)
endif()
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.inference COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB inference_tests_srcs "tests/test*.cpp")
foreach(test_src ${inference_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin inference.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.inference ${test_bin})
add_dependencies(check ${test_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${inference_local_libs})
endif()
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
target_link_libraries(${test_bin} ${inference_local_libs} ${Boost_LIBRARIES})
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(inference "${inference_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.inference)
file(GLOB inference_timing_srcs "tests/time*.cpp")
foreach(time_src ${inference_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin inference.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.inference ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${inference_local_libs})
endif()
target_link_libraries(${time_bin} ${inference_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(inference "${inference_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -3,59 +3,20 @@ file(GLOB linear_headers "*.h")
install(FILES ${linear_headers} DESTINATION include/gtsam/linear)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(linear_local_libs
linear
inference
geometry
base
ccolamd
CppUnitLite)
# link back to base
add_dependencies(linear inference)
else()
set(linear_local_libs
CppUnitLite
gtsam-static
)
endif()
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.linear COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB linear_tests_srcs "tests/test*.cpp")
foreach(test_src ${linear_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin linear.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.linear ${test_bin})
add_dependencies(check ${test_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${linear_local_libs})
endif()
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
target_link_libraries(${test_bin} ${linear_local_libs} ${Boost_LIBRARIES})
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(linear "${linear_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.linear)
file(GLOB linear_timing_srcs "tests/time*.cpp")
foreach(time_src ${linear_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin linear.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.linear ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${linear_local_libs})
endif()
target_link_libraries(${time_bin} ${linear_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(linear "${linear_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -3,7 +3,6 @@ file(GLOB nonlinear_headers "*.h")
install(FILES ${nonlinear_headers} DESTINATION include/gtsam/nonlinear)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(nonlinear_local_libs
nonlinear
linear
@ -11,52 +10,15 @@ if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
geometry
base
ccolamd
CppUnitLite)
# link back to base
add_dependencies(nonlinear linear)
else()
set(nonlinear_local_libs
CppUnitLite
gtsam-static
)
endif()
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.nonlinear COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB nonlinear_tests_srcs "tests/test*.cpp")
foreach(test_src ${nonlinear_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin nonlinear.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.nonlinear ${test_bin})
add_dependencies(check ${test_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${nonlinear_local_libs} )
endif()
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
target_link_libraries(${test_bin} ${nonlinear_local_libs} ${Boost_LIBRARIES})
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(nonlinear "${nonlinear_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.nonlinear)
file(GLOB nonlinear_timing_srcs "tests/time*.cpp")
foreach(time_src ${nonlinear_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin nonlinear.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.nonlinear ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${nonlinear_local_libs} )
endif()
target_link_libraries(${time_bin} ${nonlinear_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(nonlinear "${nonlinear_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -3,7 +3,6 @@ file(GLOB slam_headers "*.h")
install(FILES ${slam_headers} DESTINATION include/gtsam/slam)
# Components to link tests in this subfolder against
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
set(slam_local_libs
slam
nonlinear
@ -12,52 +11,14 @@ if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
geometry
base
ccolamd
CppUnitLite)
# link back to base
add_dependencies(slam nonlinear geometry)
else()
set(slam_local_libs
CppUnitLite
gtsam-static
)
endif()
# Build tests
if (GTSAM_BUILD_TESTS)
add_custom_target(check.slam COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB slam_tests_srcs "tests/test*.cpp")
foreach(test_src ${slam_tests_srcs})
get_filename_component(test_base ${test_src} NAME_WE)
set( test_bin slam.${test_base} )
message(STATUS "Adding Test ${test_bin}")
add_executable(${test_bin} ${test_src})
add_dependencies(check.slam ${test_bin})
add_dependencies(check ${test_bin})
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
target_link_libraries(${test_bin} ${slam_local_libs} ${Boost_LIBRARIES})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${test_bin} ${slam_local_libs})
endif()
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
gtsam_add_tests(slam "${slam_local_libs}")
endif(GTSAM_BUILD_TESTS)
# Build timing scripts
if (GTSAM_BUILD_TIMING)
add_custom_target(timing.slam)
file(GLOB slam_timing_srcs "tests/time*.cpp")
foreach(time_src ${slam_timing_srcs})
get_filename_component(time_base ${time_src} NAME_WE)
set( time_bin slam.${time_base} )
message(STATUS "Adding Timing Benchmark ${time_bin}")
add_executable(${time_bin} ${time_src})
add_dependencies(timing.slam ${time_bin})
add_dependencies(timing ${time_bin})
if (GTSAM_BUILD_CONVENIENCE_LIBRARIES)
add_dependencies(${time_bin} ${slam_local_libs})
endif()
target_link_libraries(${time_bin} ${slam_local_libs} ${Boost_LIBRARIES})
add_custom_target(${time_bin}.run ${EXECUTABLE_OUTPUT_PATH}${time_bin} ${ARGN})
endforeach(time_src)
gtsam_add_timing(slam "${slam_local_libs}")
endif(GTSAM_BUILD_TIMING)

View File

@ -16,17 +16,17 @@ endif(GTSAM_INSTALL_WRAP)
# Install matlab header
install(FILES matlab.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/wrap)
if (GTSAM_LINK_BINARIES_AGAINST_CONVENIENCE_LIBS)
set(convenience_libs
set(wrap_local_libs
base
# wrap_lib
# gtsam-static # FIXME: find a way to avoid this inclusion
)
else (GTSAM_LINK_BINARIES_AGAINST_CONVENIENCE_LIBS)
set(convenience_libs
gtsam-static)
endif (GTSAM_LINK_BINARIES_AGAINST_CONVENIENCE_LIBS)
# Build tests
if (GTSAM_BUILD_TESTS)
# FIXME: need to add way to force linking against local libs when convenience libraries are disabled
# gtsam_add_external_tests(wrap "${wrap_local_libs}")
add_custom_target(check.wrap COMMAND ${CMAKE_CTEST_COMMAND})
file(GLOB wrap_test_srcs "tests/test*.cpp")
add_definitions(-DTOPSRCDIR="${CMAKE_SOURCE_DIR}")
@ -37,7 +37,7 @@ if (GTSAM_BUILD_TESTS)
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}${test_bin})
add_dependencies(check ${test_bin})
add_dependencies(check.wrap ${test_bin})
target_link_libraries(${test_bin} CppUnitLite ${convenience_libs} wrap_lib)
target_link_libraries(${test_bin} CppUnitLite ${wrap_local_libs} wrap_lib)
add_custom_target(${test_bin}.run ${EXECUTABLE_OUTPUT_PATH}${test_bin} ${ARGN})
endforeach(test_src)
endif(GTSAM_BUILD_TESTS)