Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake export a target that is using rosidl_target_interfaces. #545

Closed
MaximilienNaveau opened this issue Nov 5, 2020 · 2 comments
Closed

Comments

@MaximilienNaveau
Copy link

MaximilienNaveau commented Nov 5, 2020

Bug report

Required Info:

  • Operating System:
    • Ubuntu 18.04 / RT_PREEMPT
  • Installation type:
    • ROS eloquent binaries
  • Version or commit hash:
    • unknown?
  • DDS implementation:
    • unknown?
  • Client library (if applicable):
    • rclcpp, rosidl_default_generators

Steps to reproduce issue

CMakeLists.txt

...

find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}_msg_srv "msg/MyMessage.msg")
...
add_library(mylib SHARED my_cpp_file.cpp)
target_include_directories(
  mylib PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
               $<INSTALL_INTERFACE:include>)
rosidl_target_interfaces(mylib ${PROJECT_NAME}_msg_srv "rosidl_typesupport_cpp")
...
# install and export
ament_export_interfaces(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
install(
  TARGETS mylib
  EXPORT export_${PROJECT_NAME}
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
  INCLUDES
  DESTINATION include)

Expected behavior

Successfull build.

Actual behavior

CMake Error in src/CMakeLists.txt:
  Target "my_package" INTERFACE_INCLUDE_DIRECTORIES property
  contains path:

    "<full_path_to>/workspace_ros2/build/my_package/rosidl_generator_cpp"

  which is prefixed in the build directory.

Additional information

I do think the problem comes from here: https://github.com/ros2/rosidl/blob/eloquent/rosidl_cmake/cmake/rosidl_target_interfaces.cmake#L52

This:

target_include_directories(${target} PUBLIC ${include_directories})

should become this:

target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${include_directories}>)

Or maybe I am not using these tools properly...

@sloretz
Copy link
Contributor

sloretz commented Dec 7, 2021

The function rosidl_target_interfaces() is being deprecated in the next release in favor of a new function rosidl_get_typesupport_target(). I don't think that will be backported to ROS Eloquent, but it's very easy to copy what it does - adds two underscores between the generation target name and the type support name.

function(rosidl_get_typesupport_target var generate_interfaces_target typesupport_name)
if(NOT TARGET ${generate_interfaces_target})
message(FATAL_ERROR
"${generate_interfaces_target} is not a CMake target. Maybe rosidl_generate_interfaces was given a different target name?")
endif()
set(output_target "${generate_interfaces_target}__${typesupport_name}")
if(NOT TARGET ${output_target})
message(FATAL_ERROR "${output_target} is not a CMake target - maybe the typesupport '${typesupport_name}' doesn't exist?")
endif()
set("${var}" "${output_target}" PARENT_SCOPE)
endfunction()

A solution might look like this:

rosidl_generate_interfaces(${PROJECT_NAME}_msg_srv "msg/MyMessage.msg")
...
add_library(mylib SHARED my_cpp_file.cpp)
...
target_link_libraries(mylib PUBLIC "${PROJECT_NAME}_msg_srv__rosidl_typesupport_cpp")

ros2/ros2_documentation#1798

I'll close this since ROS Eloquent is EOL and the problematic function is already deprecated in future ROS releases

@sloretz sloretz closed this as completed Dec 7, 2021
@MaximilienNaveau
Copy link
Author

Thank you very much for the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants