Check ROS Version in CMake File with Catkin
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?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
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?
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):
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()
Not the version of the package but the version of ROS: jade, kinetic, lunar
I believe my answer is addressing your interpretation of ROS version @mhallak.
Asked: 2014-04-04 09:14:54 -0600
Seen: 3,404 times
Last updated: Jul 11 '18