fsfw-example-hosted/CMakeLists.txt

161 lines
4.5 KiB
CMake
Raw Normal View History

2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# CMake support for the Flight Software Framework
2022-05-20 08:39:16 +02:00
#
2021-06-08 13:36:08 +02:00
# Developed in an effort to replace Make with a modern build system.
2022-05-20 08:39:16 +02:00
#
2021-06-08 13:36:08 +02:00
# Author: R. Mueller
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Pre-Project preparation
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
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
2022-05-20 08:59:25 +02:00
set(OBSW_MAX_SCHEDULED_TCS 200)
2021-07-13 18:58:54 +02:00
if(NOT FSFW_OSAL)
2022-05-20 08:39:16 +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()
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Pre-Sources preparation
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Specify the C++ standard
2022-05-18 15:49:29 +02:00
set(CMAKE_CXX_STANDARD 17)
2021-06-08 13:36:08 +02:00
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
2022-05-20 08:39:16 +02:00
"${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-20 08:39:16 +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)
2022-05-20 08:39:16 +02:00
2022-05-02 09:33:39 +02:00
elseif(UNIX)
find_package(Threads REQUIRED)
endif()
2021-06-08 13:59:48 +02:00
endif()
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Executable and Sources
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Add executable
2022-05-20 08:43:22 +02:00
add_executable(${TARGET_NAME} example_common/config/common/definitions.h)
2021-06-08 13:36:08 +02:00
# 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})
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Post-Sources preparation
2022-05-20 08:39:16 +02:00
# ##############################################################################
2021-06-08 13:36:08 +02:00
# Add libraries for all sources.
2022-08-08 12:32:22 +02:00
target_link_libraries(${TARGET_NAME} PRIVATE ${LIB_FSFW_NAME} ${LIB_OS_NAME})
2021-06-08 13:36:08 +02:00
# Add include paths for all sources.
2022-05-20 08:39:16 +02:00
target_include_directories(
${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
2022-07-04 10:35:45 +02:00
${CMAKE_CURRENT_BINARY_DIR} ${FSFW_CONFIG_PATH})
2021-06-08 13:36:08 +02:00
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2022-05-20 08:39:16 +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.
2022-05-20 08:39:16 +02:00
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.
2022-05-20 08:39:16 +02:00
target_link_options(${TARGET_NAME} PRIVATE "-Wl,--gc-sections")
2021-06-08 13:36:08 +02:00
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
2022-05-20 08:39:16 +02:00
2021-06-08 13:36:08 +02:00
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.
2022-05-20 08:39:16 +02:00
target_compile_options(${TARGET_NAME} PRIVATE ${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()
2022-05-20 08:39:16 +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-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}
2022-05-20 08:39:16 +02:00
COMMENT ${POST_BUILD_COMMENT})
2021-06-08 13:36:08 +02:00
2022-05-20 08:39:16 +02:00
include(BuildType)
2021-06-08 13:36:08 +02:00
set_build_type()