adapting cmakelists
This commit is contained in:
parent
3a3a3f476c
commit
5405359ff6
203
CMakeLists.txt
Normal file
203
CMakeLists.txt
Normal file
@ -0,0 +1,203 @@
|
||||
################################################################################
|
||||
# CMake support for the Flight Software Framework
|
||||
#
|
||||
# Developed in an effort to replace Make with a modern build system.
|
||||
#
|
||||
# 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")
|
||||
|
||||
if(NOT OS_FSFW)
|
||||
set(OS_FSFW host CACHE STRING "OS for the FSFW.")
|
||||
endif()
|
||||
|
||||
if(TGT_BSP MATCHES "arm/raspberrypi" OR TGT_BSP MATCHES "arm/beagleboneblack")
|
||||
option(LINUX_CROSS_COMPILE OFF)
|
||||
set(FSFW_HAL_ADD_LINUX ON)
|
||||
endif()
|
||||
|
||||
# Perform steps like loading toolchain files where applicable.
|
||||
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
|
||||
pre_project_config()
|
||||
|
||||
# Project Name
|
||||
project(fsfw_example ASM C CXX)
|
||||
|
||||
|
||||
################################################################################
|
||||
# Pre-Sources preparation
|
||||
################################################################################
|
||||
|
||||
# Specify the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
|
||||
# Set names and variables
|
||||
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
|
||||
set(LIB_FSFW_NAME fsfw)
|
||||
set(LIB_FSFW_HAL_NAME fsfw_hal)
|
||||
|
||||
# Set path names
|
||||
set(FSFW_PATH fsfw)
|
||||
set(COMMON_PATH example_common)
|
||||
set(LIB_FSFW_HAL_PATH fsfw_hal)
|
||||
|
||||
# Analyse different OS and architecture/target options, determine BSP_PATH,
|
||||
# display information about compiler etc.
|
||||
include (${CMAKE_SCRIPT_PATH}/HardwareOsPreConfig.cmake)
|
||||
pre_source_hw_os_config()
|
||||
|
||||
set(COMMON_CONFIG_PATH "${COMMON_PATH}/config")
|
||||
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
|
||||
set(FSFW_ADDITIONAL_INC_PATHS
|
||||
"${COMMON_CONFIG_PATH}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
CACHE STRING
|
||||
"FSFW configuration paths"
|
||||
)
|
||||
|
||||
if(TGT_BSP MATCHES "arm/stm32h743zi-nucleo")
|
||||
# TODO: This works but is a horrible mess. In the future, stm32-cmake support will be used and
|
||||
# linked against, so we have a clean interface which can be used by FSFW HAL.
|
||||
set(FSFW_HAL_ADDITIONAL_INC_PATHS
|
||||
${BOARD_CONFIG_PATH}
|
||||
"${BSP_PATH}/STM32CubeH7/Drivers/BSP/STM32H7xx_Nucleo"
|
||||
CACHE STRING
|
||||
"FSFW HAL configuration paths"
|
||||
)
|
||||
endif()
|
||||
|
||||
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)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set(WARNING_FLAGS
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wimplicit-fallthrough=1
|
||||
-Wno-unused-parameter
|
||||
-Wno-psabi
|
||||
)
|
||||
|
||||
set(SHADOW_LOCAL_WARNING ON)
|
||||
if(TGT_BSP MATCHES "arm/raspberrypi" OR TGT_BSP MATCHES "arm/beagleboneblack")
|
||||
set(SHADOW_LOCAL_WARNING OFF)
|
||||
endif()
|
||||
|
||||
if(SHADOW_LOCAL_WARNING)
|
||||
# Some older compilers emit odd warnings if this is used.
|
||||
set(WARNING_FLAGS ${WARNING_FLAGS} -Wshadow=local)
|
||||
endif()
|
||||
|
||||
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})
|
||||
add_subdirectory(${LIB_FSFW_HAL_PATH})
|
||||
|
||||
################################################################################
|
||||
# Post-Sources preparation
|
||||
################################################################################
|
||||
|
||||
# Add libraries for all sources.
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE
|
||||
${LIB_FSFW_NAME}
|
||||
${LIB_OS_NAME}
|
||||
${LIB_FSFW_HAL_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 ${OS_FSFW} 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(CMAKE_CROSSCOMPILING)
|
||||
include(${CMAKE_SCRIPT_PATH}/HardwareOsPostConfig.cmake)
|
||||
post_source_hw_os_config()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SIZE)
|
||||
set(CMAKE_SIZE size)
|
||||
if(WIN32)
|
||||
set(FILE_SUFFIX ".exe")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
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: ${OS_FSFW}\n"
|
||||
"Target Build Type: ${CMAKE_BUILD_TYPE}\n"
|
||||
"${TARGET_STRING}"
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX}
|
||||
COMMENT ${POST_BUILD_COMMENT}
|
||||
)
|
||||
|
||||
include (${CMAKE_SCRIPT_PATH}/BuildType.cmake)
|
||||
set_build_type()
|
@ -1,55 +1,5 @@
|
||||
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 ""
|
||||
|
@ -1,24 +1,11 @@
|
||||
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)
|
||||
if(${OS_FSFW} STREQUAL linux)
|
||||
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()
|
||||
message(FATAL_ERROR "OS_FSFW not valid, only Linux is allowed!")
|
||||
endif()
|
||||
|
||||
# Cross-compile information
|
||||
@ -51,119 +38,11 @@ if(CMAKE_CROSSCOMPILING)
|
||||
)
|
||||
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")
|
||||
if(${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)
|
||||
|
||||
|
@ -16,67 +16,10 @@ if(DEFINED TGT_BSP)
|
||||
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(${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)
|
||||
@ -110,6 +53,7 @@ elseif(${OS_FSFW} STREQUAL linux AND TGT_BSP)
|
||||
"$ENV{RASPBERRY_VERSION}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LINUX_CROSS_COMPILE)
|
||||
set(CMAKE_TOOLCHAIN_FILE
|
||||
"${CMAKE_SCRIPT_PATH}/RPiCrossCompileConfig.cmake"
|
||||
|
Loading…
Reference in New Issue
Block a user