Skip to content

Commit c0e26fb

Browse files
authored
Enable building as a native ROS package (#574)
1 parent 24927df commit c0e26fb

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
*.toml
5555
*.ubjson
5656
*.xml
57+
!package.xml
5758
*.yml
5859
*.yaml
5960

@@ -94,4 +95,4 @@ share/python-wheels/
9495
MANIFEST
9596

9697
# Docs
97-
site/
98+
site/

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ endif ()
143143

144144
project(reflectcpp VERSION 0.23.0 LANGUAGES CXX)
145145

146+
find_package(ament_cmake QUIET)
147+
146148
if (PROJECT_IS_TOP_LEVEL)
147149
set(REFLECTCPP_INSTALL ON)
148150
endif()
@@ -508,3 +510,7 @@ set(CPACK_RPM_PACKAGE_REQUIRES "")
508510

509511
include(CPack)
510512

513+
if (ament_cmake_FOUND)
514+
ament_package()
515+
endif()
516+

docs/install.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,42 @@ If you want to include all formats supported on Conan, do the following:
128128
```bash
129129
conan build . --build=missing -s compiler.cppstd=gnu20 -o *:with_cbor=True -o *:with_flatbuffers=True -o *:with_msgpack=True -o *:with_toml=True -o *:with_ubjson=True -o *:with_xml=True -o *:with_yaml=True
130130
```
131+
132+
## Option 7: Integrate as a ROS2 package
133+
134+
reflect-cpp now ships with an `ament_cmake` package manifest so it can be
135+
built directly in a ROS 2 workspace and consumed like any other
136+
CMake-config package.
137+
138+
1. Fetch the sources with `vcs` using the `.repos` file from the
139+
[tea-ros2](https://github.com/getml/tea-ros2) workspace, which already
140+
tracks `reflect-cpp`:
141+
142+
```bash
143+
mkdir -p ~/ros2_ws/src
144+
cd ~/ros2_ws
145+
# adding the entry to your vcs .repos file, or create one
146+
# reflect-cpp:
147+
# type: git
148+
# url: git@github.com:getml/reflect-cpp.git
149+
# version: main
150+
vcs import src < src/.repos
151+
```
152+
153+
2. Build the package with `colcon` (package name: `reflectcpp`). The build
154+
enables installation automatically when invoked from an ament workspace:
155+
156+
```bash
157+
colcon build --packages-select reflectcpp
158+
```
159+
160+
3. Link against reflect-cpp from your ROS 2 package via the exported CMake
161+
config.
162+
163+
```cmake
164+
find_package(reflectcpp REQUIRED)
165+
target_link_libraries(${PROJECT_NAME} reflectcpp::reflectcpp)
166+
```
167+
168+
This makes the `reflectcpp::reflectcpp` target available to your nodes
169+
while keeping the ROS build flow unchanged.

package.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>reflectcpp</name>
5+
<version>0.23.0</version>
6+
<description>C++ reflection library</description>
7+
<maintainer email="liuzicheng1987@example.com">liuzicheng1987</maintainer>
8+
<license>MIT</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<export>
13+
<build_type>ament_cmake</build_type>
14+
</export>
15+
</package>

0 commit comments

Comments
 (0)