The REP 149 which specifies format 3 of package.xml
files addresses exactly this use case.
The assumption is that a ROS package which want to support both major ROS versions will have consistent header information (name, version, license, maintainer, etc.) and only diverges in dependencies (e.g. in ROS 1 using roscpp
, in ROS 2 using rclcpp
).
The new condition attribute on dependency tags allows you to express that:
<depend condition="$ROS_VERSION == 1">roscpp</depend>
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
The environment variable ROS_VERSION
is provided by the new package ros_environment package which is available as of ROS Kinetic as well as ROS Ardent