Merge branch '23-make-users-of-tracetools-automatically-use-rdynamic' into 'master'

Export "-rdynamic" link flag for downstream packages

Closes #23

See merge request micro-ROS/ros_tracing/ros2_tracing!156
This commit is contained in:
Christophe Bedard 2020-03-09 03:52:56 +00:00
commit 31f63d2f27
5 changed files with 21 additions and 35 deletions

View file

@ -20,6 +20,7 @@ else()
set(DISABLED_DEFAULT OFF)
endif()
option(TRACETOOLS_DISABLED "Explicitly disable support for tracing" ${DISABLED_DEFAULT})
option(TRACETOOLS_NO_RDYNAMIC "Disable export of -rdynamic link flag" OFF)
if(NOT TRACETOOLS_DISABLED)
# Set TRACETOOLS_LTTNG_ENABLED if we can find lttng-ust
@ -112,24 +113,23 @@ install(
ament_export_include_directories(include)
if(TRACETOOLS_LTTNG_ENABLED)
ament_export_libraries(${PROJECT_NAME} ${LTTNG_LIBRARIES})
# Export -rdynamic for downtream packages to use when calling
# ament_target_dependencies()
# which is needed to resolve function addresses to symbols when
# using function pointers directly/without std::bind()
# (the flag should not be used on Windows, but TRACETOOLS_LTTNG_ENABLED
# should never be true on Windows anyway, so there is no need to check)
if(NOT TRACETOOLS_NO_RDYNAMIC)
ament_export_link_flags("-rdynamic")
endif()
else()
ament_export_libraries(${PROJECT_NAME})
endif()
if(BUILD_TESTING)
set(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS ${LTTNG_INCLUDE_DIRS})
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
# Only build tracetools utils tests if LTTng is enabled and found
if(TRACETOOLS_LTTNG_ENABLED)
ament_add_gtest(test_utils test/test_utils.cpp)
if(TARGET test_utils)
target_link_libraries(test_utils ${PROJECT_NAME} -rdynamic)
endif()
endif()
endif()
ament_package()

View file

@ -13,7 +13,6 @@
<buildtool_depend>ament_cmake_ros</buildtool_depend>
<buildtool_depend>pkg-config</buildtool_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

View file

@ -26,17 +26,10 @@ endif()
# Tests
if(BUILD_TESTING)
# tracetools is exported by rclcpp
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(tracetools REQUIRED)
# Avoid using -rdynamic on Windows
if(NOT WIN32)
set(RDYNAMIC_FLAG "-rdynamic")
else()
set(RDYNAMIC_FLAG "")
endif()
add_executable(test_publisher
src/test_publisher.cpp
@ -44,62 +37,48 @@ if(BUILD_TESTING)
ament_target_dependencies(test_publisher
rclcpp
std_msgs
tracetools
)
target_link_libraries(test_publisher "${RDYNAMIC_FLAG}")
add_executable(test_intra
src/test_intra.cpp
)
ament_target_dependencies(test_intra
rclcpp
std_msgs
tracetools
)
target_link_libraries(test_intra "${RDYNAMIC_FLAG}")
add_executable(test_ping
src/test_ping.cpp
)
ament_target_dependencies(test_ping
rclcpp
std_msgs
tracetools
)
target_link_libraries(test_ping "${RDYNAMIC_FLAG}")
add_executable(test_pong
src/test_pong.cpp
)
ament_target_dependencies(test_pong
rclcpp
std_msgs
tracetools
)
target_link_libraries(test_pong "${RDYNAMIC_FLAG}")
add_executable(test_timer
src/test_timer.cpp
)
ament_target_dependencies(test_timer
rclcpp
tracetools
)
target_link_libraries(test_timer "${RDYNAMIC_FLAG}")
add_executable(test_service_ping
src/test_service_ping.cpp
)
ament_target_dependencies(test_service_ping
rclcpp
std_srvs
tracetools
)
target_link_libraries(test_service_ping "${RDYNAMIC_FLAG}")
add_executable(test_service_pong
src/test_service_pong.cpp
)
ament_target_dependencies(test_service_pong
rclcpp
std_srvs
tracetools
)
target_link_libraries(test_service_pong "${RDYNAMIC_FLAG}")
install(TARGETS
test_intra
@ -117,8 +96,16 @@ if(BUILD_TESTING)
# Only build tracing tests if LTTng is enabled and found
if(TRACING_ENABLED)
find_package(ament_cmake_pytest REQUIRED)
find_package(tracetools REQUIRED)
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(test_utils test/test_utils.cpp)
if(TARGET test_utils)
ament_target_dependencies(test_utils
tracetools
)
endif()
find_package(ament_cmake_pytest REQUIRED)
# Run each test in its own pytest invocation
set(_tracetools_test_pytest_tests
test/test_intra.py
@ -128,7 +115,6 @@ if(BUILD_TESTING)
test/test_subscription.py
test/test_timer.py
)
foreach(_test_path ${_tracetools_test_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}

View file

@ -20,6 +20,7 @@
<exec_depend>std_msgs</exec_depend>
<exec_depend>std_srvs</exec_depend>
<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_mypy</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_auto</test_depend>