168 lines
5.8 KiB
CMake
168 lines
5.8 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(RTEMS_CMAKE_PATH "${CMAKE_SCRIPT_PATH}/rtems-cmake")
|
|
|
|
set(FSFW_OSAL
|
|
rtems
|
|
CACHE STRING "OS for the FSFW")
|
|
set(STM32_ADD_NETWORKING_CODE ON)
|
|
set(OBSW_MAX_SCHEDULED_TCS 200)
|
|
set(FSFW_HAL_ADD_STM32H7 ON)
|
|
|
|
# Set TGT_BSP to correct target for pre-project configuration
|
|
set(TGT_BSP "arm/stm32h743zi-nucleo")
|
|
add_definitions(-DSTM32H743ZI_NUCLEO)
|
|
|
|
# This call has to come before the project call
|
|
include("${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake")
|
|
|
|
# Project Name
|
|
project(fsfw-example-stm32h7-rtems ASM C CXX)
|
|
|
|
# ##############################################################################
|
|
# Pre-Sources preparation
|
|
# ##############################################################################
|
|
|
|
# Specify the C++ standard
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
# Set names and variables
|
|
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
|
|
set(LIB_FSFW_NAME fsfw)
|
|
set(LIB_LWIP_NAME lwip)
|
|
|
|
# Set path names
|
|
set(FSFW_PATH fsfw)
|
|
set(COMMON_PATH example_common)
|
|
|
|
set(BSP_PATH "bsp_stm32h7_rtems")
|
|
set(COMMON_CONFIG_PATH "${COMMON_PATH}/config")
|
|
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
|
|
set(BSP_NUCLEO_PATH "${BSP_PATH}/boarconfig/NUCLEO-H743ZI")
|
|
set(BSP_NUCLEO_PATH_INC "${BSP_PATH}/boardconfig/NUCLEO-H743ZI/Inc")
|
|
|
|
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}/lwipopts.h.in lwipopts.h)
|
|
configure_file(${BSP_PATH}/RTEMSConfig.h.in RTEMSConfig.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(${COMMON_PATH})
|
|
|
|
# ##############################################################################
|
|
# Post-Sources preparation
|
|
# ##############################################################################
|
|
|
|
# Check whether the user has already installed ETL first find_package(etl
|
|
# ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET) Not installed, so use FetchContent
|
|
# to download and provide etl 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()
|
|
|
|
# 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()
|
|
|
|
# Add libraries for all sources.
|
|
target_link_libraries(
|
|
${TARGET_NAME}
|
|
PRIVATE ${LIB_FSFW_NAME} etl
|
|
# Link against lwip which is part of the RTEMS BSP
|
|
${LIB_LWIP_NAME})
|
|
|
|
# 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})
|
|
|
|
string(CONCAT POST_BUILD_COMMENT "Build directory: ${CMAKE_BINARY_DIR}\n"
|
|
"Target OSAL: ${FSFW_OSAL}\n" "Target RTEMS BSP: ${RTEMS_BSP}\n"
|
|
"Target Build Type: ${CMAKE_BUILD_TYPE}\n" "${TARGET_STRING}")
|
|
|
|
add_custom_command(
|
|
TARGET ${TARGET_NAME}
|
|
POST_BUILD
|
|
COMMAND ${CMAKE_SIZE} ${TARGET_NAME}
|
|
COMMENT ${POST_BUILD_COMMENT})
|
|
|
|
include("${RTEMS_CONFIG_DIR}/BuildType.cmake")
|
|
set_build_type()
|
|
|
|
# ##############################################################################
|
|
# Load RTEMS post-project configuration and checks
|
|
# ##############################################################################
|
|
include("${RTEMS_CONFIG_DIR}/RTEMSPostProjectConfig.cmake")
|
|
rtems_post_project_config(${TARGET_NAME})
|