Skip to content

Commit

Permalink
Prepare CMake files for testing support. (#47)
Browse files Browse the repository at this point in the history
- Only build gmock if we really require testing.
- Adds a wrapper for generating catkin aware tests. This works around
  ros/catkin#830.
  • Loading branch information
SirVer committed Oct 12, 2016
1 parent 8e7996f commit be813a0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(CARTOGRAPHER_SOVERSION ${CARTOGRAPHER_MAJOR_VERSION}.${CARTOGRAPHER_MINOR_VE

include("${CMAKE_SOURCE_DIR}/cmake/functions.cmake")
google_initialize_cartographer_project()
google_enable_testing()

find_package(Boost REQUIRED COMPONENTS system iostreams)
find_package(Ceres REQUIRED)
Expand All @@ -36,8 +37,6 @@ if(SPHINX_FOUND)
add_subdirectory("docs")
endif()

enable_testing()

SET(ALL_LIBRARIES "" CACHE INTERNAL "ALL_LIBRARIES")

# Install catkin package.xml
Expand Down
31 changes: 27 additions & 4 deletions cmake/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,39 @@ function(google_add_flag VAR_NAME FLAG)
endif()
endfunction()

function(google_test NAME)
_parse_arguments("${ARGN}")

macro(_common_test_stuff)
add_executable(${NAME}
${ARG_SRCS} ${ARG_HDRS}
)

_common_compile_stuff("PRIVATE")

# Make sure that gmock always includes the correct gtest/gtest.h.
target_include_directories("${NAME}" SYSTEM PRIVATE
"${GMOCK_SRC_DIR}/gtest/include")
target_link_libraries("${NAME}" gmock_main)
endmacro()

function(google_catkin_test NAME)
if(NOT "${CATKIN_ENABLE_TESTING}")
return()
endif()

_parse_arguments("${ARGN}")
_common_test_stuff()

# Copied from the catkin sources. Tracked in ros/catkin:#830.
add_dependencies(tests ${NAME})
get_target_property(_target_path ${NAME} RUNTIME_OUTPUT_DIRECTORY)
set(cmd "${_target_path}/${NAME} --gtest_output=xml:${CATKIN_TEST_RESULTS_DIR}/${PROJECT_NAME}/gtest-${NAME}.xml")
catkin_run_tests_target("gtest" ${NAME} "gtest-${NAME}.xml"
COMMAND ${cmd}
DEPENDENCIES ${NAME}
WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY})
endfunction()

function(google_test NAME)
_parse_arguments("${ARGN}")
_common_test_stuff()
add_test(${NAME} ${NAME})
endfunction()

Expand Down Expand Up @@ -335,6 +354,10 @@ macro(google_initialize_cartographer_project)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

endmacro()

macro(google_enable_testing)
set(GMOCK_SRC_DIR "/usr/src/gmock" CACHE STRING "Path to google-mock sources.")
add_subdirectory(${GMOCK_SRC_DIR} "${CMAKE_CURRENT_BINARY_DIR}/gmock")
enable_testing()
endmacro()

0 comments on commit be813a0

Please sign in to comment.