diff --git a/tracetools/CMakeLists.txt b/tracetools/CMakeLists.txt index 1e9ffb8..3de8d4d 100644 --- a/tracetools/CMakeLists.txt +++ b/tracetools/CMakeLists.txt @@ -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() diff --git a/tracetools/package.xml b/tracetools/package.xml index 35e0276..201e985 100644 --- a/tracetools/package.xml +++ b/tracetools/package.xml @@ -13,7 +13,6 @@ ament_cmake_ros pkg-config - ament_cmake_gtest ament_lint_auto ament_lint_common diff --git a/tracetools_test/CMakeLists.txt b/tracetools_test/CMakeLists.txt index 24211d0..df8c4a9 100644 --- a/tracetools_test/CMakeLists.txt +++ b/tracetools_test/CMakeLists.txt @@ -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} diff --git a/tracetools_test/package.xml b/tracetools_test/package.xml index 62142d9..f8cc79e 100644 --- a/tracetools_test/package.xml +++ b/tracetools_test/package.xml @@ -20,6 +20,7 @@ std_msgs std_srvs + ament_cmake_gtest ament_cmake_mypy ament_cmake_pytest ament_lint_auto diff --git a/tracetools/test/test_utils.cpp b/tracetools_test/test/test_utils.cpp similarity index 100% rename from tracetools/test/test_utils.cpp rename to tracetools_test/test/test_utils.cpp