fsfw-example-stm32h7-freertos/CMakeLists.txt

206 lines
6.6 KiB
CMake
Raw Permalink Normal View History

2022-05-22 15:30:38 +02:00
# ##############################################################################
# CMake support for the Flight Software Framework Author: R. Mueller
# ##############################################################################
2021-07-12 21:50:48 +02:00
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Pre-Project preparation
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
cmake_minimum_required(VERSION 3.13)
# set(CMAKE_VERBOSE TRUE)
set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2022-05-29 18:41:52 +02:00
set(CMAKE_COMMON_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/example_common/cmake")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SCRIPT_PATH})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_COMMON_SCRIPT_PATH})
message(STATUS ${CMAKE_MODULE_PATH})
2022-05-22 15:30:38 +02:00
set(STM32_CMAKE_PATH "${CMAKE_SCRIPT_PATH}/stm32-cmake")
2021-07-12 22:11:03 +02:00
set(STM32_CUBE_H7_PATH STM32CubeH7)
set(STM32_TOOLCHAIN_PATH $ENV{STM32_TOOLCHAIN_PATH})
set(TARGET_TRIPLET "arm-none-eabi")
2021-07-12 21:50:48 +02:00
2021-07-12 22:11:03 +02:00
# This call has to come before the project call
set(CMAKE_TOOLCHAIN_FILE ${STM32_CMAKE_PATH}/cmake/stm32_gcc.cmake)
2021-07-12 21:50:48 +02:00
# Project Name
2021-07-12 21:54:04 +02:00
project(fsfw-example-stm32h7-freertos ASM C CXX)
2021-07-12 21:50:48 +02:00
2022-05-22 19:29:52 +02:00
set(FSFW_OSAL
freertos
CACHE STRING "OS for the FSFW")
set(STM32_ADD_NETWORKING_CODE ON)
set(FSFW_HAL_ADD_STM32H7 ON)
2022-05-22 17:45:44 +02:00
set(OBSW_MAX_SCHEDULED_TCS 200)
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Pre-Sources preparation
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Specify the C++ standard
2022-05-22 15:30:38 +02:00
set(CMAKE_CXX_STANDARD 17)
2021-07-12 21:50:48 +02:00
set(CMAKE_CXX_STANDARD_REQUIRED True)
2021-10-27 17:09:41 +02:00
set(FSFW_OSAL "freertos")
2021-07-12 23:33:05 +02:00
set(TGT_BSP "arm/stm32h743zi-nucleo")
2021-07-12 22:11:03 +02:00
set(FREERTOS_NAMESPACE FreeRTOS::STM32::H7::M7)
2021-07-12 21:50:48 +02:00
# Set names and variables
2022-05-22 15:30:38 +02:00
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
2021-07-12 21:50:48 +02:00
set(LIB_FSFW_NAME fsfw)
# Set path names
set(FSFW_PATH fsfw)
set(COMMON_PATH example_common)
2021-07-12 21:54:04 +02:00
set(BSP_PATH "bsp_stm32h7_freertos")
2021-07-12 21:50:48 +02:00
set(COMMON_CONFIG_PATH "${COMMON_PATH}/config")
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
2021-07-12 23:33:05 +02:00
set(BSP_NUCLEO_PATH "${BSP_PATH}/NUCLEO-H743ZI")
2021-07-13 10:23:17 +02:00
set(BSP_NUCLEO_INC_PATH "${BSP_NUCLEO_PATH}/Inc")
2021-07-13 11:04:31 +02:00
# See stm32-cmake documentation for more information
2022-05-22 15:30:38 +02:00
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)
2021-07-13 11:04:31 +02:00
find_package(LwIP REQUIRED)
2021-07-12 23:33:05 +02:00
2022-05-22 15:30:38 +02:00
# These need to be set for the FSFW so the sources are compiled with the ABI
# flags and to compile FreeRTOS first
2021-07-13 11:04:31 +02:00
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})
2022-05-22 15:30:38 +02:00
set(FSFW_HAL_LINK_LIBS HAL::STM32::H7::M7::CORTEX ${CMSIS_LINK_TARGET}
${LIB_OS_NAME})
2021-07-13 11:04:31 +02:00
set(FSFW_HAL_ADDITIONAL_INC_PATHS ${BSP_NUCLEO_INC_PATH})
2022-05-22 15:30:38 +02:00
set(FSFW_ADDITIONAL_INC_PATHS
"${COMMON_CONFIG_PATH}" "${CMAKE_CURRENT_BINARY_DIR}"
CACHE STRING "FSFW configuration paths")
2021-07-12 21:50:48 +02:00
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)
2021-07-12 23:33:05 +02:00
configure_file(${BSP_NUCLEO_PATH}/Inc/FreeRTOSConfig.h.in FreeRTOSConfig.h)
configure_file(${BSP_NUCLEO_PATH}/Inc/lwipopts.h.in lwipopts.h)
2021-07-12 21:50:48 +02:00
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Executable and Sources
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Add executable
add_executable(${TARGET_NAME})
# Add subdirectories
add_subdirectory(${BSP_PATH})
add_subdirectory(${FSFW_PATH})
add_subdirectory(${COMMON_PATH})
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
# Post-Sources preparation
2022-05-22 15:30:38 +02:00
# ##############################################################################
2021-07-12 21:50:48 +02:00
2022-05-22 17:45:44 +02:00
# Check whether the user has already installed ETL first
2022-05-22 19:29:52 +02:00
# find_package(etl ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET)
2022-05-22 18:11:11 +02:00
# Not installed, so use FetchContent to download and provide etl
2022-05-22 19:29:52 +02:00
# if(NOT etl_FOUND)
# There are issues using find_package. For now, always use FetchContent
# See this github issue: https://github.com/ETLCPP/etl/issues/548
message(
STATUS
"No ETL installation was found with find_package. Installing and providing "
"etl with FindPackage")
include(FetchContent)
FetchContent_Declare(
etl
GIT_REPOSITORY https://github.com/ETLCPP/etl
GIT_TAG ${FSFW_ETL_LIB_VERSION})
list(APPEND FSFW_FETCH_CONTENT_TARGETS etl)
# endif()
2022-05-22 17:45:44 +02:00
# The documentation for FetchContent recommends declaring all the dependencies
# before making them available. We make all declared dependency available here
# after their declaration
if(FSFW_FETCH_CONTENT_TARGETS)
FetchContent_MakeAvailable(${FSFW_FETCH_CONTENT_TARGETS})
endif()
2021-07-12 21:50:48 +02:00
# Add libraries for all sources.
2022-05-22 15:30:38 +02:00
target_link_libraries(
${TARGET_NAME}
PRIVATE ${LIB_FSFW_NAME}
2022-05-22 17:45:44 +02:00
etl::etl
2022-05-22 15:30:38 +02:00
${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)
2021-07-12 21:50:48 +02:00
2022-05-29 18:41:52 +02:00
include(common)
get_common_build_flags(${TARGET_NAME})
2021-07-12 21:50:48 +02:00
# Add include paths for all sources.
2022-05-22 15:30:38 +02:00
target_include_directories(
${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${FSFW_CONFIG_PATH})
2021-07-12 21:50:48 +02:00
2022-05-29 18:41:52 +02:00
target_compile_options(${TARGET_NAME} PRIVATE ${COMMON_COMPILE_OPTS} ${COMMON_WARNING_FLAGS})
target_link_options(${TARGET_NAME} PRIVATE ${COMMON_LINK_OPTS})
2021-07-12 21:50:48 +02:00
if(TGT_BSP)
2022-05-22 15:30:38 +02:00
set(TARGET_STRING "Target BSP: ${TGT_BSP}")
2021-07-12 21:50:48 +02:00
else()
2022-05-22 15:30:38 +02:00
set(TARGET_STRING "Target BSP: Hosted")
2021-07-12 21:50:48 +02:00
endif()
2022-05-22 15:30:38 +02:00
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}")
2021-07-12 21:50:48 +02:00
2022-05-22 15:30:38 +02:00
stm32_add_linker_script(${TARGET_NAME} "PRIVATE"
"${BSP_NUCLEO_PATH}/STM32H743ZITx_FLASH.ld")
2021-07-13 10:23:17 +02:00
2022-05-29 18:41:52 +02:00
include(BuildType)
2021-07-12 21:50:48 +02:00
set_build_type()
2021-07-12 22:11:03 +02:00
stm32_print_size_of_target(${TARGET_NAME})
stm32_generate_binary_file(${TARGET_NAME})