Where to install ROS 2 node CMake executables with GNUInstallDirs
I am trying to create a simple ROS package, while following the "latest" advice on installs to use GNUInstallDirs for a humble
package.
https://youtu.be/m0DwB4OvDXk?t=2057
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
https://cmake.org/cmake/help/latest/command/install.html#command:install
From the CMake docs on the install command:
For regular executables, static libraries and shared libraries, the DESTINATION argument is not required. For these target types, when DESTINATION is omitted, a default destination will be taken from the appropriate variable from GNUInstallDirs, or set to a built-in default value if that variable is not defined.
However, in the ament docs, GNUInstallDirs is not used. https://docs.ros.org/en/humble/How-To-Guides/Ament-CMake-Documentation.html#building-a-library
For example, a simple example of a ROS node executable, here is the CMake code
project(foo)
add_executable(${PROJECT_NAME}_exe main.cpp) # my ROS 2 node
include(GNUInstallDirs)
install(
TARGETS ${CMAKE_PROJECT_NAME}_exe
EXPORT export_${CMAKE_PROJECT_NAME}
# DESTINATION lib/${PROJECT_NAME} # When commented out, ros2 run cannot find the executable
)
# ament_export_targets and ament_export_dependencies would go here but are omitted for brevity.
The CMake docs say I don't need a DESTINATION keyword, however, it seems ROS requires me to install my executable into a nonstandard location than what GNUInstallDirs provides for executables, which is bin
instead of lib
. If I don't, the executables don't show up with ros2 run foo foo_exe
or ros2 pkg executables foo
. Normally in CMake, lib
is for the .lib
and .so
libraries created with add_library
, while bin
is for targets created with add_executable
.
Is there a reason ROS 2 is requiring users to put their executables in a nonstandard location counter to what GNUInstallDirs sets as a default?
Asked by ryanf55 on 2023-06-13 15:08:24 UTC
Answers
Upon further research, I've filed a bug upstream: https://github.com/ros2/ros2cli/issues/845
Asked by ryanf55 on 2023-07-26 16:00:50 UTC
Comments