build(cmake): Allow spliting of toolchains, which will help with multi-platform support

CMake: Use ExternalProject_Add() to split by toolchain

Splits targets between native and cross-compiled targets, provides a cleaner solution to problems raised by compiling for example on Apple silicon, and better managing dependencies by allowing for object libraries in a cleaner way.
This commit is contained in:
Peter Feerick
2022-04-24 10:29:31 +10:00
committed by GitHub
624 changed files with 888 additions and 206891 deletions
@@ -270,8 +270,6 @@ add_definitions(-DGPS)
add_definitions(-DBATTGRAPH -DTHRTRACE)
add_definitions(-DSBUS_TRAINER)
include_directories(${RTOS_DIR}/include)
foreach(LANGUAGE ${TTS_LANGUAGES})
string(TOLOWER ${LANGUAGE} lang_lower)
set(SRC ${SRC} translations/tts_${lang_lower}.cpp)
@@ -299,22 +297,6 @@ set(FIRMWARE_TARGET_SRC
telemetry_driver.cpp
)
set(FIRMWARE_SRC
${FIRMWARE_SRC}
${RTOS_DIR}/list.c
${RTOS_DIR}/queue.c
${RTOS_DIR}/tasks.c
${RTOS_DIR}/event_groups.c
${RTOS_DIR}/timers.c
rtos.c)
if(CLI)
set(FIRMWARE_SRC
${FIRMWARE_SRC}
${RTOS_DIR}/stream_buffer.c)
endif()
set(PULSES_SRC
${PULSES_SRC}
pulses.cpp
@@ -180,7 +180,7 @@ endif()
add_custom_command(
TARGET bootloader POST_BUILD
COMMAND ${FIRMWARE_OBJCOPY} -O binary bootloader.elf ${CMAKE_BINARY_DIR}/bootloader.bin
COMMAND ${CMAKE_OBJCOPY} -O binary bootloader.elf ${CMAKE_BINARY_DIR}/bootloader.bin
)
if(PYTHONINTERP_FOUND)
@@ -47,16 +47,36 @@ set(STM32LIB_SRC
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_adc.c
)
#
# FreeRTOS port specific include
#
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM3)
if(NOT NATIVE_BUILD)
#
# FreeRTOS port specific include
#
add_library(freertos OBJECT EXCLUDE_FROM_ALL
${RTOS_DIR}/list.c
${RTOS_DIR}/queue.c
${RTOS_DIR}/tasks.c
${RTOS_DIR}/event_groups.c
${RTOS_DIR}/timers.c
${RTOS_DIR}/stream_buffer.c
${RTOS_DIR}/portable/GCC/ARM_CM3/port.c
)
#
# System and FreeRTOS port files
#
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/f2/system_stm32f2xx.c
../../${RTOS_DIR}/portable/GCC/ARM_CM3/port.c
)
target_include_directories(freertos
PUBLIC ${RTOS_DIR}/portable/GCC/ARM_CM3
PRIVATE ${RTOS_DIR}/include
)
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM3)
# EdgeTx Compat layer
set(FIRMWARE_SRC ${FIRMWARE_SRC} rtos.c)
#
# System and FreeRTOS port files
#
set(FIRMWARE_SRC ${FIRMWARE_SRC}
$<TARGET_OBJECTS:freertos>
targets/common/arm/stm32/f2/system_stm32f2xx.c
)
endif()
@@ -2,25 +2,27 @@ set(CPU_FAMILY STM32)
set(MCU cortex-m4)
set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
# STM32 HAL/LL library
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32F4xx_HAL_Driver)
if(NOT NATIVE_BUILD)
# STM32 HAL/LL library
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32F4xx_HAL_Driver)
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
${STM32CUBE_DIR}/Src/stm32f4xx_ll_gpio.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_tim.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_dma.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_usart.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_rcc.c
)
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
${STM32CUBE_DIR}/Src/stm32f4xx_ll_gpio.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_tim.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_dma.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_usart.c
${STM32CUBE_DIR}/Src/stm32f4xx_ll_rcc.c
)
target_compile_options(stm32cube_ll PRIVATE -DUSE_FULL_LL_DRIVER)
target_include_directories(stm32cube_ll PRIVATE
${STM32CUBE_DIR}/Inc
${THIRDPARTY_DIR}/CMSIS/Device/ST/STM32F4xx/Include
${THIRDPARTY_DIR}/CMSIS/Include)
target_compile_options(stm32cube_ll PRIVATE -DUSE_FULL_LL_DRIVER)
target_include_directories(stm32cube_ll PRIVATE
${STM32CUBE_DIR}/Inc
${THIRDPARTY_DIR}/CMSIS/Device/ST/STM32F4xx/Include
${THIRDPARTY_DIR}/CMSIS/Include)
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
endif()
# StdPeriph library
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries)
@@ -47,16 +49,35 @@ set(STM32LIB_SRC
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_adc.c
)
#
# FreeRTOS port specific include
#
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM4F)
if(NOT NATIVE_BUILD)
#
# FreeRTOS port specific include
#
add_library(freertos OBJECT EXCLUDE_FROM_ALL
${RTOS_DIR}/list.c
${RTOS_DIR}/queue.c
${RTOS_DIR}/tasks.c
${RTOS_DIR}/event_groups.c
${RTOS_DIR}/timers.c
${RTOS_DIR}/stream_buffer.c
${RTOS_DIR}/portable/GCC/ARM_CM4F/port.c
)
#
# System and FreeRTOS port files
#
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/f4/system_stm32f4xx.c
../../${RTOS_DIR}/portable/GCC/ARM_CM4F/port.c
)
target_include_directories(freertos
PUBLIC ${RTOS_DIR}/portable/GCC/ARM_CM4F
PRIVATE ${RTOS_DIR}/include
)
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM4F)
# EdgeTx Compat layer
set(FIRMWARE_SRC ${FIRMWARE_SRC} rtos.c)
#
# System and FreeRTOS port files
#
set(FIRMWARE_SRC ${FIRMWARE_SRC}
$<TARGET_OBJECTS:freertos>
targets/common/arm/stm32/f4/system_stm32f4xx.c
)
endif()
+10 -40
View File
@@ -309,50 +309,20 @@ set(STM32LIB_SRC
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma2d.c
)
MACRO(GET_GCC_INCLUDE_PATH gcc_include_path)
if (WIN32)
execute_process(COMMAND ${CMAKE_C_COMPILER} -v -x c -E NUL ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
else()
execute_process(COMMAND ${CMAKE_C_COMPILER} -v -x c -E - INPUT_FILE /dev/null ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
endif()
# Build an array of string from the GCC output
string(REPLACE "\n" ";" _gcc_output "${_gcc_output}")
set(_capture_include FALSE)
set(_include_path "")
# Go through the lines and capture between '"#include <...> search starts here:"' and 'End of search list.'
foreach(_line ${_gcc_output})
if(${_line} STREQUAL "End of search list.")
set(_capture_include FALSE)
endif()
if(_capture_include)
# Remove the leading and trailing empty characters
string(REPLACE "\r" "" _line ${_line})
string(SUBSTRING "${_line}" 1 -1 _line)
set(_include_path "${_include_path}" "-I\"${_line}\"")
endif()
if(${_line} STREQUAL "#include <...> search starts here:")
set(_capture_include TRUE)
endif()
endforeach()
set(${gcc_include_path} ${_include_path})
ENDMACRO()
if(PYTHONINTERP_FOUND)
GET_GCC_INCLUDE_PATH(gcc_include_path)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h -DPCBHORUS -DPCB${PCB} -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU -I. -Igui/colorlcd -Itargets/horus -Itargets/common/arm/stm32 -I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include ${gcc_include_path} -Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG} > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h
-DPCBHORUS -DPCB${PCB} -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU
-I. -Igui/colorlcd -Itargets/horus -Itargets/common/arm/stm32
-I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include
-Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG}
> ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py
)
add_custom_target(datacopy
DEPENDS ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
)
add_custom_target(datacopy DEPENDS ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp)
endif()
+10 -40
View File
@@ -187,51 +187,21 @@ set(STM32LIB_SRC
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
)
MACRO(GET_GCC_INCLUDE_PATH gcc_include_path)
if (WIN32)
execute_process(COMMAND arm-none-eabi-gcc -v -x c -E NUL ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
else()
execute_process(COMMAND arm-none-eabi-gcc -v -x c -E - INPUT_FILE /dev/null ERROR_VARIABLE _gcc_output OUTPUT_QUIET)
endif()
# Build an array of string from the GCC output
string(REPLACE "\n" ";" _gcc_output "${_gcc_output}")
set(_capture_include FALSE)
set(_include_path "")
# Go through the lines and capture between '"#include <...> search starts here:"' and 'End of search list.'
foreach(_line ${_gcc_output})
if(${_line} STREQUAL "End of search list.")
set(_capture_include FALSE)
endif()
if(_capture_include)
# Remove the leading and trailing empty characters
string(REPLACE "\r" "" _line ${_line})
string(SUBSTRING "${_line}" 1 -1 _line)
set(_include_path "${_include_path}" "-I\"${_line}\"")
endif()
if(${_line} STREQUAL "#include <...> search starts here:")
set(_capture_include TRUE)
endif()
endforeach()
set(${gcc_include_path} ${_include_path})
ENDMACRO()
if(PYTHONINTERP_FOUND)
GET_GCC_INCLUDE_PATH(gcc_include_path)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h -DPCBFLYSKY -DPCBNV14 -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU -I. -Igui/colorlcd -Itargets/nv14 -Itargets/common/arm/stm32 -I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include -I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include ${gcc_include_path} -Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG} > ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
COMMAND ${PYTHON_EXECUTABLE} ${RADIO_DIRECTORY}/util/generate_datacopy.py datastructs_private.h
-DPCBFLYSKY -DPCBNV14 -DCPUARM -DSTM32F4 -DSTM32F429_439xx -DCOLORLCD -DBACKUP -DSIMU
-I. -Igui/colorlcd -Itargets/nv14 -Itargets/common/arm/stm32
-I${THIRDPARTY_DIR} -I${THIRDPARTY_DIR}/libopenui/src
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/STM32F4xx_StdPeriph_Driver/inc
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include
-I${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries/CMSIS/Include
-Wno-asm-operand-widths -Wno-pragma-once-outside-header ${SYSROOT_ARG}
> ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h ${RADIO_DIRECTORY}/util/generate_datacopy.py
)
add_custom_target(datacopy
DEPENDS ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp
)
add_custom_target(datacopy DEPENDS ${PROJECT_BINARY_DIR}/radio/src/datacopy.cpp)
endif()