Ask Your Question
2

Best way to get distro version in CMakeLists.txt?

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

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 imagegvdhoorn ( 2015-12-16 03:36:19 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

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

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 -0500

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 417 times

Last updated: May 22 '16