Added cartographer test library to CMake project (#1129)
Fake, mock and test helpers are now compiled into a test library. This should resolve #1128. The bazel build file was updated in #1101.master
parent
13d9754155
commit
913b1b5856
|
@ -59,6 +59,8 @@ install(DIRECTORY cmake DESTINATION share/cartographer/)
|
||||||
|
|
||||||
file(GLOB_RECURSE ALL_LIBRARY_HDRS "cartographer/*.h")
|
file(GLOB_RECURSE ALL_LIBRARY_HDRS "cartographer/*.h")
|
||||||
file(GLOB_RECURSE ALL_LIBRARY_SRCS "cartographer/*.cc")
|
file(GLOB_RECURSE ALL_LIBRARY_SRCS "cartographer/*.cc")
|
||||||
|
file(GLOB_RECURSE TEST_LIBRARY_HDRS "cartographer/fake_*.h" "cartographer/*test_helpers*.h" "cartographer/mock_*.h")
|
||||||
|
file(GLOB_RECURSE TEST_LIBRARY_SRCS "cartographer/fake_*.cc" "cartographer/*test_helpers*.cc" "cartographer/mock_*.cc")
|
||||||
file(GLOB_RECURSE ALL_TESTS "cartographer/*_test.cc")
|
file(GLOB_RECURSE ALL_TESTS "cartographer/*_test.cc")
|
||||||
file(GLOB_RECURSE ALL_EXECUTABLES "cartographer/*_main.cc")
|
file(GLOB_RECURSE ALL_EXECUTABLES "cartographer/*_main.cc")
|
||||||
|
|
||||||
|
@ -67,24 +69,31 @@ file(GLOB_RECURSE ALL_DOTFILES ".*/*")
|
||||||
if (ALL_DOTFILES)
|
if (ALL_DOTFILES)
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_DOTFILES})
|
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_DOTFILES})
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_DOTFILES})
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_DOTFILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_HDRS ${ALL_DOTFILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_SRCS ${ALL_DOTFILES})
|
||||||
list(REMOVE_ITEM ALL_TESTS ${ALL_DOTFILES})
|
list(REMOVE_ITEM ALL_TESTS ${ALL_DOTFILES})
|
||||||
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_DOTFILES})
|
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_DOTFILES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_TESTS})
|
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_EXECUTABLES})
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_EXECUTABLES})
|
||||||
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_TESTS})
|
||||||
|
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${TEST_LIBRARY_HDRS})
|
||||||
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${TEST_LIBRARY_SRCS})
|
||||||
file(GLOB_RECURSE ALL_GRPC_FILES "cartographer/cloud/*")
|
file(GLOB_RECURSE ALL_GRPC_FILES "cartographer/cloud/*")
|
||||||
file(GLOB_RECURSE ALL_PROMETHEUS_FILES "cartographer/cloud/metrics/prometheus/*")
|
file(GLOB_RECURSE ALL_PROMETHEUS_FILES "cartographer/cloud/metrics/prometheus/*")
|
||||||
list(REMOVE_ITEM ALL_GRPC_FILES ${ALL_PROMETHEUS_FILES})
|
list(REMOVE_ITEM ALL_GRPC_FILES ${ALL_PROMETHEUS_FILES})
|
||||||
if (NOT ${BUILD_GRPC})
|
if (NOT ${BUILD_GRPC})
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_GRPC_FILES})
|
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_GRPC_FILES})
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_GRPC_FILES})
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_GRPC_FILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_HDRS ${ALL_GRPC_FILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_SRCS ${ALL_GRPC_FILES})
|
||||||
list(REMOVE_ITEM ALL_TESTS ${ALL_GRPC_FILES})
|
list(REMOVE_ITEM ALL_TESTS ${ALL_GRPC_FILES})
|
||||||
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_GRPC_FILES})
|
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_GRPC_FILES})
|
||||||
endif()
|
endif()
|
||||||
if (NOT ${BUILD_PROMETHEUS})
|
if (NOT ${BUILD_PROMETHEUS})
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_PROMETHEUS_FILES})
|
list(REMOVE_ITEM ALL_LIBRARY_HDRS ${ALL_PROMETHEUS_FILES})
|
||||||
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_PROMETHEUS_FILES})
|
list(REMOVE_ITEM ALL_LIBRARY_SRCS ${ALL_PROMETHEUS_FILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_HDRS ${ALL_PROMETHEUS_FILES})
|
||||||
|
list(REMOVE_ITEM TEST_LIBRARY_SRCS ${ALL_PROMETHEUS_FILES})
|
||||||
list(REMOVE_ITEM ALL_TESTS ${ALL_PROMETHEUS_FILES})
|
list(REMOVE_ITEM ALL_TESTS ${ALL_PROMETHEUS_FILES})
|
||||||
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_PROMETHEUS_FILES})
|
list(REMOVE_ITEM ALL_EXECUTABLES ${ALL_PROMETHEUS_FILES})
|
||||||
endif()
|
endif()
|
||||||
|
@ -182,22 +191,6 @@ if(${BUILD_GRPC})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(ABS_FIL ${ALL_TESTS})
|
|
||||||
file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${ABS_FIL})
|
|
||||||
get_filename_component(DIR ${REL_FIL} DIRECTORY)
|
|
||||||
get_filename_component(FIL_WE ${REL_FIL} NAME_WE)
|
|
||||||
# Replace slashes as required for CMP0037.
|
|
||||||
string(REPLACE "/" "." TEST_TARGET_NAME "${DIR}/${FIL_WE}")
|
|
||||||
google_test("${TEST_TARGET_NAME}" ${ABS_FIL})
|
|
||||||
if(${BUILD_GRPC})
|
|
||||||
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC grpc++)
|
|
||||||
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC async_grpc)
|
|
||||||
endif()
|
|
||||||
if(${BUILD_PROMETHEUS})
|
|
||||||
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC prometheus-cpp)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
|
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
|
||||||
"${EIGEN3_INCLUDE_DIR}")
|
"${EIGEN3_INCLUDE_DIR}")
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${EIGEN3_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} PUBLIC ${EIGEN3_LIBRARIES})
|
||||||
|
@ -236,6 +229,38 @@ if(${BUILD_PROMETHEUS})
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_PROMETHEUS=1)
|
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_PROMETHEUS=1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${GOOG_CXX_FLAGS}")
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
|
||||||
|
|
||||||
|
set(TEST_LIB
|
||||||
|
cartographer_test_library
|
||||||
|
)
|
||||||
|
add_library(${TEST_LIB} ${TEST_LIBRARY_HDRS} ${TEST_LIBRARY_SRCS})
|
||||||
|
target_include_directories(${TEST_LIB} SYSTEM PRIVATE
|
||||||
|
"${GMOCK_INCLUDE_DIRS}")
|
||||||
|
target_link_libraries(${TEST_LIB} PUBLIC ${GMOCK_LIBRARY})
|
||||||
|
target_link_libraries(${TEST_LIB} PUBLIC ${PROJECT_NAME})
|
||||||
|
set_target_properties(${TEST_LIB} PROPERTIES
|
||||||
|
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
|
||||||
|
|
||||||
|
foreach(ABS_FIL ${ALL_TESTS})
|
||||||
|
file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR} ${ABS_FIL})
|
||||||
|
get_filename_component(DIR ${REL_FIL} DIRECTORY)
|
||||||
|
get_filename_component(FIL_WE ${REL_FIL} NAME_WE)
|
||||||
|
# Replace slashes as required for CMP0037.
|
||||||
|
string(REPLACE "/" "." TEST_TARGET_NAME "${DIR}/${FIL_WE}")
|
||||||
|
google_test("${TEST_TARGET_NAME}" ${ABS_FIL})
|
||||||
|
if(${BUILD_GRPC})
|
||||||
|
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC grpc++)
|
||||||
|
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC async_grpc)
|
||||||
|
endif()
|
||||||
|
if(${BUILD_PROMETHEUS})
|
||||||
|
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC prometheus-cpp)
|
||||||
|
endif()
|
||||||
|
target_link_libraries("${TEST_TARGET_NAME}" PUBLIC ${TEST_LIB})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
# Add the binary directory first, so that port.h is included after it has
|
# Add the binary directory first, so that port.h is included after it has
|
||||||
# been generated.
|
# been generated.
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
|
@ -244,15 +269,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
$<INSTALL_INTERFACE:include>
|
$<INSTALL_INTERFACE:include>
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO(damonkohler): Create a testing library.
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
|
|
||||||
"${GMOCK_INCLUDE_DIRS}")
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${GMOCK_LIBRARY})
|
|
||||||
|
|
||||||
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${GOOG_CXX_FLAGS}")
|
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
||||||
COMPILE_FLAGS ${TARGET_COMPILE_FLAGS})
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS ${PROJECT_NAME}
|
TARGETS ${PROJECT_NAME}
|
||||||
EXPORT CartographerExport
|
EXPORT CartographerExport
|
||||||
|
|
Loading…
Reference in New Issue