Skip to content

Commit

Permalink
Cleanup of the CMakeLists.txt for test_rclcpp. (#526)
Browse files Browse the repository at this point in the history
Switch to target_link_libraries, and also only find
the cpp typesupport once.  This slightly speeds up
the build as a side bonus.

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette committed Aug 24, 2023
1 parent d871c5b commit b56ca1c
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions test_rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ find_package(ament_cmake REQUIRED)

if(BUILD_TESTING)
find_package(rclcpp REQUIRED)
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${rclcpp_INCLUDE_DIRS})

find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
Expand Down Expand Up @@ -43,6 +42,8 @@ if(BUILD_TESTING)
find_package("${rmw_implementation}" REQUIRED)
endforeach()

rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}" "rosidl_typesupport_cpp")

macro(custom_gtest target)
ament_add_gtest(${target}${target_suffix} ${ARGN}
APPEND_LIBRARY_DIRS "${append_library_dirs}"
Expand All @@ -52,10 +53,7 @@ if(BUILD_TESTING)
if(TARGET ${target}${target_suffix})
target_compile_definitions(${target}${target_suffix}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}" "rosidl_typesupport_cpp")
target_link_libraries(${target}${target_suffix} "${cpp_typesupport_target}")
ament_target_dependencies(${target}${target_suffix}
"rclcpp")
target_link_libraries(${target}${target_suffix} "${cpp_typesupport_target}" rclcpp::rclcpp)
target_include_directories(${target}${target_suffix} PUBLIC include)
endif()
endmacro()
Expand All @@ -64,20 +62,14 @@ if(BUILD_TESTING)
add_executable(${target} ${ARGN})
target_compile_definitions(${target}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}" "rosidl_typesupport_cpp")
target_link_libraries(${target} "${cpp_typesupport_target}")
ament_target_dependencies(${target}
"rclcpp")
target_link_libraries(${target} "${cpp_typesupport_target}" rclcpp::rclcpp)
endfunction()

function(custom_gtest_executable target)
ament_add_gtest_executable(${target} ${ARGN})
target_compile_definitions(${target}
PUBLIC "RMW_IMPLEMENTATION=${rmw_implementation}")
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}" "rosidl_typesupport_cpp")
target_link_libraries(${target} "${cpp_typesupport_target}")
ament_target_dependencies(${target}
"rclcpp")
target_link_libraries(${target} "${cpp_typesupport_target}" rclcpp::rclcpp)
endfunction()

macro(custom_launch_test_two_executables test_name executable1 executable2)
Expand Down Expand Up @@ -374,14 +366,11 @@ if(BUILD_TESTING)

# Test node names
add_executable(node_with_name "test/node_with_name.cpp")
ament_target_dependencies(node_with_name
"rclcpp")
target_link_libraries(node_with_name rclcpp::rclcpp)
add_executable(node_name_list "test/node_name_list.cpp")
ament_target_dependencies(node_name_list
"rclcpp")
target_link_libraries(node_name_list rclcpp::rclcpp)
add_executable(node_check_names "test/node_check_names.cpp")
ament_target_dependencies(node_check_names
"rclcpp")
target_link_libraries(node_check_names rclcpp::rclcpp)

call_for_each_rmw_implementation(targets)

Expand All @@ -405,8 +394,3 @@ endif() # BUILD_TESTING

# TODO should not install anything
ament_package()

if(TEST cppcheck)
# cppcheck test is created in hook in ament_package()
set_tests_properties(cppcheck PROPERTIES TIMEOUT 400)
endif()

0 comments on commit b56ca1c

Please sign in to comment.