ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
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()