Robotics StackExchange | Archived questions

Crosscompiling ROS into relocatable code

Hi,

I am currently working on cross-compiling the ROS dependencies I need for a project for a Raspberry Pi 3. After a bit of work I got it working. I install to the default location and later build a .deb package which copies the code to /opt/ros/kinetic on the target system.

My problem is that the generated files, specificly the -config.cmake files, contain references to directories in the installation-path. I don't know how to avoid this, since I cannot set the install-path to the correct location (it's not writable for me) so that I need to use an intermediate directory. I thought about using the DESTDIR environment variable or the CMAKESTAGINPREFIX but I don't know which would be the correct one or whether catkin adheres these variables. Any help is very welcome!

I crosscompile by simply passing this toolchain file to catkin:

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR armv7l)

SET(CMAKE_C_COMPILER ${RASPI_TOOLCHAIN}/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${RASPI_TOOLCHAIN}/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_FIND_ROOT_PATH ${RASPI_ROOTFS})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_SYSROOT ${CMAKE_FIND_ROOT_PATH})

# Workarounds:
# Not populated automaticaly
SET(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)

# rootfs/usr/include/arm-linux-gnueabihf not included
INCLUDE_DIRECTORIES(SYSTEM ${CMAKE_FIND_ROOT_PATH}/usr/include/arm-linux-gnueabihf)

# Compilerselftest fails, rootfs/usr/lib/arm-linux-gnueabihf is not linked against, only 
# Symlink from rootfs/usr/lib/arm-linux-gnueabihf/4.9.3 to rootfs/usr/lib/arm-linux-gnueabihf

# /usr/lib/arm-linux-gnueabif instead of rootfs/usr/lib/arm-linux-gnueabif is added to the rpath for some packages
#   -> happens when sysroot is prefix of runtime-dir: https://github.com/Kitware/CMake/blob/master/Source/cmComputeLinkInformation.cxx#L1753
# rootfs/lib/arm-linux-gnueabihf is not present in the rpath
set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-Wl,-rpath,${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf:${CMAKE_FIND_ROOT_PATH}/usr/lib/arm-linux-gnueabihf:" CACHE STRING "" FORCE)
set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG "-Wl,-rpath,${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf:${CMAKE_FIND_ROOT_PATH}/usr/lib/arm-linux-gnueabihf:" CACHE STRING "" FORCE)

# console_bridge & urdfdom returns /usr/include as <name>_INCLUDE_DIRS (https://github.com/ros/console_bridge/issues/44)
# Use modified find{console_bridge,urdfdom}.cmake (find_path)
# GTest adds host /usr/include to include directories
# remove NO_CMAKE_FIND_ROOT_PATH from find_path calls in src/catkin/cmake/tests/gtest.cmake

# pkg config looks up packages on the hostsystem
set(ENV{PKG_CONFIG_DIR} )
set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_FIND_ROOT_PATH}/usr/lib/pkgconfig:${CMAKE_FIND_ROOT_PATH}/usr/share/pkgconfig")
set(ENV{PKG_CONFIG_SYSROOT} "${CMAKE_FIND_ROOT_PATH}")

I was thinking about using the DESTDIR environment variable or CMAKESTAGINGPREFIX to make the generated code relocatable but I am not sure which is the right one to use or whether they work with catkin.

Asked by antipattern on 2017-04-28 16:40:33 UTC

Comments

I'm not sure about CMAKE_STAGING_PREFIX but I know people have used DESTDIR with catkin before because we had to fix some things in the tools in order to support it.

Asked by William on 2017-04-28 16:43:10 UTC

In general the generated <package>-config.cmake files should not contain absolute paths. Can you please add the information for which packages that is the case.

Asked by Dirk Thomas on 2017-04-28 16:47:41 UTC

I tried using DESTDIR which fixed some of my issues. There is still a lot of files which contain the absolute install-directory. Most of it is commented out, but the generated CMake configs use it for the library-lookup: http://sprunge.us/JfVc

Asked by antipattern on 2017-05-05 04:07:21 UTC

Please mention specific files with specific content for others to be able to help. "still a lot of files which contain the absolute install-directory" makes it difficult to give you any feedback. I also don't know that the referenced "library-lookup" snippet is about. Maybe you can clarify.

Asked by Dirk Thomas on 2017-05-09 13:57:13 UTC

For example, the generated roscppConfig.cmake contains absolute paths referring to my rootfs (CMAKE_SYSROOT) and the workspace I am building in: http://sprunge.us/QYff. I replaced the paths by ROOTFS and WORKSPACE. The install-prefix is set to /opt/ros/kinetic and the DESTDIR is install_isolated.

Asked by antipattern on 2017-05-10 12:50:34 UTC

Answers