This repository provides a solution for the common challenges encountered when developing ROS2 packages: managing CMakeLists.txt
and setup.py
. If you’ve ever worked with building both Python and C++ executables, you know how tricky it can be to configure these files correctly.
We wanted to eliminate the repetitive work of manually setting up both CMakeLists.txt
for C++ and setup.py
for Python. The goal? Create a single CMakeLists.txt
file that handles everything. Whether you’re working with Python nodes, C++ nodes, or additional resources like URDFs and launch files, this CMakeLists.txt
can manage it all.
This approach allows you to focus on building your ROS2 applications without worrying about the build setup.
- Automatically detects and installs Python executables from the
scripts/
directory. - Automatically builds and installs C++ executables from the
src/
directory. - Handles all additional resources like launch files, URDFs, meshes, and config files.
- Reusable across multiple ROS2 packages with minimal changes.
- Example package included to demonstrate how to use the
CMakeLists.txt
.
Clone this repository and use the CMakeLists.txt
for your ROS2 package:
git clone https://github.com/SAKErobotics/ros2_reusable_cmakelists.git
Place this CMakeLists.txt
in the root of your ROS2 package. Ensure your package follows this structure:
your_package/
├── CMakeLists.txt # The reusable CMakeLists.txt from this repository
├── package.xml # Your package metadata
├── scripts/ # Python executables (nodes)
├── src/ # C++ source files (nodes)
├── launch/ # Optional launch files
├── urdf/ # Optional URDF files
└── config/ # Optional config files
Modify the package.xml
in your ROS2 package to include the correct package metadata and dependencies for your nodes.
Build your package using colcon
:
colcon build
Source the workspace:
source install/setup.bash
Run your nodes:
- For Python nodes:
ros2 run your_package your_python_node
- For C++ nodes:
ros2 run your_package your_cpp_node
An example ROS2 package is provided in the example_package/
directory that demonstrates how to use the CMakeLists.txt
. You can explore this example for guidance.
This project is licensed under the MIT License. See the LICENSE
file for more details.
Feel free to submit issues or pull requests if you find any bugs or have suggestions for improvements!