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 | Q&A answers.ros.org |
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.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2014-04-04 09:14:54 -0600
Seen: 2,819 times
Last updated: Jul 11 '18
How can i copy non-binary files into my binaries directory with catkin and cmake?
Add files to project in CMakefile
Best practice for incorporating catkin into larger CMake project?
CMakeCache overwritten by Catkin?
PkgConfig in Groovy on Quantal
catkin build configuration options
CMakeLists.txt: Install Python
CMake error while executing catkin_make on Ubuntu 14.04 with ROS Jade
Combining CMakeLists.txt of Libtorch and CMakeLists.txt of ROS package