Detect ROS version in compile time [closed]
Hi all, I am looking for a very simple question, but I can't find any other post about this topic, so I'm hoping someone can help me:
How can I detect in compile time which ROS distro I am running on? Ideally, I would like to have something like:
#ifdef MELODIC
#include "my_header_melodic.h"
#elif NOETIC
#include "my_header_noetic.h"
#endif
I am now doing this by hand forcing it in my CMakelists.txt with a add_definitions(-DNOETIC) or -DMELODIC, but I would like ideally to be this automatic.
Thank you in advance,
R.
I believe this is a duplicate of (at least) #q9562. For the CMake side: #q148831 (see the accepted answer).
Please see whether that helps, and if it does, please close your question as a duplicate.
Thanks, #q148831 was exactly what I was looking for! The way I'm using it is simply passing it on as a compiler flag: add_definitions(-D$ENV{ROS_DISTRO})
that wasn't exactly what I was thinking, but if you're happy, I'm happy.
(comparing versions will always be better than comparing for the existence of particular names)