ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
By using @stevemacenski 's example project, I was able to solve the issue. I basically generated two projects from the same package and Cmake. I am aware it's not best practice - BUT I had to do it because I also had to pack it into a debian(Which can only pack one project).
Following is a template for such a project if anyone needs it in the future:
find_package(rosidl_default_generators REQUIRED)
...
set(library_name mynode)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/msgFile.msg"
)
add_library(${library_name} SHARED
${INCLUDES}
${SOURCES}
)
rosidl_get_typesupport_target(cpp_typesupport_target "${PROJECT_NAME}" "rosidl_typesupport_cpp")
target_link_libraries(${library_name} "${cpp_typesupport_target}")
ament_target_dependencies(${library_name}
${dependencies}
)
target_link_libraries(${library_name}
...
)
install(TARGETS ${library_name}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
rclcpp_components_register_node(${library_name}
PLUGIN "Myclass::ActiveNode"
EXECUTABLE activenode
)
target_include_directories(activenode PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
...
)
target_compile_features(activenode PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17
## Specify libraries to link a library or executable target against
target_link_libraries(activenode
...
)
ament_target_dependencies(activenode
${dependencies}
)
# Install binaries
install(TARGETS activenode
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Install headers
install(
DIRECTORY include/
DESTINATION include
)
# Install launch files
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)
install(DIRECTORY
config
DESTINATION share/${PROJECT_NAME}
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_export_include_directories(include)
ament_export_libraries(${library_name})
ament_export_dependencies(${dependencies} )
ament_package()