diff --git a/rcl/CMakeLists.txt b/rcl/CMakeLists.txt index 92d6b8e..d967013 100644 --- a/rcl/CMakeLists.txt +++ b/rcl/CMakeLists.txt @@ -5,11 +5,10 @@ project(rcl) find_package(ament_cmake REQUIRED) find_package(rcl_interfaces REQUIRED) find_package(rmw REQUIRED) +find_package(rmw_implementation REQUIRED) +find_package(rmw_implementation_cmake REQUIRED) find_package(rosidl_generator_c REQUIRED) -ament_export_dependencies(rmw rosidl_generator_c) -ament_export_include_directories(include) - include_directories(include) if(NOT WIN32) @@ -28,93 +27,44 @@ set(${PROJECT_NAME}_sources src/rcl/time.c src/rcl/timer.c ) -add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_sources}) -ament_target_dependencies(${PROJECT_NAME} - "rcl_interfaces" - "rmw" - "rosidl_generator_c" -) -if(NOT WIN32) - set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-std=c11") -endif() + +macro(target) + add_library(${PROJECT_NAME}${target_suffix} SHARED ${${PROJECT_NAME}_sources}) + ament_target_dependencies(${PROJECT_NAME}${target_suffix} + "rcl_interfaces" + "rmw" + "rosidl_generator_c" + "${rmw_implementation}" + ) + + if(NOT WIN32) + set_target_properties(${PROJECT_NAME}${target_suffix} PROPERTIES COMPILE_FLAGS "-std=c11") + endif() + + install( + TARGETS ${PROJECT_NAME}${target_suffix} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) +endmacro() + +call_for_each_rmw_implementation(target GENERATE_DEFAULT) + +ament_export_dependencies(rcl_interfaces) +ament_export_dependencies(rmw) +ament_export_dependencies(rmw_implementation) +ament_export_dependencies(rosidl_generator_c) + +ament_export_include_directories(include) + +ament_export_libraries(${PROJECT_NAME}) if(AMENT_ENABLE_TESTING) find_package(ament_cmake_gtest REQUIRED) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() - set(extra_test_libraries) - set(extra_memory_tools_env PHONY=) # Use a phony env var so there is always at least one. - ament_find_gtest() # For GTEST_LIBRARIES - if(APPLE) - add_library(${PROJECT_NAME}_memory_tools_interpose SHARED test/memory_tools_osx_interpose.cpp) - target_link_libraries(${PROJECT_NAME}_memory_tools_interpose ${GTEST_LIBRARIES}) - set_target_properties(${PROJECT_NAME}_memory_tools_interpose - PROPERTIES COMPILE_FLAGS "-std=c++11") - list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools_interpose) - list(APPEND extra_memory_tools_env - DYLD_INSERT_LIBRARIES=$) - endif() - add_library(${PROJECT_NAME}_memory_tools SHARED test/memory_tools.cpp) - if(NOT WIN32) - set_target_properties(${PROJECT_NAME}_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11") - endif() - target_link_libraries(${PROJECT_NAME}_memory_tools ${GTEST_LIBRARIES} ${extra_test_libraries}) - list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools) - - ament_add_gtest(test_memory_tools test/test_memory_tools.cpp ENV ${extra_memory_tools_env}) - if(TARGET test_memory_tools) - target_include_directories(test_memory_tools PUBLIC - ${rcl_interfaces_INCLUDE_DIRS} - ${rmw_INCLUDE_DIRS} - ) - if(NOT WIN32) - set_target_properties(test_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11") - endif() - target_link_libraries(test_memory_tools ${PROJECT_NAME} ${extra_test_libraries}) - endif() - - ament_add_gtest(test_allocator test/rcl/test_allocator.cpp ENV ${extra_memory_tools_env}) - if(TARGET test_allocator) - target_include_directories(test_allocator PUBLIC - ${rcl_interfaces_INCLUDE_DIRS} - ${rmw_INCLUDE_DIRS} - ) - if(NOT WIN32) - set_target_properties(test_allocator PROPERTIES COMPILE_FLAGS "-std=c++11") - endif() - target_link_libraries(test_allocator ${PROJECT_NAME} ${extra_test_libraries}) - endif() - - ament_add_gtest(test_time test/rcl/test_time.cpp ENV ${extra_memory_tools_env}) - if(TARGET test_time) - target_include_directories(test_time PUBLIC - ${rcl_interfaces_INCLUDE_DIRS} - ${rmw_INCLUDE_DIRS} - ) - if(NOT WIN32) - set_target_properties(test_time PROPERTIES COMPILE_FLAGS "-std=c++11") - endif() - target_link_libraries(test_time ${PROJECT_NAME} ${extra_test_libraries}) - endif() - - ament_add_gtest(test_common - test/rcl/test_common.cpp - ENV - ${extra_memory_tools_env} - EMPTY_TEST= - NORMAL_TEST=foo - ) - if(TARGET test_common) - target_include_directories(test_common PUBLIC - ${rcl_interfaces_INCLUDE_DIRS} - ${rmw_INCLUDE_DIRS} - ) - if(NOT WIN32) - set_target_properties(test_common PROPERTIES COMPILE_FLAGS "-std=c++11") - endif() - target_link_libraries(test_common ${PROJECT_NAME} ${extra_test_libraries}) - endif() + add_subdirectory(test) endif() ament_package() diff --git a/rcl/package.xml b/rcl/package.xml index c0da176..493e2c1 100644 --- a/rcl/package.xml +++ b/rcl/package.xml @@ -10,17 +10,20 @@ ament_cmake - rmw - - rmw_implementation - rmw - rcl_interfaces - rosidl_generator_c + rcl_interfaces + rmw_implementation_cmake + rosidl_generator_c + rcl_interfaces + rosidl_generator_c + rmw_implementation + + ament_cmake_gtest ament_lint_auto ament_lint_common + rmw ament_cmake diff --git a/rcl/test/CMakeLists.txt b/rcl/test/CMakeLists.txt new file mode 100644 index 0000000..8f10bc2 --- /dev/null +++ b/rcl/test/CMakeLists.txt @@ -0,0 +1,74 @@ +if(AMENT_ENABLE_TESTING) + set(extra_test_libraries) + set(extra_memory_tools_env PHONY=) # Use a phony env var so there is always at least one. + ament_find_gtest() # For GTEST_LIBRARIES + if(APPLE) + add_library(${PROJECT_NAME}_memory_tools_interpose SHARED memory_tools_osx_interpose.cpp) + target_link_libraries(${PROJECT_NAME}_memory_tools_interpose ${GTEST_LIBRARIES}) + set_target_properties(${PROJECT_NAME}_memory_tools_interpose + PROPERTIES COMPILE_FLAGS "-std=c++11") + list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools_interpose) + list(APPEND extra_memory_tools_env + DYLD_INSERT_LIBRARIES=$) + endif() + add_library(${PROJECT_NAME}_memory_tools SHARED memory_tools.cpp) + if(NOT WIN32) + set_target_properties(${PROJECT_NAME}_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11") + endif() + target_link_libraries(${PROJECT_NAME}_memory_tools ${GTEST_LIBRARIES} ${extra_test_libraries}) + list(APPEND extra_test_libraries ${PROJECT_NAME}_memory_tools) + + ament_add_gtest(test_memory_tools test_memory_tools.cpp ENV ${extra_memory_tools_env}) + if(TARGET test_memory_tools) + target_include_directories(test_memory_tools PUBLIC + ${rcl_interfaces_INCLUDE_DIRS} + ${rmw_INCLUDE_DIRS} + ) + if(NOT WIN32) + set_target_properties(test_memory_tools PROPERTIES COMPILE_FLAGS "-std=c++11") + endif() + target_link_libraries(test_memory_tools ${PROJECT_NAME} ${extra_test_libraries}) + endif() + + ament_add_gtest(test_allocator rcl/test_allocator.cpp ENV ${extra_memory_tools_env}) + if(TARGET test_allocator) + target_include_directories(test_allocator PUBLIC + ${rcl_interfaces_INCLUDE_DIRS} + ${rmw_INCLUDE_DIRS} + ) + if(NOT WIN32) + set_target_properties(test_allocator PROPERTIES COMPILE_FLAGS "-std=c++11") + endif() + 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}) + if(TARGET test_time) + target_include_directories(test_time PUBLIC + ${rcl_interfaces_INCLUDE_DIRS} + ${rmw_INCLUDE_DIRS} + ) + if(NOT WIN32) + set_target_properties(test_time PROPERTIES COMPILE_FLAGS "-std=c++11") + endif() + target_link_libraries(test_time ${PROJECT_NAME} ${extra_test_libraries}) + endif() + + ament_add_gtest(test_common + rcl/test_common.cpp + ENV + ${extra_memory_tools_env} + EMPTY_TEST= + NORMAL_TEST=foo + ) + if(TARGET test_common) + target_include_directories(test_common PUBLIC + ${rcl_interfaces_INCLUDE_DIRS} + ${rmw_INCLUDE_DIRS} + ) + if(NOT WIN32) + set_target_properties(test_common PROPERTIES COMPILE_FLAGS "-std=c++11") + endif() + target_link_libraries(test_common ${PROJECT_NAME} ${extra_test_libraries}) + endif() +endif()