You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix numerous inconsistencies in ament-cmake-docs w.r.t installation of linkage, and target installation (#3805)
* Fix numerous inconsistencies in ament-cmake-docs
* Nodes need a special RUNTIME directory to be recognized by ROS 2 CLI
* The order of creating the export set and using it was not intuitive
* target_link_libraries was missing linkage type which is not
recommended
* It did not show to install nodes and libraries at the same time
* The installation of headers was overly complex since the install
directory is the same for all headers
* HAS_LIBRARY_TARGET wasn't explained that it's only needed if you are
installing libraries
* Updates from review.
Signed-off-by: Ryan Friedman <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
(cherry picked from commit 42ccd72)
This adds all files in the folder ``${CMAKE_CURRENT_SOURCE_DIR}/include`` to the public interface during build time and all files in the include folder (relative to ``${CMAKE_INSTALL_DIR}``) when being installed.
87
87
@@ -98,7 +98,7 @@ As an example, suppose we want to link ``my_target`` against the linear algebra
98
98
.. code-block:: cmake
99
99
100
100
find_package(Eigen3 REQUIRED)
101
-
ament_target_dependencies(my_target Eigen3)
101
+
ament_target_dependencies(my_library PUBLIC Eigen3::Eigen)
102
102
103
103
It includes the necessary headers and libraries and their dependencies to be correctly found by the project.
104
104
It will also ensure that the include directories of all dependencies are ordered correctly when using overlay workspaces.
@@ -109,14 +109,13 @@ The recommended way in modern CMake is to only use targets, exporting and linkin
109
109
CMake targets are namespaced, similar to C++.
110
110
For instance, ``Eigen3`` defines the target ``Eigen3::Eigen``.
111
111
112
-
At least until ``Crystal Clemmys`` target names are not supported in the ``ament_target_dependencies`` macro.
113
112
Sometimes it will be necessary to call the ``target_link_libaries`` CMake function.
114
113
In the example of Eigen3, the call should then look like
115
114
116
115
.. code-block:: cmake
117
116
118
117
find_package(Eigen3 REQUIRED)
119
-
target_link_libraries(my_target Eigen3::Eigen)
118
+
target_link_libraries(my_target PUBLIC Eigen3::Eigen)
120
119
121
120
This will also include necessary headers, libraries and their dependencies, but in contrast to ``ament_target_dependencies`` it might not correctly order the dependencies when using overlay workspaces.
122
121
@@ -130,48 +129,50 @@ Building a Library
130
129
131
130
When building a reusable library, some information needs to be exported for downstream packages to easily use it.
132
131
133
-
.. code-block:: cmake
132
+
First, install the headers files which should be available to clients.
Here, we assume that the folder ``include`` contains the headers which need to be exported.
154
160
Note that it is not necessary to put all headers into a separate folder, only those that should be included by clients.
155
161
156
162
Here is what's happening in the snippet above:
157
163
158
164
- The ``ament_export_targets`` macro exports the targets for CMake.
159
-
This is necessary to allow your library's clients to use the ``target_link_libraries(client my_library::my_library)`` syntax.
160
-
``ament_export_targets`` can take an arbitrary list of targets named as ``EXPORT`` in an install call and an additional option ``HAS_LIBRARY_TARGET``, which adds potential libraries to environment variables.
165
+
This is necessary to allow your library's clients to use the ``target_link_libraries(client PRIVATE my_library::my_library)`` syntax.
166
+
If the export set includes a library, add the option ``HAS_LIBRARY_TARGET`` to ``ament_export_targets``, which adds potential libraries to environment variables.
161
167
162
168
- The ``ament_export_dependencies`` exports dependencies to downstream packages.
163
169
This is necessary so that the user of the library does not have to call ``find_package`` for those dependencies, too.
164
170
165
-
- The first ``install`` commands installs the header files which should be available to clients.
166
-
167
171
.. warning::
168
172
169
173
Calling ``ament_export_targets``, ``ament_export_dependencies``, or other ament commands from a CMake subdirectory will not work as expected.
170
174
This is because the CMake subdirectory has no way of setting necessary variables in the parent scope where ``ament_package`` is called.
171
175
172
-
- The last large install command installs the library.
173
-
Archive and library files will be exported to the lib folder, runtime binaries will be installed to the bin folder and the path to installed headers is ``include``.
174
-
175
176
.. note::
176
177
177
178
Windows DLLs are treated as runtime artifacts and installed into the ``RUNTIME DESTINATION`` folder.
0 commit comments