Detect ROS version in compile time [closed]

asked 2021-03-01 07:18:21 -0500

ramonvp gravatar image

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.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by ramonvp
close date 2021-03-02 06:26:01.876179

Comments

1

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.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-01 09:53:36 -0500 )edit

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})

ramonvp gravatar image ramonvp  ( 2021-03-02 06:24:51 -0500 )edit

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)

gvdhoorn gravatar image gvdhoorn  ( 2021-03-02 06:53:07 -0500 )edit