Skip to content

Commit

Permalink
Merge pull request ros2#10 from ros2/add_test_append_env_option
Browse files Browse the repository at this point in the history
Use APPEND_LIBRARY_DIRS option to ament_add_gtest to fix tests on Windows
  • Loading branch information
wjwwood committed Dec 31, 2015
2 parents 083f6ec + 4db5a77 commit 55814e6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions rcl/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ find_package(ament_cmake_gtest REQUIRED)

set(extra_test_libraries)
set(extra_memory_tools_env PHONY=) # Use a phony env var so there is always at least one.
# rcl_lib_dir is passed as APPEND_LIBRARY_DIRS for each ament_add_gtest call so
# the librcl that they link against is on the library path.
# This is especially improtant on Windows.
set(rcl_lib_dir $<TARGET_FILE_DIR:${PROJECT_NAME}>)
ament_find_gtest() # For GTEST_LIBRARIES
if(APPLE)
add_library(${PROJECT_NAME}_memory_tools_interpose SHARED memory_tools_osx_interpose.cpp)
Expand All @@ -26,7 +30,8 @@ target_compile_definitions(${PROJECT_NAME}_memory_tools
list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools)

if(NOT WIN32)
ament_add_gtest(test_memory_tools test_memory_tools.cpp ENV ${extra_memory_tools_env})
ament_add_gtest(test_memory_tools test_memory_tools.cpp
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
if(TARGET test_memory_tools)
target_include_directories(test_memory_tools PUBLIC
${rcl_interfaces_INCLUDE_DIRS}
Expand All @@ -39,7 +44,8 @@ if(NOT WIN32)
endif()
endif()

ament_add_gtest(test_allocator rcl/test_allocator.cpp ENV ${extra_memory_tools_env})
ament_add_gtest(test_allocator rcl/test_allocator.cpp
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
if(TARGET test_allocator)
target_include_directories(test_allocator PUBLIC
${rcl_interfaces_INCLUDE_DIRS}
Expand All @@ -51,7 +57,8 @@ if(TARGET test_allocator)
target_link_libraries(test_allocator ${PROJECT_NAME} ${extra_test_libraries})
endif()

ament_add_gtest(test_time rcl/test_time.cpp ENV ${extra_memory_tools_env})
ament_add_gtest(test_time rcl/test_time.cpp
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
if(TARGET test_time)
target_include_directories(test_time PUBLIC
${rcl_interfaces_INCLUDE_DIRS}
Expand All @@ -69,6 +76,8 @@ ament_add_gtest(test_common
${extra_memory_tools_env}
EMPTY_TEST=
NORMAL_TEST=foo
APPEND_LIBRARY_DIRS
${rcl_lib_dir}
)
if(TARGET test_common)
target_include_directories(test_common PUBLIC
Expand All @@ -81,7 +90,8 @@ if(TARGET test_common)
target_link_libraries(test_common ${PROJECT_NAME} ${extra_test_libraries})
endif()

ament_add_gtest(test_rcl rcl/test_rcl.cpp ENV ${extra_memory_tools_env})
ament_add_gtest(test_rcl rcl/test_rcl.cpp
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
if(TARGET test_rcl)
target_include_directories(test_rcl PUBLIC
${rcl_interfaces_INCLUDE_DIRS}
Expand All @@ -93,7 +103,8 @@ if(TARGET test_rcl)
target_link_libraries(test_rcl ${PROJECT_NAME} ${extra_test_libraries})
endif()

ament_add_gtest(test_node rcl/test_node.cpp ENV ${extra_memory_tools_env})
ament_add_gtest(test_node rcl/test_node.cpp
ENV ${extra_memory_tools_env} APPEND_LIBRARY_DIRS ${rcl_lib_dir})
if(TARGET test_node)
target_include_directories(test_node PUBLIC
${rcl_interfaces_INCLUDE_DIRS}
Expand Down

0 comments on commit 55814e6

Please sign in to comment.