updated x-compile cmake files

This commit is contained in:
Robin Müller 2021-07-15 01:19:42 +02:00
parent ed772665d5
commit 684ef747ac
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 65 additions and 58 deletions

View File

@ -1,20 +1,22 @@
# BBB_ROOTFS should point to the local directory which contains all the
# LINUX_ROOTFS should point to the local directory which contains all the
# libraries and includes from the target raspi.
# The following command can be used to do this, replace <ip-address> and the
# local <rootfs-path> accordingly:
# rsync -vR --progress -rl --delete-after --safe-links pi@<ip-address>:/{lib,usr,opt/vc/lib} <rootfs-path>
# RASPBIAN_ROOTFS needs to be passed to the CMake command or defined in the
# LINUX_ROOTFS needs to be passed to the CMake command or defined in the
# application CMakeLists.txt before loading the toolchain file.
# CROSS_COMPILE also needs to be set accordingly or passed to the CMake command
if(NOT DEFINED ENV{BBB_ROOTFS})
message(FATAL_ERROR
"Define the BBB_ROOTFS variable to point to the Beagle Bone Black rootfs."
)
if(NOT DEFINED ENV{LINUX_ROOTFS})
# Sysroot has not been cached yet and was not set in environment either
if(NOT SYSROOT_PATH)
message(FATAL_ERROR
"Define the LINUX_ROOTFS variable to point to the Raspberry Pi rootfs."
)
endif()
else()
set(SYSROOT_PATH "$ENV{BBB_ROOTFS}" CACHE FILEPATH "BBB root filesystem path")
message(STATUS "Beagle Bone Black sysroot: ${SYSROOT_PATH}")
set(SYSROOT_PATH "$ENV{LINUX_ROOTFS}" CACHE PATH "Local linux root filesystem path")
message(STATUS "Raspberry Pi sysroot: ${SYSROOT_PATH}")
endif()
if(NOT DEFINED ENV{CROSS_COMPILE})
@ -31,6 +33,15 @@ else()
)
endif()
# Generally, the debian roots will be a multiarch rootfs where some libraries are put
# into a folder named "arm-linux-gnueabihf". The user can override the folder name if this is
# not the case
if(NOT ENV{MULTIARCH_FOLDER_NAME})
set(MULTIARCH_FOLDER_NAME "arm-linux-gnueabihf")
else()
set(MUTLIARCH_FOLDER_NAME $ENV{MULTIARCH_FOLDER_NAME})
endif()
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
set(CROSS_COMPILE_CC "${CROSS_COMPILE}-gcc")
@ -44,8 +55,11 @@ set(CROSS_COMPILE_OBJCOPY "${CROSS_COMPILE}-objcopy")
set(CROSS_COMPILE_SIZE "${CROSS_COMPILE}-size")
# At the very least, cross compile gcc and g++ have to be set!
find_program (CROSS_COMPILE_CC_FOUND ${CROSS_COMPILE_CC} REQUIRED)
find_program (CROSS_COMPILE_CXX_FOUND ${CROSS_COMPILE_CXX} REQUIRED)
find_program (CMAKE_C_COMPILER ${CROSS_COMPILE_CC} REQUIRED)
find_program (CMAKE_CXX_COMPILER ${CROSS_COMPILE_CXX} REQUIRED)
# Useful utilities, not strictly necessary
find_program(CMAKE_SIZE ${CROSS_COMPILE_SIZE})
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE_OBJCOPY})
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
@ -54,16 +68,12 @@ set(CMAKE_SYSROOT "${SYSROOT_PATH}")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")
# Define the compiler
set(CMAKE_C_COMPILER ${CROSS_COMPILE_CC})
set(CMAKE_CXX_COMPILER ${CROSS_COMPILE_CXX})
# List of library dirs where LD has to look. Pass them directly through gcc.
# LD_LIBRARY_PATH is not evaluated by arm-*-ld
set(LIB_DIRS
"${SYSROOT_PATH}/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/lib/${MUTLIARCH_FOLDER_NAME}"
"${SYSROOT_PATH}/usr/local/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/usr/lib/${MUTLIARCH_FOLDER_NAME}"
"${SYSROOT_PATH}/usr/lib"
)
# You can additionally check the linker paths if you add the
@ -73,11 +83,6 @@ foreach(LIB ${LIB_DIRS})
set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
endforeach()
set(CMAKE_PREFIX_PATH
"${CMAKE_PREFIX_PATH}"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
)
set(CMAKE_C_FLAGS
"-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "Flags for Beagle Bone Black"

View File

@ -1,7 +1,7 @@
# Based on https://github.com/Pro/raspi-toolchain but rewritten completely.
# Adapted for the FSFW Example
if(NOT $ENV{RASPBERRY_VERSION})
if(NOT DEFINED ENV{RASPBERRY_VERSION})
message(STATUS "Raspberry Pi version not specified, setting version 4!")
set(RASPBERRY_VERSION 4)
else()
@ -9,23 +9,25 @@ else()
endif()
# RASPBIAN_ROOTFS should point to the local directory which contains all the
# LINUX_ROOTFS should point to the local directory which contains all the
# libraries and includes from the target raspi.
# The following command can be used to do this, replace <ip-address> and the
# local <rootfs-path> accordingly:
# rsync -vR --progress -rl --delete-after --safe-links pi@<ip-address>:/{lib,usr,opt/vc/lib} <rootfs-path>
# RASPBIAN_ROOTFS needs to be passed to the CMake command or defined in the
# LINUX_ROOTFS needs to be passed to the CMake command or defined in the
# application CMakeLists.txt before loading the toolchain file.
# CROSS_COMPILE also needs to be set accordingly or passed to the CMake command
if(NOT DEFINED ENV{RASPBIAN_ROOTFS})
message(FATAL_ERROR
"Define the RASPBIAN_ROOTFS variable to "
"point to the raspbian rootfs."
)
if(NOT DEFINED ENV{LINUX_ROOTFS})
# Sysroot has not been cached yet and was not set in environment either
if(NOT SYSROOT_PATH)
message(FATAL_ERROR
"Define the LINUX_ROOTFS variable to point to the Raspberry Pi rootfs."
)
endif()
else()
set(SYSROOT_PATH "$ENV{RASPBIAN_ROOTFS}" CACHE FILEPATH "RPi root filesystem path")
set(SYSROOT_PATH "$ENV{LINUX_ROOTFS}" CACHE PATH "Local linux root filesystem path")
message(STATUS "Raspberry Pi sysroot: ${SYSROOT_PATH}")
endif()
if(NOT DEFINED ENV{CROSS_COMPILE})
@ -42,6 +44,15 @@ else()
)
endif()
# Generally, the debian roots will be a multiarch rootfs where some libraries are put
# into a folder named "arm-linux-gnueabihf". The user can override the folder name if this is
# not the case
if(NOT ENV{MULTIARCH_FOLDER_NAME})
set(MULTIARCH_FOLDER_NAME "arm-linux-gnueabihf")
else()
set(MUTLIARCH_FOLDER_NAME $ENV{MULTIARCH_FOLDER_NAME})
endif()
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
set(CROSS_COMPILE_CC "${CROSS_COMPILE}-gcc")
@ -55,8 +66,11 @@ set(CROSS_COMPILE_OBJCOPY "${CROSS_COMPILE}-objcopy")
set(CROSS_COMPILE_SIZE "${CROSS_COMPILE}-size")
# At the very least, cross compile gcc and g++ have to be set!
find_program (CROSS_COMPILE_CC_FOUND ${CROSS_COMPILE_CC} REQUIRED)
find_program (CROSS_COMPILE_CXX_FOUND ${CROSS_COMPILE_CXX} REQUIRED)
find_program (CMAKE_C_COMPILER ${CROSS_COMPILE_CC} REQUIRED)
find_program (CMAKE_CXX_COMPILER ${CROSS_COMPILE_CXX} REQUIRED)
# Useful utilities, not strictly necessary
find_program(CMAKE_SIZE ${CROSS_COMPILE_SIZE})
find_program(CMAKE_OBJCOPY ${CROSS_COMPILE_OBJCOPY})
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
@ -69,22 +83,16 @@ else()
set(CMAKE_SYSTEM_PROCESSOR "arm")
endif()
# Define the compiler
set(CMAKE_C_COMPILER ${CROSS_COMPILE_CC})
set(CMAKE_CXX_COMPILER ${CROSS_COMPILE_CXX})
# List of library dirs where LD has to look. Pass them directly through gcc.
# LD_LIBRARY_PATH is not evaluated by arm-*-ld
set(LIB_DIRS
"/opt/cross-pi-gcc/arm-linux-gnueabihf/lib"
"/opt/cross-pi-gcc/lib"
"${SYSROOT_PATH}/opt/vc/lib"
"${SYSROOT_PATH}/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/lib/${MULTIARCH_FOLDER_NAME}"
"${SYSROOT_PATH}/usr/local/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/usr/lib/${MULTIARCH_FOLDER_NAME}"
"${SYSROOT_PATH}/usr/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}/blas"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}/lapack"
"${SYSROOT_PATH}/usr/lib/${MULTIARCH_FOLDER_NAME}/blas"
"${SYSROOT_PATH}/usr/lib/${MULTIARCH_FOLDER_NAME}/lapack"
)
# You can additionally check the linker paths if you add the
# flags ' -Xlinker --verbose'
@ -93,43 +101,38 @@ foreach(LIB ${LIB_DIRS})
set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
endforeach()
set(CMAKE_PREFIX_PATH
"${CMAKE_PREFIX_PATH}"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
)
if(RASPBERRY_VERSION VERSION_GREATER 3)
set(CMAKE_C_FLAGS
"-mcpu=cortex-a72 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "CPP flags for Raspberry PI 4"
CACHE STRING "Flags for Raspberry Pi 4"
)
set(CMAKE_CXX_FLAGS
"${CMAKE_C_FLAGS}"
CACHE STRING "C flags for Raspberry PI 4"
CACHE STRING "Flags for Raspberry Pi 4"
)
elseif(RASPBERRY_VERSION VERSION_GREATER 2)
set(CMAKE_C_FLAGS
"-mcpu=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "C flags for Raspberry PI 3"
CACHE STRING "Flags for Raspberry Pi 3"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "CPP flags for Raspberry PI 3"
CACHE STRING "Flags for Raspberry Pi 3"
)
elseif(RASPBERRY_VERSION VERSION_GREATER 1)
set(CMAKE_C_FLAGS
"-mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "C flags for Raspberry PI 2"
CACHE STRING "Flags for Raspberry Pi 2"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "CPP flags for Raspberry PI 2"
CACHE STRING "Flags for Raspberry Pi 2"
)
else()
set(CMAKE_C_FLAGS
"-mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "C flags for Raspberry PI 1 B+ Zero"
CACHE STRING "Flags for Raspberry Pi 1 B+ Zero"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "CPP flags for Raspberry PI 1 B+ Zero"
CACHE STRING "Flags for Raspberry PI 1 B+ Zero"
)
endif()
@ -137,7 +140,6 @@ set(CMAKE_FIND_ROOT_PATH
"${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH};${CMAKE_SYSROOT}"
)
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories