Skip to content

Instantly share code, notes, and snippets.

@twbabyduck

twbabyduck/FindROS.cmake

Last active Jan 14, 2019
Embed
What would you like to do?
DRIVE PX2 ROS CROSS COMPILATION (Dec 05)
set(CMAKE_SYSTEM_NAME Linux)
# Specify the cross compiler
set(TOOLCHAIN "$ENV{HOME}/gcc-linaro-5.4.1-2017.05-x86_64_aarch64-linux-gnu")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN}/bin/aarch64-linux-gnu-g++")
set(CMAKE_C_COMPILER "${TOOLCHAIN}/bin/aarch64-linux-gnu-gcc")
# Targetfs path
set(ROS_SYSROOT "$ENV{HOME}/nvidia/nvidia_sdk/DRIVE/Linux/5.0.10.3/OS/DriveSDK/drive-t186ref-linux/targetfs")
set(LD_PATH "${ROS_SYSROOT}/usr/lib/aarch64-linux-gnu")
set(LD_PATH_EXTRA_1 "${ROS_SYSROOT}/lib/aarch64-linux-gnu")
set(ROSCONSOLE_BACKEND "print")
# setup compiler for cross-compilation
set(CMAKE_CXX_FLAGS "-fPIC" CACHE STRING "c++ flags")
set(CMAKE_C_FLAGS "-fPIC" CACHE STRING "c flags")
set(CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS "" CACHE STRING "module linker flags")
set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "executable linker flags")
# Where is the target environment
set(CMAKE_FIND_ROOT_PATH ${ROS_SYSROOT})
# Please, be carefull looks like "-Wl,-unresolved-symbols=ignore-in-shared-libs" can lead to silent "ld" problems
set(CMAKE_SHARED_LINKER_FLAGS "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA_1} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA_1} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA_1} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA_1} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA_1} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA_1} ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_C_FLAGS "-fPIC --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_FLAGS "-fPIC --sysroot=${CMAKE_FIND_ROOT_PATH}" CACHE INTERNAL "" FORCE)
# Search for programs only in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers only in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# set system default include dir
include_directories(BEFORE SYSTEM ${ROS_SYSROOT}/../include)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.