ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Best way to get distro version in CMakeLists.txt?

asked 2015-12-16 01:13:07 -0600

wkentaro gravatar image

I usually do like below to check the rosdistro. Are there better way to do like this?

# check ros distro >= indigo
execute_process(
  COMMAND python -c "import sys; sys.exit(ord('$ENV{ROS_DISTRO}'[0]) >= ord('indigo'[0]))"
  RESULT_VARIABLE DISTRO_GE_INDIGO
)
if(DISTRO_GE_INDIGO)
...
endif()
edit retag flag offensive close merge delete

Comments

2

I'm not sure whether there is a CMake macro defined anywhere. An alternative to the python one-liner might be to use rosversion -d. That returns hydro, indigo, etc.

gvdhoorn gravatar image gvdhoorn  ( 2015-12-16 03:36:19 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-05-22 17:43:05 -0600

wkentaro gravatar image

I found a better solution by comparing $ENV{ROS_DISTRO} value with STRGREATER like below:

if("$ENV{ROS_DISTRO}" STRGREATER "hydro")
...
endif()
edit flag offensive delete link more
2

answered 2016-02-03 21:45:53 -0600

Dirk Thomas gravatar image

You can access the environment variable ROS_DISTRO directly in CMake:

$ENV{ROS_DISTRO}

Regarding the greater check: your approach makes assumptions about future releases which might not be true. Therefore I would suggest a more defensive approach comparing the distro name against a list of known names and inverting the logic.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-16 01:13:07 -0600

Seen: 1,026 times

Last updated: May 22 '16