diff --git a/.gitignore b/.gitignore index 91479bda..43aa36d0 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ *.toml *.ubjson *.xml +!package.xml *.yml *.yaml @@ -94,4 +95,4 @@ share/python-wheels/ MANIFEST # Docs -site/ \ No newline at end of file +site/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 193f9f47..71c8ce2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,8 @@ endif () project(reflectcpp VERSION 0.23.0 LANGUAGES CXX) +find_package(ament_cmake QUIET) + if (PROJECT_IS_TOP_LEVEL) set(REFLECTCPP_INSTALL ON) endif() @@ -508,3 +510,7 @@ set(CPACK_RPM_PACKAGE_REQUIRES "") include(CPack) +if (ament_cmake_FOUND) + ament_package() +endif() + diff --git a/docs/install.md b/docs/install.md index ef099db3..daba7af2 100644 --- a/docs/install.md +++ b/docs/install.md @@ -128,3 +128,42 @@ If you want to include all formats supported on Conan, do the following: ```bash 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 ``` + +## Option 7: Integrate as a ROS2 package + +reflect-cpp now ships with an `ament_cmake` package manifest so it can be +built directly in a ROS 2 workspace and consumed like any other +CMake-config package. + +1. Fetch the sources with `vcs` using the `.repos` file from the + [tea-ros2](https://github.com/getml/tea-ros2) workspace, which already + tracks `reflect-cpp`: + + ```bash + mkdir -p ~/ros2_ws/src + cd ~/ros2_ws + # adding the entry to your vcs .repos file, or create one + # reflect-cpp: + # type: git + # url: git@github.com:getml/reflect-cpp.git + # version: main + vcs import src < src/.repos + ``` + +2. Build the package with `colcon` (package name: `reflectcpp`). The build + enables installation automatically when invoked from an ament workspace: + + ```bash + colcon build --packages-select reflectcpp + ``` + +3. Link against reflect-cpp from your ROS 2 package via the exported CMake + config. + + ```cmake + find_package(reflectcpp REQUIRED) + target_link_libraries(${PROJECT_NAME} reflectcpp::reflectcpp) + ``` + + This makes the `reflectcpp::reflectcpp` target available to your nodes + while keeping the ROS build flow unchanged. diff --git a/package.xml b/package.xml new file mode 100644 index 00000000..b2960e8d --- /dev/null +++ b/package.xml @@ -0,0 +1,15 @@ + + + + reflectcpp + 0.23.0 + C++ reflection library + liuzicheng1987 + MIT + + ament_cmake + + + ament_cmake + +