fsfw-example-stm32h7-freertos/CMakeLists.txt

203 lines
6.1 KiB
CMake

################################################################################
# CMake support for the Flight Software Framework
# Author: R. Mueller
################################################################################
################################################################################
# Pre-Project preparation
################################################################################
cmake_minimum_required(VERSION 3.13)
# set(CMAKE_VERBOSE TRUE)
set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(STM32_CMAKE_PATH "${CMAKE_SCRIPT_PATH}/stm32-cmake")
set(STM32_CUBE_H7_PATH STM32CubeH7)
set(STM32_TOOLCHAIN_PATH $ENV{STM32_TOOLCHAIN_PATH})
set(TARGET_TRIPLET "arm-none-eabi")
set(FSFW_OSAL freertos CACHE STRING "OS for the FSFW")
set(STM32_ADD_NETWORKING_CODE ON)
set(FSFW_HAL_ADD_STM32H7 ON)
# This call has to come before the project call
set(CMAKE_TOOLCHAIN_FILE ${STM32_CMAKE_PATH}/cmake/stm32_gcc.cmake)
# Project Name
project(fsfw-example-stm32h7-freertos ASM C CXX)
################################################################################
# Pre-Sources preparation
################################################################################
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(FSFW_OSAL "freertos")
set(TGT_BSP "arm/stm32h743zi-nucleo")
set(FREERTOS_NAMESPACE FreeRTOS::STM32::H7::M7)
# Set names and variables
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
set(LIB_FSFW_NAME fsfw)
# Set path names
set(FSFW_PATH fsfw)
set(COMMON_PATH example_common)
set(BSP_PATH "bsp_stm32h7_freertos")
set(COMMON_CONFIG_PATH "${COMMON_PATH}/config")
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
set(BSP_NUCLEO_PATH "${BSP_PATH}/NUCLEO-H743ZI")
set(BSP_NUCLEO_INC_PATH "${BSP_NUCLEO_PATH}/Inc")
# See stm32-cmake documentation for more information
find_package(CMSIS COMPONENTS STM32H743ZI STM32H7_M7 RTOS REQUIRED)
find_package(FreeRTOS COMPONENTS STM32H7 ARM_CM7 REQUIRED)
find_package(HAL COMPONENTS STM32H7M7 STM32H743ZI RCC GPIO UART TIM CORTEX ETH SPI DMA REQUIRED)
find_package(LwIP REQUIRED)
# These need to be set for the FSFW so the sources are compiled with the ABI flags
# and to compile FreeRTOS first
set(LIB_OS_NAME ${FREERTOS_NAMESPACE}::ARM_CM7)
# This target is used because a custom linker script is used
set(CMSIS_LINK_TARGET CMSIS::STM32::H743xx::M7)
set(FSFW_ADDITIONAL_LINK_LIBS ${CMSIS_LINK_TARGET})
set(FSFW_HAL_LINK_LIBS
HAL::STM32::H7::M7::CORTEX
${CMSIS_LINK_TARGET}
${LIB_OS_NAME}
)
set(FSFW_HAL_ADDITIONAL_INC_PATHS ${BSP_NUCLEO_INC_PATH})
set(FSFW_ADDITIONAL_INC_PATHS
"${COMMON_CONFIG_PATH}"
"${CMAKE_CURRENT_BINARY_DIR}"
CACHE STRING
"FSFW configuration paths"
)
configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h)
configure_file(${FSFW_CONFIG_PATH}/FSFWConfig.h.in FSFWConfig.h)
configure_file(${FSFW_CONFIG_PATH}/OBSWConfig.h.in OBSWConfig.h)
configure_file(${BSP_NUCLEO_PATH}/Inc/FreeRTOSConfig.h.in FreeRTOSConfig.h)
configure_file(${BSP_NUCLEO_PATH}/Inc/lwipopts.h.in lwipopts.h)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNING_FLAGS
-Wall
-Wextra
-Wimplicit-fallthrough=1
-Wno-unused-parameter
-Wno-psabi
)
set(FSFW_WARNING_FLAGS ${WARNING_FLAGS})
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/permissive- /d2SSAOptimizer-)
# To avoid nameclashes with min and max macro
add_compile_definitions(NOMINMAX)
endif()
################################################################################
# Executable and Sources
################################################################################
# Add executable
add_executable(${TARGET_NAME})
# Add subdirectories
add_subdirectory(${BSP_PATH})
add_subdirectory(${FSFW_PATH})
# add_subdirectory(${LIB_FSFW_HAL_PATH})
add_subdirectory(${COMMON_PATH})
################################################################################
# Post-Sources preparation
################################################################################
# Add libraries for all sources.
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_FSFW_NAME}
# ${LIB_FSFW_HAL_NAME}
${FREERTOS_NAMESPACE}::Heap::4
${FREERTOS_NAMESPACE}::ARM_CM7
HAL::STM32::H7::M7::RCC
HAL::STM32::H7::M7::RCCEx
HAL::STM32::H7::M7::GPIO
HAL::STM32::H7::M7::UART
HAL::STM32::H7::M7::CORTEX
HAL::STM32::H7::M7::TIM
HAL::STM32::H7::M7::TIMEx
HAL::STM32::H7::M7::ETH
HAL::STM32::H7::M7::SPI
HAL::STM32::H7::M7::DMA
${CMSIS_LINK_TARGET}
CMSIS::STM32::H7::M7::RTOS
STM32::NoSys
STM32::Nano
STM32::Nano::FloatPrint
STM32::Nano::FloatScan
LwIP
LwIP::IPv4
LwIP::NETIF
)
# Add include paths for all sources.
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${FSFW_CONFIG_PATH}
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_options(${TARGET_NAME} PRIVATE
"-Wl,-Map=${TARGET_NAME}.map"
)
# Remove unused sections.
target_compile_options(${TARGET_NAME} PRIVATE
"-ffunction-sections"
"-fdata-sections"
)
# Removed unused sections.
if(NOT FSFW_OSAL MATCHES rtems)
target_link_options(${TARGET_NAME} PRIVATE
"-Wl,--gc-sections"
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
endif()
if(CMAKE_VERBOSE)
message(STATUS "Warning flags: ${WARNING_FLAGS}")
endif()
# Compile options for all sources.
target_compile_options(${TARGET_NAME} PRIVATE
${WARNING_FLAGS}
)
if(TGT_BSP)
set(TARGET_STRING "Target BSP: ${TGT_BSP}")
else()
set(TARGET_STRING "Target BSP: Hosted")
endif()
string(CONCAT POST_BUILD_COMMENT
"Build directory: ${CMAKE_BINARY_DIR}\n"
"Target OSAL: ${FSFW_OSAL}\n"
"Target Build Type: ${CMAKE_BUILD_TYPE}\n"
"${TARGET_STRING}"
)
stm32_add_linker_script(${TARGET_NAME} "PRIVATE" "${BSP_NUCLEO_PATH}/STM32H743ZITx_FLASH.ld")
include (${CMAKE_SCRIPT_PATH}/BuildType.cmake)
set_build_type()
stm32_print_size_of_target(${TARGET_NAME})
stm32_generate_binary_file(${TARGET_NAME})