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

Check ROS Version in CMake File with Catkin

asked 2014-04-04 09:14:54 -0600

rtoris288 gravatar image

updated 2016-10-24 09:02:10 -0600

ngrennan gravatar image

Is there a way to check the version of ROS being used in the CMakeLists.txt file? i.e., are there any variables or macros to query the version?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2014-04-04 13:46:25 -0600

Dirk Thomas gravatar image

updated 2014-04-04 13:46:53 -0600

The question is what you mean with "ROS version".

Each package has its own version number and they level independently. After calling find_package() to find a catkin package foo you can access the version variables for it (as it is recommended CMake standard):

  • ${foo_VERSION}
  • ${roscpp_VERSION_MAJOR}
  • ${roscpp_VERSION_MINOR}
  • ${roscpp_VERSION_PATCH}
edit flag offensive delete link more

Comments

Great, this will do the trick!

rtoris288 gravatar image rtoris288  ( 2014-04-07 02:01:29 -0600 )edit
2

answered 2018-07-11 15:28:42 -0600

If you want to know the distro (e.g. kinetic, lunar etc.), you can check the ROS_DISTRO environment variable, and similar to this file: you can try to look for the ROS header file if the environment variable wasn't set:

set(ROS_FOUND FALSE)
if(DEFINED ENV{ROS_DISTRO})
  set(FOUND_ROS_DISTRO $ENV{ROS_DISTRO})
  set(ROS_FOUND TRUE)
else()
  message("ROS distro variable not set. Trying to figure it out...")
  set(AVAILABLE_ROS_VERSIONS "melodic;lunar;kinetic;jade;indigo")
  set(ROS_FOUND FALSE)
  foreach(version ${AVAILABLE_ROS_VERSIONS})
    if(NOT ROS_FOUND)
      find_path(ROS_H ros.h PATHS /opt/ros/${version}/include/ros)
      if(ROS_H)
        message("Found ros version ${version}")
        set(FOUND_ROS_DISTRO ${version})
        set(ROS_FOUND TRUE)
      endif()
    endif()
  endforeach()
endif()

if(ROS_FOUND)
  if($ENV{ROS_DISTRO} STREQUAL "melodic")
    message("Using ROS Kinetic")
    # Do stuff specific to Kinetic
  elseif($ENV{ROS_DISTRO} STREQUAL "lunar")
    message("Using ROS Lunar")
    # Do stuff specific to Lunar

  # ... check other versions ...

  else()
    message("Unknown ROS distro:")
    message($ENV{ROS_DISTRO})
  endif()
else()
  message("ROS distro is unknown.")
endif()
edit flag offensive delete link more
0

answered 2018-06-28 05:33:59 -0600

mhallak gravatar image

Not the version of the package but the version of ROS: jade, kinetic, lunar

edit flag offensive delete link more

Comments

1

Is this a question? If so, please post a new one.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-28 06:51:44 -0600 )edit

I believe my answer is addressing your interpretation of ROS version @mhallak.

adamconkey gravatar image adamconkey  ( 2018-07-11 15:30:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-04-04 09:14:54 -0600

Seen: 3,404 times

Last updated: Jul 11 '18