When a new feature or deprecation is added to a C++ repo, it would be useful to have an easy way of detecting whether this feature is available.
Currently, it’s possible to use has_include (if the feature added a whole new header file), or you’re left with try_compile in CMake. Or version checks, which get very quickly very complicated.
Take for example Add imu & mag support in `tf2_sensor_msgs` (#800) by roncapat · Pull Request #813 · ros2/geometry2 · GitHub which added support for transforming IMU messages. If my package uses this feature and has a fallback for the releases where it’s missing, I need a reliable way for detecting the presence of the feature. I went with try_compile and it works.
However, imagine that tf2_sensor_msgs::tf2_sensor_msgs target automatically adds a compile definition like `-DTF2_SENSOR_MSGS_HAS_IMU_SUPPORT`. It would be much easier for downstream packages.
As long as it’s feasible, I very much want to have single-branch ROS2 packages for all distros out there, and this kind of packages would benefit a lot.
Another example: ament_index_cpp added std::filesystem interface recently. For downstream packages that want to work with both the old and new interfaces, there are some ifdefs needed in the implementation. But it doesn’t make sense to me for each package using ament_index_cpp to do the try_compile check…
What do you think about adding such feature flags to packages? Would it be maintainable? Would there be any drawbacks?