0
$\begingroup$

Rosanswers logo

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?


Originally posted by rtoris288 on ROS Answers with karma: 1173 on 2014-04-04

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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}

Originally posted by Dirk Thomas with karma: 16276 on 2014-04-04

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by rtoris288 on 2014-04-07:
Great, this will do the trick!

$\endgroup$
0
$\begingroup$

Rosanswers logo

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

Originally posted by adamconkey with karma: 642 on 2018-07-11

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.