2021-06-08 13:36:08 +02:00
|
|
|
################################################################################
|
|
|
|
# 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)
|
|
|
|
|
2022-05-05 20:55:48 +02:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
2021-06-08 13:36:08 +02:00
|
|
|
|
2021-07-13 18:58:54 +02:00
|
|
|
if(NOT FSFW_OSAL)
|
2022-05-02 09:33:39 +02:00
|
|
|
set(FSFW_OSAL host CACHE STRING "OS for the FSFW.")
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Project Name
|
2021-06-08 13:53:52 +02:00
|
|
|
project(fsfw-example-hosted C CXX)
|
2021-06-08 13:36:08 +02:00
|
|
|
|
2022-05-17 18:55:23 +02:00
|
|
|
option(OBSW_ENABLE_IPO "Enable IPO/LTO optimization" ON)
|
|
|
|
|
|
|
|
if(OBSW_ENABLE_IPO)
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif()
|
|
|
|
|
2021-06-08 13:36:08 +02:00
|
|
|
################################################################################
|
|
|
|
# Pre-Sources preparation
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Specify the C++ standard
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
|
|
|
|
# Set names and variables
|
2022-05-02 09:33:39 +02:00
|
|
|
set(TARGET_NAME ${CMAKE_PROJECT_NAME})
|
2021-06-08 13:36:08 +02:00
|
|
|
set(LIB_FSFW_NAME fsfw)
|
|
|
|
set(LIB_FSFW_HAL_NAME fsfw_hal)
|
|
|
|
|
|
|
|
# Set path names
|
|
|
|
set(FSFW_PATH fsfw)
|
2021-06-08 13:53:52 +02:00
|
|
|
set(COMMON_PATH example_common)
|
2021-06-08 13:36:08 +02:00
|
|
|
set(LIB_FSFW_HAL_PATH fsfw_hal)
|
|
|
|
|
2021-06-08 13:59:48 +02:00
|
|
|
set(BSP_PATH "bsp_hosted")
|
2021-06-08 13:36:08 +02:00
|
|
|
set(COMMON_CONFIG_PATH "${COMMON_PATH}/config")
|
|
|
|
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
|
2022-05-02 09:33:39 +02:00
|
|
|
set(FSFW_ADDITIONAL_INC_PATHS
|
|
|
|
"${COMMON_CONFIG_PATH}"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
CACHE STRING
|
|
|
|
"FSFW configuration paths"
|
|
|
|
)
|
2021-06-08 13:36:08 +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-19 18:30:24 +02:00
|
|
|
set(FSFW_ADD_MONITORING ON)
|
|
|
|
|
2021-06-08 13:36:08 +02:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2022-05-02 09:33:39 +02:00
|
|
|
set(WARNING_FLAGS
|
|
|
|
-Wall
|
|
|
|
-Wextra
|
|
|
|
-Wimplicit-fallthrough=1
|
|
|
|
-Wno-unused-parameter
|
|
|
|
-Wno-psabi
|
2021-06-08 13:36:08 +02:00
|
|
|
)
|
|
|
|
|
2022-05-02 09:33:39 +02:00
|
|
|
set(FSFW_WARNING_FLAGS ${WARNING_FLAGS})
|
2021-06-08 13:36:08 +02:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2022-05-02 09:33:39 +02:00
|
|
|
add_compile_options(/permissive- /d2SSAOptimizer-)
|
|
|
|
# To avoid nameclashes with min and max macro
|
|
|
|
add_compile_definitions(NOMINMAX)
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
|
|
|
|
2021-07-13 18:58:54 +02:00
|
|
|
if(FSFW_OSAL MATCHES linux)
|
2022-05-02 09:33:39 +02:00
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
# Hosted
|
2021-06-08 13:59:48 +02:00
|
|
|
else()
|
|
|
|
|
2022-05-02 09:33:39 +02:00
|
|
|
if(WIN32)
|
|
|
|
elseif(UNIX)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
endif()
|
2021-06-08 13:59:48 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2021-06-08 13:36:08 +02:00
|
|
|
################################################################################
|
|
|
|
# Executable and Sources
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Add executable
|
|
|
|
add_executable(${TARGET_NAME})
|
|
|
|
|
|
|
|
# Add subdirectories
|
|
|
|
if(LIB_OS_NAME)
|
2022-05-02 09:33:39 +02:00
|
|
|
add_subdirectory(${LIB_OS_NAME})
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
|
|
|
add_subdirectory(${BSP_PATH})
|
|
|
|
add_subdirectory(${FSFW_PATH})
|
|
|
|
add_subdirectory(${COMMON_PATH})
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Post-Sources preparation
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Add libraries for all sources.
|
|
|
|
target_link_libraries(${TARGET_NAME} PRIVATE
|
2022-05-02 09:33:39 +02:00
|
|
|
${LIB_FSFW_NAME}
|
|
|
|
${LIB_OS_NAME}
|
|
|
|
# ${LIB_FSFW_HAL_NAME}
|
|
|
|
)
|
2021-06-08 13:36:08 +02:00
|
|
|
|
|
|
|
# Add include paths for all sources.
|
|
|
|
target_include_directories(${TARGET_NAME} PRIVATE
|
2022-05-02 09:33:39 +02:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${FSFW_CONFIG_PATH}
|
|
|
|
)
|
2021-06-08 13:36:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
2022-05-02 09:33:39 +02:00
|
|
|
target_link_options(${TARGET_NAME} PRIVATE
|
|
|
|
"-Wl,-Map=${TARGET_NAME}.map"
|
2021-06-08 13:36:08 +02:00
|
|
|
)
|
|
|
|
|
2022-05-02 09:33:39 +02:00
|
|
|
# Remove unused sections.
|
|
|
|
target_compile_options(${TARGET_NAME} PRIVATE
|
|
|
|
"-ffunction-sections"
|
|
|
|
"-fdata-sections"
|
2021-06-08 13:36:08 +02:00
|
|
|
)
|
|
|
|
|
2022-05-02 09:33:39 +02:00
|
|
|
# Removed unused sections.
|
|
|
|
target_link_options(${TARGET_NAME} PRIVATE
|
|
|
|
"-Wl,--gc-sections"
|
2021-07-13 18:58:54 +02:00
|
|
|
)
|
2021-06-08 13:36:08 +02:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_VERBOSE)
|
2022-05-02 09:33:39 +02:00
|
|
|
message(STATUS "Warning flags: ${WARNING_FLAGS}")
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
2022-05-02 09:33:39 +02:00
|
|
|
|
2021-06-08 13:36:08 +02:00
|
|
|
|
|
|
|
# Compile options for all sources.
|
|
|
|
target_compile_options(${TARGET_NAME} PRIVATE
|
2022-05-02 09:33:39 +02:00
|
|
|
${WARNING_FLAGS}
|
|
|
|
)
|
2021-06-08 13:36:08 +02:00
|
|
|
|
|
|
|
if(NOT CMAKE_SIZE)
|
2022-05-02 09:33:39 +02:00
|
|
|
set(CMAKE_SIZE size)
|
|
|
|
if(WIN32)
|
|
|
|
set(FILE_SUFFIX ".exe")
|
|
|
|
endif()
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(TGT_BSP)
|
2022-05-02 09:33:39 +02:00
|
|
|
set(TARGET_STRING "Target BSP: ${TGT_BSP}")
|
2021-06-08 13:36:08 +02:00
|
|
|
else()
|
2022-05-02 09:33:39 +02:00
|
|
|
set(TARGET_STRING "Target BSP: Hosted")
|
2021-06-08 13:36:08 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
string(CONCAT POST_BUILD_COMMENT
|
2022-05-02 09:33:39 +02:00
|
|
|
"Build directory: ${CMAKE_BINARY_DIR}\n"
|
|
|
|
"Target OSAL: ${FSFW_OSAL}\n"
|
|
|
|
"Target Build Type: ${CMAKE_BUILD_TYPE}\n"
|
|
|
|
"${TARGET_STRING}"
|
|
|
|
)
|
2021-06-08 13:36:08 +02:00
|
|
|
|
|
|
|
add_custom_command(
|
2022-05-02 09:33:39 +02:00
|
|
|
TARGET ${TARGET_NAME}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX}
|
|
|
|
COMMENT ${POST_BUILD_COMMENT}
|
2021-06-08 13:36:08 +02:00
|
|
|
)
|
|
|
|
|
2022-05-05 20:55:48 +02:00
|
|
|
include (BuildType)
|
2021-06-08 13:36:08 +02:00
|
|
|
set_build_type()
|