Skip to content

Commit

Permalink
Fix rosidl_generator_py assuming incorect library names (#149)
Browse files Browse the repository at this point in the history
rosidl_generator_py was assuming all interface packages being depended
upon call their interface generation target name "${PROJECT_NAME}", but
that's an incorrect assumption. The target name is a required argument
to rosidl_generate_interfaces. This fixes it by exporting the python
library target using an existing CMake macro for that purpose called
rosidl_export_typesupport_targets() and amen_export_targets()

I works by adding a variable
"${PROJECT_NAME}_TARGETS__rosidl_generator_py" which is set when the
interface package is `find_package()`d. That variable contains the
targets generated by `rosidl_generator_py` so that downstream interface
packages can depend on it.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz authored Jan 11, 2022
1 parent fb0eade commit 0f43ffc
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ macro(set_lib_properties _build_type)
RUNTIME_OUTPUT_DIRECTORY${_build_type} ${_output_path})
endmacro()

set(_target_name_lib "${rosidl_generate_interfaces_TARGET}__python")
# Export target so downstream interface packages can link to it
set(rosidl_generator_py_suffix "__rosidl_generator_py")

set(_target_name_lib "${rosidl_generate_interfaces_TARGET}${rosidl_generator_py_suffix}")
add_library(${_target_name_lib} SHARED ${_generated_c_files})
target_link_libraries(${_target_name_lib}
${rosidl_generate_interfaces_TARGET}__rosidl_generator_c)
Expand All @@ -174,7 +177,7 @@ target_link_libraries(
${PythonExtra_LIBRARIES}
)
target_include_directories(${_target_name_lib}
PUBLIC
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_c
${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py
${PythonExtra_INCLUDE_DIRS}
Expand Down Expand Up @@ -283,17 +286,9 @@ endforeach()

set(PYTHON_EXECUTABLE ${_PYTHON_EXECUTABLE})

# Depend on rosidl_generator_py generated targets from our dependencies
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
set(_pkg_install_base "${${_pkg_name}_DIR}/../../..")
set(_pkg_python_libname "${_pkg_name}__python")

if(WIN32)
target_link_libraries(${_target_name_lib} "${_pkg_install_base}/Lib/${_pkg_python_libname}.lib")
elseif(APPLE)
target_link_libraries(${_target_name_lib} "${_pkg_install_base}/lib/lib${_pkg_python_libname}.dylib")
else()
target_link_libraries(${_target_name_lib} "${_pkg_install_base}/lib/lib${_pkg_python_libname}.so")
endif()
target_link_libraries(${_target_name_lib} ${${_pkg_name}_TARGETS${rosidl_generator_py_suffix}})
endforeach()

set_lib_properties("")
Expand All @@ -305,9 +300,14 @@ if(WIN32)
endif()
if(NOT rosidl_generate_interfaces_SKIP_INSTALL)
install(TARGETS ${_target_name_lib}
EXPORT export_${_target_name_lib}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

# Export this target so downstream interface packages can depend on it
rosidl_export_typesupport_targets("${rosidl_generator_py_suffix}" "${_target_name_lib}")
ament_export_targets(export_${_target_name_lib})
endif()

if(BUILD_TESTING AND rosidl_generate_interfaces_ADD_LINTER_TESTS)
Expand Down

0 comments on commit 0f43ffc

Please sign in to comment.