Skip to content

Commit 27015cc

Browse files
mergify[bot]christophfroehlichahcorde
authored
Update Pluginlib.rst (backport #5894) (#5899)
* Update Pluginlib.rst (#5894) Signed-off-by: Christoph Fröhlich <[email protected]> (cherry picked from commit c87aa57) Signed-off-by: Alejandro Hernandez Cordero <[email protected]> Co-authored-by: Christoph Fröhlich <[email protected]> Co-authored-by: Alejandro Hernandez Cordero <[email protected]>
1 parent 7337fe5 commit 27015cc

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

source/Tutorials/Beginner-Client-Libraries/Pluginlib.rst

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,53 @@ The code above creates an abstract class called ``RegularPolygon``.
7373
One thing to notice is the presence of the initialize method.
7474
With ``pluginlib``, a constructor without parameters is required, so if any parameters to the class are needed, we use the initialize method to pass them to the object.
7575

76-
We need to make this header available to other classes, so open ``ros2_ws/src/polygon_base/CMakeLists.txt`` for editing.
77-
Add the following lines after the ``ament_target_dependencies`` command:
76+
We need to make this header available to other classes by exporting it as an interface library.
77+
To do so, open ``~/ros2_ws/src/polygon_base/CMakeLists.txt`` for editing
78+
and add the following lines after the ``find_package(pluginlib REQUIRED)`` command:
7879

7980
.. code-block:: cmake
8081
81-
install(
82-
DIRECTORY include/
83-
DESTINATION include
82+
# Library (this will be used as the base class for plugins)
83+
add_library(${PROJECT_NAME} INTERFACE)
84+
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
85+
target_compile_features(${PROJECT_NAME} INTERFACE c_std_99 cxx_std_17)
86+
target_include_directories(${PROJECT_NAME} INTERFACE
87+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
88+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
8489
)
90+
target_link_libraries(${PROJECT_NAME} ${pluginlib_TARGETS})
8591
86-
And add this command before the ``ament_package`` command:
92+
# Install headers
93+
install(DIRECTORY include/
94+
DESTINATION include/${PROJECT_NAME}
95+
)
96+
97+
# Install library and export targets
98+
install(TARGETS ${PROJECT_NAME}
99+
EXPORT export_${PROJECT_NAME}
100+
ARCHIVE DESTINATION lib
101+
LIBRARY DESTINATION lib
102+
RUNTIME DESTINATION bin
103+
)
104+
install(EXPORT export_${PROJECT_NAME}
105+
NAMESPACE ${PROJECT_NAME}::
106+
DESTINATION share/${PROJECT_NAME}/cmake
107+
)
108+
109+
And add this commands before the ``ament_package`` command:
87110

88111
.. code-block:: cmake
89112
113+
# Export old-style CMake variables
90114
ament_export_include_directories(
91115
include
92116
)
93117
118+
# Export modern CMake targets
119+
ament_export_targets(
120+
export_${PROJECT_NAME}
121+
)
122+
94123
We will return to this package later to write our test node.
95124

96125
2 Create the Plugin Package

0 commit comments

Comments
 (0)