eive-obsw/CMakeLists.txt

223 lines
5.2 KiB
CMake
Raw Normal View History

2020-12-29 01:09:59 +01:00
################################################################################
# CMake support for the EIVE OBSW
#
# 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)
2020-12-29 14:21:52 +01:00
set(CMAKE_SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2020-12-29 01:09:59 +01:00
option(ADD_ETL_LIB "Add ETL library" ON)
2020-12-29 01:09:59 +01:00
if(NOT OS_FSFW)
set(OS_FSFW host CACHE STRING "OS for the FSFW.")
endif()
# Perform steps like loading toolchain files where applicable.
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
pre_project_config()
# Project Name
2020-12-29 02:15:04 +01:00
project(eive_obsw ASM C CXX)
2020-12-29 01:09:59 +01:00
################################################################################
# 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_ETL_NAME etl)
2020-12-29 14:14:11 +01:00
set(LIB_CSP_NAME libcsp)
2021-02-27 21:24:19 +01:00
set(LIB_LWGPS_NAME lwgps)
set(THIRD_PARTY_FOLDER thirdparty)
2020-12-29 01:09:59 +01:00
# Set path names
set(FSFW_PATH fsfw)
set(MISSION_PATH mission)
2021-02-14 09:25:40 +01:00
set(TEST_PATH test/testtasks)
2021-02-14 12:35:08 +01:00
set(LINUX_PATH linux)
2021-02-27 21:24:19 +01:00
set(COMMON_PATH common)
2020-12-29 01:09:59 +01:00
set(CSP_LIB_PATH ${THIRD_PARTY_FOLDER}/libcsp)
set(ETL_LIB_PATH ${THIRD_PARTY_FOLDER}/etl)
set(LWGPS_LIB_PATH ${THIRD_PARTY_FOLDER}/lwgps)
2021-01-19 16:35:44 +01:00
set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF)
2021-02-14 12:35:08 +01:00
set(ADD_LINUX_FILES FALSE)
2020-12-29 18:06:52 +01:00
2020-12-29 01:09:59 +01:00
# 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()
2020-12-29 13:59:31 +01:00
if(TGT_BSP)
2021-02-14 15:01:04 +01:00
if(${TGT_BSP} MATCHES "arm/q7s" OR ${TGT_BSP} MATCHES "arm/raspberrypi")
set(ROOT_CONFIG_FOLDER TRUE)
set(FSFW_CONFIG_PATH "fsfwconfig")
2021-02-14 14:55:33 +01:00
set(ADD_LINUX_FILES TRUE)
set(ADD_CSP_LIB TRUE)
2021-02-14 15:01:04 +01:00
endif()
2021-02-22 12:45:10 +01:00
if(${TGT_BSP} MATCHES "arm/raspberrypi")
add_definitions(-DRASPBERRY_PI)
endif()
if(${TGT_BSP} MATCHES "arm/q7s")
add_definitions(-DXIPHOS_Q7S)
endif()
2020-12-29 01:26:22 +01:00
else()
2021-02-14 15:01:04 +01:00
# Required by FSFW library
set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig")
2020-12-29 01:26:22 +01:00
endif()
2021-02-27 21:24:19 +01:00
# Set for lwgps library
set(LWGPS_CONFIG_PATH "${COMMON_PATH}/config")
2020-12-29 01:09:59 +01:00
################################################################################
# Executable and Sources
################################################################################
# Add executable
add_executable(${TARGET_NAME})
# Add subdirectories
2020-12-29 13:59:31 +01:00
if(ROOT_CONFIG_FOLDER)
2021-02-14 15:01:04 +01:00
add_subdirectory(${FSFW_CONFIG_PATH})
2020-12-29 01:09:59 +01:00
endif()
2020-12-29 01:26:22 +01:00
2020-12-29 13:59:31 +01:00
if(ADD_CSP_LIB)
add_subdirectory(${CSP_LIB_PATH})
endif()
if(ADD_ETL_LIB)
add_subdirectory(${ETL_LIB_PATH})
2020-12-29 01:28:21 +01:00
endif()
2021-02-14 12:35:08 +01:00
if(ADD_LINUX_FILES)
add_subdirectory(${LINUX_PATH})
endif()
2021-02-27 21:24:19 +01:00
add_subdirectory(${LWGPS_LIB_PATH})
2020-12-29 01:09:59 +01:00
add_subdirectory(${BSP_PATH})
add_subdirectory(${FSFW_PATH})
add_subdirectory(${MISSION_PATH})
2021-02-14 09:25:40 +01:00
add_subdirectory(${TEST_PATH})
2021-02-27 21:24:19 +01:00
add_subdirectory(${COMMON_PATH})
2020-12-29 01:09:59 +01:00
################################################################################
# Post-Sources preparation
################################################################################
2020-12-29 18:12:05 +01:00
set_property(CACHE OS_FSFW PROPERTY STRINGS host linux)
2020-12-29 01:09:59 +01:00
# Add libraries for all sources.
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_FSFW_NAME}
${LIB_OS_NAME}
2021-02-27 21:24:19 +01:00
${LIB_LWGPS_NAME}
2020-12-29 01:09:59 +01:00
)
if(ADD_ETL_LIB)
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_ETL_NAME}
)
endif()
2020-12-29 14:14:11 +01:00
if(ADD_CSP_LIB)
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_CSP_NAME}
)
endif()
2020-12-29 01:09:59 +01:00
# Add include paths for all sources.
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${FSFW_CONFIG_PATH}
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNING_FLAGS
-Wall
-Wextra
-Wimplicit-fallthrough=1
-Wno-unused-parameter
-Wno-psabi
)
# Remove unused sections.
target_compile_options(${TARGET_NAME} PRIVATE
"-ffunction-sections"
"-fdata-sections"
)
# Removed unused sections.
target_link_options(${TARGET_NAME} PRIVATE
"-Wl,--gc-sections"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(COMPILER_FLAGS "/permissive-")
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()
2021-02-03 13:38:04 +01:00
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}"
)
2020-12-29 01:09:59 +01:00
add_custom_command(
TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX}
2021-02-03 13:38:04 +01:00
COMMENT ${POST_BUILD_COMMENT}
2020-12-29 01:09:59 +01:00
)
include (${CMAKE_SCRIPT_PATH}/BuildType.cmake)
set_build_type()