added cmake scripts

This commit is contained in:
Robin Müller 2021-06-11 12:51:20 +02:00
parent 63c7c6e5af
commit 3a3a3f476c
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
18 changed files with 1219 additions and 0 deletions

View File

@ -0,0 +1,98 @@
# BBB_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
# 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."
)
else()
set(SYSROOT_PATH "$ENV{BBB_ROOTFS}" CACHE PATH "BBB root filesystem path")
message(STATUS "Beagle Bone Black sysroot: ${SYSROOT_PATH}")
endif()
if(NOT DEFINED ENV{CROSS_COMPILE})
set(CROSS_COMPILE "arm-linux-gnueabihf")
message(STATUS
"No CROSS_COMPILE environmental variable set, using default ARM linux "
"cross compiler name ${CROSS_COMPILE}"
)
else()
set(CROSS_COMPILE "$ENV{CROSS_COMPILE}")
message(STATUS
"Using environmental variable CROSS_COMPILE as cross-compiler: "
"$ENV{CROSS_COMPILE}"
)
endif()
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
set(CROSS_COMPILE_CC "${CROSS_COMPILE}-gcc")
set(CROSS_COMPILE_CXX "${CROSS_COMPILE}-g++")
set(CROSS_COMPILE_LD "${CROSS_COMPILE}-ld")
set(CROSS_COMPILE_AR "${CROSS_COMPILE}-ar")
set(CROSS_COMPILE_RANLIB "${CROSS_COMPILE}-ranlib")
set(CROSS_COMPILE_STRIP "${CROSS_COMPILE}-strip")
set(CROSS_COMPILE_NM "${CROSS_COMPILE}-nm")
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)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
# Define name of the target system
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}/usr/local/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/usr/lib"
)
# You can additionally check the linker paths if you add the
# flags ' -Xlinker --verbose'
set(COMMON_FLAGS "-I${SYSROOT_PATH}/usr/include")
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"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "Flags for Beagle Bone Black"
)
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
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

45
cmake/BuildType.cmake Normal file
View File

@ -0,0 +1,45 @@
function(set_build_type)
message(STATUS "Used build generator: ${CMAKE_GENERATOR}")
# Set a default build type if none was specified
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(DEFAULT_BUILD_TYPE "Debug")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS
"Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified."
)
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo"
)
endif()
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
message(STATUS
"Building Debug application with flags: ${CMAKE_C_FLAGS_DEBUG}"
)
elseif(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo")
message(STATUS
"Building Release (Debug) application with "
"flags: ${CMAKE_C_FLAGS_RELWITHDEBINFO}"
)
elseif(${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel")
message(STATUS
"Building Release (Size) application with "
"flags: ${CMAKE_C_FLAGS_MINSIZEREL}"
)
else()
message(STATUS
"Building Release (Speed) application with "
"flags: ${CMAKE_C_FLAGS_RELEASE}"
)
endif()
endfunction()

View File

@ -0,0 +1,84 @@
function(post_source_hw_os_config)
if(${TGT_BSP} MATCHES "arm/stm32h743zi-nucleo")
if(${OS_FSFW} MATCHES "freertos")
if(ADD_LWIP_STACK)
message(STATUS "Linking against ${LIB_LWIP_NAME} lwIP library")
if(LIB_LWIP_NAME)
target_link_libraries(${TARGET_NAME} PUBLIC
${LIB_LWIP_NAME}
)
else()
message(WARNING "lwIP library name not set!")
endif()
endif()
if(LINK_HAL)
message(STATUS "Linking against ${LIB_HAL_NAME} HAL library")
if(LIB_HAL_NAME)
target_link_libraries(${TARGET_NAME} PUBLIC
${LIB_HAL_NAME}
)
else()
message(WARNING "HAL library name not set!")
endif()
endif()
elseif(${OS_FSFW} MATCHES "rtems")
if(ADD_LWIP_STACK)
message(STATUS "Linking against ${LIB_LWIP_NAME} lwIP library")
if(LIB_LWIP_NAME)
target_link_libraries(${TARGET_NAME} PUBLIC
${LIB_LWIP_NAME}
)
else()
message(WARNING "lwIP library name not set!")
endif()
endif()
include("${RTEMS_CONFIG_DIR}/RTEMSPostProjectConfig.cmake")
rtems_post_project_config(${TARGET_NAME})
endif()
endif()
if(LINKER_SCRIPT)
target_link_options(${TARGET_NAME} PRIVATE
-T${LINKER_SCRIPT}
)
endif()
set(C_FLAGS "" CACHE INTERNAL "C flags")
set(C_DEFS ""
CACHE INTERNAL
"C Defines"
)
set(CXX_FLAGS ${C_FLAGS})
set(CXX_DEFS ${C_DEFS})
if(CMAKE_VERBOSE)
message(STATUS "C Flags: ${C_FLAGS}")
message(STATUS "CXX Flags: ${CXX_FLAGS}")
message(STATUS "C Defs: ${C_DEFS}")
message(STATUS "CXX Defs: ${CXX_DEFS}")
endif()
# Generator expression. Can be used to set different C, CXX and ASM flags.
target_compile_options(${TARGET_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:C>:${C_DEFS} ${C_FLAGS}>
$<$<COMPILE_LANGUAGE:CXX>:${CXX_DEFS} ${CXX_FLAGS}>
$<$<COMPILE_LANGUAGE:ASM>:${ASM_FLAGS}>
)
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND echo Generating binary file ${CMAKE_PROJECT_NAME}.bin..
COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET_NAME} ${TARGET_NAME}.bin
)
endfunction()

View File

@ -0,0 +1,179 @@
function(pre_source_hw_os_config)
# FreeRTOS
if(${OS_FSFW} MATCHES freertos)
add_definitions(-DFREERTOS)
# RTEMS
elseif(${OS_FSFW} STREQUAL rtems)
add_definitions(-DRTEMS)
elseif(${OS_FSFW} STREQUAL linux)
add_definitions(-DUNIX -DLINUX)
find_package(Threads REQUIRED)
set(BSP_PATH "bsp_linux")
# Hosted
else()
set(BSP_PATH "bsp_hosted")
if(WIN32)
add_definitions(-DWIN32)
elseif(UNIX)
find_package(Threads REQUIRED)
add_definitions(-DUNIX -DLINUX)
endif()
endif()
# Cross-compile information
if(CMAKE_CROSSCOMPILING)
# set(CMAKE_VERBOSE TRUE)
message(STATUS "Cross-compiling for ${TGT_BSP} target")
message(STATUS "Cross-compile gcc: ${CMAKE_C_COMPILER}")
message(STATUS "Cross-compile g++: ${CMAKE_CXX_COMPILER}")
if(CMAKE_VERBOSE)
message(STATUS "Cross-compile linker: ${CMAKE_LINKER}")
message(STATUS "Cross-compile size utility: ${CMAKE_SIZE}")
message(STATUS "Cross-compile objcopy utility: ${CMAKE_OBJCOPY}")
message(STATUS "Cross-compile ranlib utility: ${CMAKE_RANLIB}")
message(STATUS "Cross-compile ar utility: ${CMAKE_AR}")
message(STATUS "Cross-compile nm utility: ${CMAKE_NM}")
message(STATUS "Cross-compile strip utility: ${CMAKE_STRIP}")
message(STATUS
"Cross-compile assembler: ${CMAKE_ASM_COMPILER} "
"-x assembler-with-cpp"
)
message(STATUS "ABI flags: ${ABI_FLAGS}")
message(STATUS "Custom linker script: ${LINKER_SCRIPT}")
endif()
set_property(CACHE TGT_BSP
PROPERTY STRINGS
"arm/stm32h743zi-nucleo" "arm/raspberrypi"
)
endif()
if(${TGT_BSP} MATCHES "arm/stm32h743zi-nucleo")
add_definitions(-DSTM32H743ZI_NUCLEO)
if(${OS_FSFW} MATCHES freertos)
option(ADD_LWIP_STACK "Add LwIP stack for application" ON)
set(LIB_OS_NAME "freertos" CACHE STRING "OS FSFW library name")
set(BSP_PATH "bsp_stm32_freertos")
set(BOARD_CONFIG_PATH
"${BSP_PATH}/STM32CubeH7/Boards/NUCLEO-H743ZI/Inc"
CACHE STRING
"Board configuration include path."
)
set(MIDDLEWARES_PATH
"${BSP_PATH}/STM32CubeH7/Middlewares"
)
set(CMSIS_INC_PATH
"${BSP_PATH}/STM32CubeH7/Drivers/CMSIS/Include"
CACHE STRING
"CMSIS include path"
)
set(FREERTOS_GENERIC_PORT_PATH
"${MIDDLEWARES_PATH}/Third_Party/FreeRTOS"
)
set(FREERTOS_PORT_PATH
"${FREERTOS_GENERIC_PORT_PATH}/portable/GCC/ARM_CM7/r0p1"
)
set(FREERTOS_CONFIG_AND_PORT_PATHS
"${FREERTOS_PORT_PATH}"
"${BOARD_CONFIG_PATH}"
"${CMSIS_INC_PATH}"
CACHE STRING
"FreeRTOS configuration and port paths."
)
set(FREERTOS_PORT_SOURCES
${FREERTOS_PORT_PATH}/port.c
CACHE INTERNAL
"FreeRTOS port sources"
)
set(LIB_STM_HAL_NAME "stm_hal" CACHE STRING "STM32 HAL library name")
set(LIB_HAL_NAME ${LIB_STM_HAL_NAME} PARENT_SCOPE)
set(LINK_HAL TRUE PARENT_SCOPE)
set(STM_HAL_CONFIG_PATH
"${BOARD_CONFIG_PATH}"
CACHE INTERNAL
"STM HAL config path."
)
set(STM_HAL_DEFINES
"USE_HAL_DRIVER"
"STM32H743xx"
CACHE INTERNAL
"HAL defines for target machine"
)
set(FSFW_HAL_DEFINES
${STM_HAL_DEFINES}
CACHE INTERNAL
"Defines for FSFW HAL"
)
set(FSFW_HAL_LINK_LIBS
${LIB_OS_NAME}
${LIB_STM_HAL_NAME}
CACHE INTERNAL
"Link FSFW HAL against OS"
)
set(LINKER_SCRIPT_PATH "${BSP_PATH}/STM32CubeH7/Boards/NUCLEO-H743ZI")
set(LINKER_SCRIPT_NAME "STM32H743ZITx_FLASH.ld")
get_filename_component(LINKER_SCRIPT
${LINKER_SCRIPT_PATH}/${LINKER_SCRIPT_NAME}
REALPATH BASE_DIR ${CMAKE_SOURCE_DIR}
)
set(LINKER_SCRIPT ${LINKER_SCRIPT} CACHE STRING "Custom linker script")
if(ADD_LWIP_STACK)
set(LWIP_CONFIG_PATH
"${BOARD_CONFIG_PATH}"
CACHE INTERNAL
"lwIP configuration include path"
)
set(LIB_LWIP_NAME "lwip" CACHE STRING "lwIP library name")
endif()
elseif(${OS_FSFW} MATCHES rtems)
option(ADD_LWIP_STACK "Add LwIP stack for application" ON)
set(BSP_PATH "bsp_stm32_rtems")
set(BOARD_CONFIG_PATH "${BSP_PATH}/boardconfig")
if(ADD_LWIP_STACK)
set(LWIP_CONFIG_PATH
"${BOARD_CONFIG_PATH}"
CACHE INTERNAL
"lwIP configuration include path"
)
set(LIB_LWIP_NAME "lwip" CACHE STRING "lwIP library name")
endif()
endif() # ${OS_FSFW} MATCHES XYZ
elseif(${TGT_BSP} MATCHES "arm/raspberrypi")
add_definitions(-DRASPBERRY_PI)
elseif(${TGT_BSP} MATCHES "arm/beagleboneblack")
add_definitions(-DBEAGLE_BONE_BLACK)
elseif(${TGT_BSP} MATCHES "host/none")
option(ADD_LWIP_STACK "Add LwIP stack for application" OFF)
else()
option(ADD_LWIP_STACK "Add LwIP stack for application" OFF)
if(TGT_BSP)
message(WARNING "CMake not configured for this target!")
message(FATAL_ERROR "Target: ${TGT_BSP}!")
endif()
endif()
set(BSP_PATH ${BSP_PATH} PARENT_SCOPE)
endfunction()

View File

@ -0,0 +1,131 @@
function(pre_project_config)
# Basic input sanitization
if(DEFINED TGT_BSP)
if(${TGT_BSP} MATCHES "arm/raspberrypi" AND NOT ${OS_FSFW} MATCHES linux)
message(STATUS "FSFW OSAL invalid for specified target BSP ${TGT_BSP}!")
message(STATUS "Setting valid OS_FSFW: linux")
set(OS_FSFW "linux")
if(${TGT_BSP} MATCHES "arm/stm32h743zi-nucleo")
if(NOT ${OS_FSFW} MATCHES freertos)
message(STATUS
"FSFW OSAL invalid for specified target BSP ${TGT_BSP}!"
)
message(STATUS "Setting valid OS_FSFW: freertos")
set(OS_FSFW "freertos")
endif()
endif()
endif()
endif()
# Disable compiler checks for cross-compiling.
if(${OS_FSFW} MATCHES freertos)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SCRIPT_PATH}/STM32FreeRTOSConfig.cmake"
PARENT_SCOPE
)
elseif(${OS_FSFW} MATCHES rtems)
set(RTEMS_CONFIG_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/rtems-cmake"
CACHE FILEPATH
"Directory containing the RTEMS *.cmake files"
)
include(${RTEMS_CONFIG_DIR}/RTEMSPreProjectConfig.cmake)
if(NOT DEFINED RTEMS_PREFIX)
if(NOT DEFINED ENV{RTEMS_PREFIX})
message(FATAL_ERROR
"RTEMS_PREFIX must be set either manually or as an environment "
"variable!"
)
else()
message(STATUS
"Using environment variable RTEMS_PREFIX $ENV{RTEMS_PREFIX} "
"as RTEMS prefix"
)
set(RTEMS_PREFIX $ENV{RTEMS_PREFIX})
endif()
endif()
if(${TGT_BSP} MATCHES "arm/stm32h743zi-nucleo")
set(RTEMS_BSP "arm/nucleo-h743zi")
else()
if(NOT DEFINED RTEMS_BSP)
if(NOT DEFINED ENV{RTEMS_BSP})
message(FATAL_ERROR
"RTEMS_BSP must be set either manually or as an environment"
"variable!"
)
else()
set(RTEMS_BSP $ENV{RTEMS_BSP})
endif()
endif()
endif()
rtems_pre_project_config(${RTEMS_PREFIX} ${RTEMS_BSP})
set(CMAKE_TOOLCHAIN_FILE
${RTEMS_CONFIG_DIR}/RTEMSToolchain.cmake
PARENT_SCOPE
)
elseif(${OS_FSFW} STREQUAL linux AND TGT_BSP)
if(${TGT_BSP} MATCHES "host/none")
elseif(${TGT_BSP} MATCHES "arm/raspberrypi")
if(NOT DEFINED ENV{RASPBIAN_ROOTFS})
if(NOT RASPBIAN_ROOTFS)
set(ENV{RASPBIAN_ROOTFS} "$ENV{HOME}/raspberrypi/rootfs")
else()
set(ENV{RASPBIAN_ROOTFS} "${RASPBIAN_ROOTFS}")
endif()
else()
message(STATUS
"RASPBIAN_ROOTFS from environmental variables used: "
"$ENV{RASPBIAN_ROOTFS}"
)
endif()
if(NOT DEFINED ENV{RASPBERRY_VERSION})
if(NOT RASPBERRY_VERSION)
message(STATUS "No RASPBERRY_VERSION specified, setting to 4")
set(RASPBERRY_VERSION "4" CACHE STRING "Raspberry Pi version")
else()
message(STATUS
"Setting RASPBERRY_VERSION to ${RASPBERRY_VERSION}"
)
set(RASPBERRY_VERSION
${RASPBERRY_VERSION} CACHE STRING "Raspberry Pi version"
)
set(ENV{RASPBERRY_VERSION} ${RASPBERRY_VERSION})
endif()
else()
message(STATUS
"RASPBERRY_VERSION from environmental variables used: "
"$ENV{RASPBERRY_VERSION}"
)
endif()
if(LINUX_CROSS_COMPILE)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SCRIPT_PATH}/RPiCrossCompileConfig.cmake"
PARENT_SCOPE
)
endif()
elseif(${TGT_BSP} MATCHES "arm/beagleboneblack")
if(LINUX_CROSS_COMPILE)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SCRIPT_PATH}/BBBCrossCompileConfig.cmake"
PARENT_SCOPE
)
endif()
else()
message(WARNING "Target BSP (TGT_BSP) ${TGT_BSP} unknown!")
endif()
endif()
endfunction()

View File

@ -0,0 +1,146 @@
# Based on https://github.com/Pro/raspi-toolchain but rewritten completely.
# Adapted for the FSFW Example
if(NOT DEFINED ENV{RASPBERRY_VERSION})
message(STATUS "Raspberry Pi version not specified, setting version 4!")
set(RASPBERRY_VERSION 4)
else()
set(RASPBERRY_VERSION $ENV{RASPBERRY_VERSION})
endif()
# RASPBIAN_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
# 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 Raspberry Pi rootfs."
)
else()
set(SYSROOT_PATH "$ENV{RASPBIAN_ROOTFS}" CACHE PATH "Raspbian root filesystem path")
message(STATUS "Raspberry Pi sysroot: ${SYSROOT_PATH}")
endif()
if(NOT DEFINED ENV{CROSS_COMPILE})
set(CROSS_COMPILE "arm-linux-gnueabihf")
message(STATUS
"No CROSS_COMPILE environmental variable set, using default ARM linux "
"cross compiler name ${CROSS_COMPILE}"
)
else()
set(CROSS_COMPILE "$ENV{CROSS_COMPILE}")
message(STATUS
"Using environmental variable CROSS_COMPILE as cross-compiler: "
"$ENV{CROSS_COMPILE}"
)
endif()
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
set(CROSS_COMPILE_CC "${CROSS_COMPILE}-gcc")
set(CROSS_COMPILE_CXX "${CROSS_COMPILE}-g++")
set(CROSS_COMPILE_LD "${CROSS_COMPILE}-ld")
set(CROSS_COMPILE_AR "${CROSS_COMPILE}-ar")
set(CROSS_COMPILE_RANLIB "${CROSS_COMPILE}-ranlib")
set(CROSS_COMPILE_STRIP "${CROSS_COMPILE}-strip")
set(CROSS_COMPILE_NM "${CROSS_COMPILE}-nm")
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)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
# Define name of the target system
set(CMAKE_SYSTEM_NAME "Linux")
if(RASPBERRY_VERSION VERSION_GREATER 1)
set(CMAKE_SYSTEM_PROCESSOR "armv7")
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}/usr/local/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}"
"${SYSROOT_PATH}/usr/lib"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}/blas"
"${SYSROOT_PATH}/usr/lib/${CROSS_COMPILE}/lapack"
)
# You can additionally check the linker paths if you add the
# flags ' -Xlinker --verbose'
set(COMMON_FLAGS "-I${SYSROOT_PATH}/usr/include")
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 "Flags for Raspberry PI 4"
)
set(CMAKE_CXX_FLAGS
"${CMAKE_C_FLAGS}"
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 "Flags for Raspberry PI 3"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
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 "Flags for Raspberry PI 2"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "Flags for Raspberry PI 2"
)
else()
set(CMAKE_C_FLAGS
"-mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard ${COMMON_FLAGS}"
CACHE STRING "Flags for Raspberry PI 1 B+ Zero"
)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}"
CACHE STRING "Flags for Raspberry PI 1 B+ Zero"
)
endif()
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
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/beagleboneblack"
build_generator=""
builddir="build-Debug-BBB"
defines="LINUX_CROSS_COMPILE=OFF"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,3 @@
export PATH=$PATH:"$HOME/beaglebone/<cross_compiler_path>/bin"
export CROSS_COMPILE="arm-linux-gnueabihf"
export BBB_ROOTFS="${HOME}/raspberrypi/rootfs"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/beagleboneblack"
build_generator=""
builddir="build-Debug-BBB"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/beagleboneblack"
build_generator=""
builddir="build-Release-BBB"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/beagleboneblack"
build_generator=""
builddir="build-Release-BBB"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/raspberrypi"
build_generator=""
builddir="build-Debug-RPi"
defines="LINUX_CROSS_COMPILE=OFF"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/raspberrypi"
build_generator=""
builddir="build-Debug-RPi"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/raspberrypi"
build_generator=""
builddir="build-Release-RPi"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,30 @@
#!/bin/sh
counter=0
while [ ${counter} -lt 5 ]
do
cd ..
if [ -f "cmake_build_config.py" ];then
break
fi
counter=$((counter=counter + 1))
done
if [ "${counter}" -ge 5 ];then
echo "cmake_build_config.py not found in upper directories!"
exit 1
fi
os_fsfw="linux"
tgt_bsp="arm/raspberrypi"
build_generator=""
builddir="build-Release-RPi"
defines="LINUX_CROSS_COMPILE=ON"
if [ "${OS}" = "Windows_NT" ]; then
build_generator="MinGW Makefiles"
# Could be other OS but this works for now.
else
build_generator="Unix Makefiles"
fi
python3 cmake_build_config.py -o "${os_fsfw}" -g "${build_generator}" -b "debug" -t "${tgt_bsp}" \
-l "${builddir}" -d "${defines}"

View File

@ -0,0 +1,24 @@
#!/bin/sh
# This script can be used to set the path to the cross-compile toolchain
# A default path is set if the path is not supplied via command line
if [ $# -eq 1 ];then
export PATH=$PATH:"$1"
else
# TODO: make version configurable via shell argument
export PATH=$PATH:"/opt/cross-pi-gcc/bin"
export CROSS_COMPILE="arm-linux-gnueabihf"
export RASPBERRY_VERSION="4"
export RASPBIAN_ROOTFS="${HOME}/raspberrypi/rootfs"
fi
# It is also recommended to set up a custom shell script to perform the
# sysroot synchronization so that any software is built with the library and
# headers of the Raspberry Pi. This can for example be dome with the rsync
# command.
# The following command can be used, <ip-address> and the local
# <rootfs-path> need to be set accordingly.
# rsync -vR --progress -rl --delete-after --safe-links pi@<ip-address>:/{lib,usr,opt/vc/lib} <rootfs-path>
# It is recommended to use $HOME/raspberrypi/rootfs as the rootfs path,
# so the default RASPBIAN_ROOTFS variable set in the CMakeLists.txt is correct.

View File

@ -0,0 +1,22 @@
#!/bin/sh
# This script can be used to set the path to the cross-compile toolchain
# A default path is set if the path is not supplied via command line
if [ $# -eq 1 ];then
export PATH=$PATH:"$1"
else
# TODO: make version configurable via shell argument
export PATH=$PATH:"/c/SysGCC/raspberry/bin"
export CROSS_COMPILE="arm-linux-gnueabihf"
export RASPBERRY_VERSION="4"
export RASPBIAN_ROOTFS="/c/Users/<UserName>/raspberrypi/rootfs"
fi
# It is also recommended to set up a custom shell script to perform the
# sysroot synchronization so that any software is built with the library and
# headers of the Raspberry Pi. This can for example be dome with the rsync
# command.
# The following command can be used, <ip-address> and the local
# <rootfs-path> need to be set accordingly.
# rsync -vR --progress -rl --delete-after --safe-links pi@<ip-address>:/{lib,usr,opt/vc/lib} <rootfs-path>

View File

@ -0,0 +1,247 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*
"""
@brief CMake configuration helper
@details
This script was written to have a portable way to perform the CMake configuration with various parameters on
different OSes. It was first written for the FSFW Example, but could be adapted to be more generic
in the future.
Run cmake_build_config.py --help to get more information.
"""
import os
import platform
import sys
import argparse
import shutil
def main():
print("-- Python CMake build configurator utility --")
print("Parsing command line arguments..")
parser = argparse.ArgumentParser(description="Processing arguments for CMake build configuration.")
parser.add_argument(
"-o", "--osal", type=str, choices=["freertos", "linux", "rtems", "host"],
help="FSFW OSAL. Valid arguments: host, linux, rtems, freertos"
)
parser.add_argument(
"-b", "--buildtype", type=str, choices=["debug", "release", "size", "reldeb"],
help="CMake build type. Valid arguments: debug, release, size, reldeb (Release with Debug Information)",
default="debug"
)
parser.add_argument("-l", "--builddir", type=str, help="Specify build directory.")
parser.add_argument("-g", "--generator", type=str, help="CMake Generator")
parser.add_argument(
"-t", "--target-bsp", type=str, help="Target BSP, combination of architecture and machine"
)
parser.add_argument(
"-d", "--defines",
help="Additional custom defines passed to CMake (supply without -D prefix!)",
nargs="*", type=str
)
args = parser.parse_args()
print("Determining source location..")
source_location = determine_source_location()
print(f"Determined source location: {source_location}")
print("Building cmake configuration command..")
if args.generator is None:
generator = determine_build_generator()
generator_cmake_arg = f"-G \"{generator}\""
else:
generator_cmake_arg = f"-G \"{args.generator}\""
if args.osal is None:
print("No FSFW OSAL specified.")
cmake_fsfw_osal = determine_fsfw_osal()
else:
cmake_fsfw_osal = args.osal
cmake_build_type = determine_build_type(args.buildtype)
if args.target_bsp is not None:
cmake_target_cfg_cmd = f"-DTGT_BSP=\"{args.target_bsp}\""
else:
cmake_target_cfg_cmd = determine_tgt_bsp(cmake_fsfw_osal)
define_string = ""
if args.defines is not None:
define_list = args.defines[0].split()
for define in define_list:
define_string += f"-D{define} "
if args.builddir is None:
cmake_build_folder = determine_build_folder(cmake_build_type)
else:
cmake_build_folder = args.builddir
build_path = source_location + os.path.sep + cmake_build_folder
if os.path.isdir(build_path):
remove_old_dir = input(f"{cmake_build_folder} folder already exists. "
f"Remove old directory? [y/n]: ")
if str(remove_old_dir).lower() in ["yes", "y", 1]:
remove_old_dir = True
else:
cmake_build_folder = determine_new_folder()
build_path = source_location + os.path.sep + cmake_build_folder
remove_old_dir = False
if remove_old_dir:
try:
shutil.rmtree(build_path)
except PermissionError as error:
print(error)
print("File might still be opened!")
sys.exit(0)
os.chdir(source_location)
os.mkdir(cmake_build_folder)
print(f"Navigating into build directory: {build_path}")
os.chdir(cmake_build_folder)
cmake_command = f"cmake {generator_cmake_arg} -DOS_FSFW=\"{cmake_fsfw_osal}\" " \
f"-DCMAKE_BUILD_TYPE=\"{cmake_build_type}\" {cmake_target_cfg_cmd} " \
f"{define_string} {source_location}"
# Remove redundant spaces
cmake_command = ' '.join(cmake_command.split())
print("Running CMake command (without +): ")
print(f"+ {cmake_command}")
os.system(cmake_command)
print("-- CMake configuration done. --")
def determine_build_generator() -> str:
print("No generator specified. ")
print("Please select from the following list of build types or type "
"in desired system directly [h for help]: ")
while True:
user_input = input("Enter your selection: ")
if user_input == "h":
os.system("cmake --help")
else:
build_generator = user_input
confirmation = input(f"Confirm your generator: {build_generator} [y/n]: ")
if confirmation in ["y", "yes", 1]:
break
return build_generator
def determine_build_folder(cmake_build_type: str) -> str:
confirm = input(f"No build folder specified. Set to build type name {cmake_build_type}? [y/n]: ")
if confirm in ["yes", "y", 1]:
return cmake_build_type
else:
new_folder_name = input("Please enter folder name, will be created in source folder: ")
return new_folder_name
def determine_source_location() -> str:
index = 0
while not os.path.isdir("fsfw"):
index += 1
os.chdir("..")
if index >= 5:
print("Error: Could not find source directory (determined by looking for fsfw folder!)")
sys.exit(1)
return os.getcwd()
def determine_fsfw_osal() -> str:
select_dict = dict({
1: "host",
2: "linux",
3: "freertos",
4: "rtems"
})
print("No build type specified. Please select from the following list of build types: ")
for key, item in select_dict.items():
print(f"{key}: {item}")
select = input("Enter your selection: ")
while True:
if select.isdigit():
select_num = int(select)
if select_num >= 1 or select_num <= 4:
return select_dict[select_num]
else:
print("Input digit is invalid!")
else:
print("Input is not a digit!")
def determine_build_type(build_type_arg) -> str:
if build_type_arg is None:
select_dict = dict({
1: "Debug",
2: "Release",
3: "Release with Debug Information",
4: "Size"
})
print("No build type specified. Please select from the following list of build types")
for key, item in select_dict.items():
print(f"{key}: {item}")
select = input("Enter your selection: ")
while True:
if select.isdigit():
select_num = int(select)
if select_num >= 1 or select_num <= 4:
cmake_build_type = select_dict[select_num]
break
else:
print("Input digit is invalid!")
else:
print("Input is not a digit!")
else:
if build_type_arg == "debug":
cmake_build_type = "Debug"
elif build_type_arg == "release":
cmake_build_type = "Release"
elif build_type_arg == "size":
cmake_build_type = "MinSizeRel"
elif build_type_arg == "reldeb":
cmake_build_type = "RelWithDebInfo"
else:
print("Unknown buildtype.")
cmake_build_type = determine_build_type(None)
return cmake_build_type
def determine_new_folder() -> str:
new_folder = input(f"Use different folder name? [y/n]: ")
if str(new_folder).lower() in ["yes", "y", 1]:
new_folder_name = input("New folder name: ")
return new_folder_name
else:
print("Aborting configuration.")
sys.exit(0)
def determine_tgt_bsp(osal: str) -> str:
if osal == "freertos":
print("Target BSP set to arm/stm32h743zi-nucleo")
osal = "arm/stm32h743zi-nucleo"
elif osal == "linux":
print("No target BSP specified. Please select from the following list of build types.")
select_dict = dict({
1: "arm/raspberrypi",
2: "none/hosted"
})
for key, item in select_dict.items():
print(f"{key}: {item}")
select = input("Enter your selection: ")
while True:
if select.isdigit():
select_num = int(select)
if select_num >= 1 or select_num <= 2:
osal = select_dict[select_num]
break
else:
print("Input digit is invalid!")
else:
print("Input is not a digit!")
return osal
if __name__ == "__main__":
main()