eive-obsw/CMakeLists.txt

359 lines
9.2 KiB
CMake
Raw Normal View History

2020-12-29 01:09:59 +01:00
################################################################################
# CMake support for the EIVE OBSW
#
# 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
2021-06-30 15:18:41 +02:00
if(TGT_BSP MATCHES "arm/q7s")
2022-02-05 13:19:20 +01:00
option(EIVE_BUILD_WATCHDOG "Compile the OBSW watchdog instead" OFF)
2021-07-29 11:35:20 +02:00
option(BUILD_Q7S_SIMPLE_MODE OFF "Simple mode with a minimal main function")
2021-06-30 15:18:41 +02:00
endif()
2021-09-29 09:12:57 +02:00
option(EIVE_BUILD_UNITTESTS "Build Catch2 unittests" OFF)
option(EIVE_ADD_ETL_LIB "Add ETL library" ON)
2021-09-29 09:14:17 +02:00
option(EIVE_ADD_JSON_LIB "Add JSON library" ON)
2021-07-30 16:40:24 +02:00
option(EIVE_SYSROOT_MAGIC "Perform sysroot magic which might not be necessary" OFF)
2021-07-15 01:25:32 +02:00
if(NOT FSFW_OSAL)
set(FSFW_OSAL host CACHE STRING "OS for the FSFW.")
2020-12-29 01:09:59 +01:00
endif()
2021-05-05 20:25:52 +02:00
if(TGT_BSP MATCHES "arm/raspberrypi" OR TGT_BSP MATCHES "arm/beagleboneblack")
option(LINUX_CROSS_COMPILE ON)
endif()
2020-12-29 01:09:59 +01:00
# Perform steps like loading toolchain files where applicable.
include(${CMAKE_SCRIPT_PATH}/PreProjectConfig.cmake)
pre_project_config()
2021-09-29 10:52:36 +02:00
if(EIVE_BUILD_WATCHDOG)
set(PROJECT_NAME_TO_SET eive-watchdog)
elseif(EIVE_BUILD_UNITTESTS)
set(PROJECT_NAME_TO_SET eive-unittest)
elseif(TGT_BSP MATCHES "arm/q7s")
2021-09-29 09:37:29 +02:00
set(PROJECT_NAME_TO_SET eive-obsw-$ENV{USERNAME})
else()
set(PROJECT_NAME_TO_SET eive-obsw)
endif()
2020-12-29 01:09:59 +01:00
# Project Name
2021-07-29 11:35:20 +02:00
project(${PROJECT_NAME_TO_SET} 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)
set(LIB_LWGPS_NAME lwgps)
set(LIB_ARCSEC wire)
set(THIRD_PARTY_FOLDER thirdparty)
2021-07-08 12:13:38 +02:00
set(LIB_CXX_FS -lstdc++fs)
2021-09-29 09:30:58 +02:00
set(LIB_CATCH2 Catch2)
2022-01-15 13:05:11 +01:00
set(LIB_GPS gps)
set(LIB_JSON_NAME nlohmann_json::nlohmann_json)
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-09-29 09:30:58 +02:00
set(UNITTEST_PATH unittest)
2021-02-14 12:35:08 +01:00
set(LINUX_PATH linux)
set(COMMON_PATH common)
2021-07-29 11:35:20 +02:00
set(WATCHDOG_PATH watchdog)
2021-06-08 17:04:28 +02:00
set(COMMON_CONFIG_PATH ${COMMON_PATH}/config)
2021-09-29 10:52:36 +02:00
set(UNITTEST_CFG_PATH ${UNITTEST_PATH}/testcfg)
2021-09-29 09:30:58 +02:00
set(LIB_CSP_PATH ${THIRD_PARTY_FOLDER}/libcsp)
set(LIB_ETL_PATH ${THIRD_PARTY_FOLDER}/etl)
set(LIB_CATCH2_PATH ${THIRD_PARTY_FOLDER}/Catch2)
set(LIB_LWGPS_PATH ${THIRD_PARTY_FOLDER}/lwgps)
set(LIB_ARCSEC_PATH ${THIRD_PARTY_FOLDER}/arcsec_star_tracker)
set(LIB_JSON_PATH ${THIRD_PARTY_FOLDER}/json)
2020-12-29 01:09:59 +01:00
2021-01-19 16:35:44 +01:00
set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF)
2021-09-29 09:30:58 +02:00
set(EIVE_ADD_LINUX_FILES False)
2021-09-29 10:52:36 +02:00
if(EIVE_BUILD_UNITTESTS)
endif()
2021-10-11 19:43:44 +02:00
if(FSFW_ADD_UNITTESTS)
2021-09-29 09:30:58 +02:00
set(CATCH2_TARGET Catch2)
endif()
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-07-15 01:28:25 +02:00
if(TGT_BSP MATCHES "arm/q7s" OR TGT_BSP MATCHES "arm/raspberrypi"
2022-02-05 13:19:20 +01:00
OR TGT_BSP MATCHES "arm/beagleboneblack" OR TGT_BSP MATCHES "arm/egse"
2021-05-05 20:25:52 +02:00
)
2021-05-17 20:03:56 +02:00
set(FSFW_CONFIG_PATH "linux/fsfwconfig")
2021-07-29 11:35:20 +02:00
if(NOT BUILD_Q7S_SIMPLE_MODE)
2021-09-29 09:30:58 +02:00
set(EIVE_ADD_LINUX_FILES TRUE)
2021-06-30 15:32:15 +02:00
set(ADD_CSP_LIB TRUE)
set(FSFW_HAL_ADD_LINUX ON)
endif()
2021-02-14 15:01:04 +01:00
endif()
2022-02-05 13:19:20 +01:00
if(TGT_BSP MATCHES "arm/raspberrypi" )
2021-07-29 16:31:04 +02:00
# Used by configure file
set(RASPBERRY_PI ON)
2021-03-23 16:15:31 +01:00
set(FSFW_HAL_ADD_RASPBERRY_PI ON)
endif()
2022-02-05 13:19:20 +01:00
if(TGT_BSP MATCHES "arm/egse")
# Used by configure file
set(EGSE ON)
2022-02-05 17:19:00 +01:00
set(FSFW_HAL_LINUX_ADD_LIBGPIOD OFF)
2022-02-05 13:19:20 +01:00
endif()
2021-08-23 20:38:18 +02:00
if(TGT_BSP MATCHES "arm/beagleboneblack")
2021-07-29 16:31:04 +02:00
# Used by configure file
set(BEAGLEBONEBLACK ON)
2021-05-05 20:25:52 +02:00
endif()
2021-08-23 20:38:18 +02:00
if(TGT_BSP MATCHES "arm/q7s")
2021-07-29 16:31:04 +02:00
# Used by configure file
set(XIPHOS_Q7S ON)
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-05-17 16:22:51 +02:00
2021-09-29 10:52:36 +02:00
if(EIVE_BUILD_UNITTESTS)
2021-10-11 19:43:44 +02:00
# configure_file(${UNITTEST_CFG_PATH}/TestsConfig.h.in TestsConfig.h)
# set(FSFW_CONFIG_PATH ${UNITTEST_CFG_PATH})
2021-09-29 10:52:36 +02:00
endif()
2021-06-08 17:04:28 +02:00
# Configuration files
if(NOT EIVE_BUILD_WATCHDOG)
2021-07-29 11:35:20 +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-08-23 20:38:18 +02:00
if(TGT_BSP MATCHES "arm/q7s")
2021-07-29 11:35:20 +02:00
configure_file(${BSP_PATH}/boardconfig/q7sConfig.h.in q7sConfig.h)
2022-02-05 13:19:20 +01:00
elseif(TGT_BSP MATCHES "arm/raspberrypi" OR TGT_BSP MATCHES "arm/egse")
2021-07-29 11:35:20 +02:00
configure_file(${BSP_PATH}/boardconfig/rpiConfig.h.in rpiConfig.h)
endif()
2021-06-08 17:04:28 +02:00
endif()
2021-09-29 10:52:36 +02:00
2021-07-29 13:07:07 +02:00
configure_file(${WATCHDOG_PATH}/watchdogConf.h.in watchdogConf.h)
2021-06-08 17:04:28 +02:00
2021-05-17 16:53:06 +02:00
# Set common config path for FSFW
2021-06-08 17:04:28 +02:00
set(FSFW_ADDITIONAL_INC_PATHS
"${COMMON_PATH}/config"
${CMAKE_CURRENT_BINARY_DIR}
)
2020-12-29 01:09:59 +01:00
################################################################################
# Executable and Sources
################################################################################
# Add executable
add_executable(${TARGET_NAME})
2021-09-29 09:12:57 +02:00
if(EIVE_ADD_ETL_LIB)
2021-09-29 09:30:58 +02:00
add_subdirectory(${LIB_ETL_PATH})
2020-12-29 01:28:21 +01:00
endif()
2021-09-29 09:14:17 +02:00
if(EIVE_ADD_JSON_LIB)
add_subdirectory(${LIB_JSON_PATH})
endif()
if(NOT EIVE_BUILD_WATCHDOG)
2021-09-29 10:52:36 +02:00
if(NOT EIVE_BUILD_UNITTESTS)
if(EIVE_ADD_LINUX_FILES)
2021-12-08 17:23:35 +01:00
add_subdirectory(${LIB_ARCSEC_PATH})
2021-09-29 10:52:36 +02:00
add_subdirectory(${LINUX_PATH})
endif()
add_subdirectory(${BSP_PATH})
if(ADD_CSP_LIB)
add_subdirectory(${LIB_CSP_PATH})
endif()
2021-07-29 11:35:20 +02:00
endif()
add_subdirectory(${COMMON_PATH})
endif()
2020-12-29 01:09:59 +01:00
if((NOT BUILD_Q7S_SIMPLE_MODE) AND (NOT EIVE_BUILD_WATCHDOG))
2021-09-29 09:30:58 +02:00
add_subdirectory(${LIB_LWGPS_PATH})
2021-06-30 15:32:15 +02:00
add_subdirectory(${FSFW_PATH})
add_subdirectory(${MISSION_PATH})
add_subdirectory(${TEST_PATH})
2021-09-29 09:30:58 +02:00
endif()
2021-09-29 10:52:36 +02:00
if(EIVE_BUILD_UNITTESTS)
2021-10-11 19:44:58 +02:00
# add_subdirectory(${LIB_CATCH2_PATH})
2021-09-29 09:30:58 +02:00
add_subdirectory(${UNITTEST_PATH})
2021-06-30 15:32:15 +02:00
endif()
if(EIVE_BUILD_WATCHDOG)
2021-07-29 11:35:20 +02:00
add_subdirectory(${WATCHDOG_PATH})
endif()
2021-06-30 15:32:15 +02:00
2020-12-29 01:09:59 +01:00
################################################################################
# Post-Sources preparation
################################################################################
2021-07-15 01:25:32 +02:00
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux)
2020-12-29 18:12:05 +01:00
if((NOT BUILD_Q7S_SIMPLE_MODE) AND (NOT EIVE_BUILD_WATCHDOG))
2021-06-30 15:32:15 +02:00
# Add libraries for all sources.
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_FSFW_NAME}
${LIB_OS_NAME}
${LIB_LWGPS_NAME}
)
2021-08-11 18:13:43 +02:00
if(TGT_BSP MATCHES "arm/q7s")
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_ARCSEC}
2022-01-15 13:05:11 +01:00
${LIB_GPS}
2021-08-11 18:13:43 +02:00
)
endif()
2021-06-30 15:32:15 +02:00
endif()
2020-12-29 01:09:59 +01:00
2021-09-29 09:30:58 +02:00
if(NOT EIVE_BUILD_WATCHDOG)
2021-07-29 18:21:05 +02:00
if(ADD_CSP_LIB)
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_CSP_NAME}
)
endif()
endif()
2021-09-29 09:12:57 +02:00
if(EIVE_ADD_ETL_LIB)
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_ETL_NAME}
)
endif()
2021-09-29 09:14:17 +02:00
if(EIVE_ADD_JSON_LIB)
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_JSON_NAME}
)
endif()
2021-09-29 10:52:36 +02:00
if(EIVE_BUILD_UNITTESTS)
2021-09-29 09:30:58 +02:00
target_link_libraries(${TARGET_NAME} PRIVATE
${CATCH2_TARGET}
)
endif()
2021-07-29 11:35:20 +02:00
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_CXX_FS}
)
2022-02-05 13:19:20 +01:00
if(TGT_BSP MATCHES "arm/egse")
target_link_libraries(${TARGET_NAME} PRIVATE
${LIB_ARCSEC}
)
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}
2021-06-08 17:04:28 +02:00
${CMAKE_CURRENT_BINARY_DIR}
2021-09-29 09:30:58 +02:00
${LIB_ARCSEC_PATH}
2020-12-29 01:09:59 +01:00
)
2022-02-05 13:19:20 +01:00
if(TGT_BSP MATCHES "arm/q7s" OR TGT_BSP MATCHES "arm/egse")
2021-08-11 18:13:43 +02:00
target_include_directories(${TARGET_NAME} PRIVATE
${ARCSEC_LIB_PATH}
)
endif()
2020-12-29 01:09:59 +01:00
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(EIVE_BUILD_WATCHDOG)
2021-07-29 11:35:20 +02:00
set(TARGET_STRING "OBSW Watchdog")
2020-12-29 01:09:59 +01:00
else()
2021-07-29 11:35:20 +02:00
if(TGT_BSP)
set(TARGET_STRING "Target BSP: ${TGT_BSP}")
else()
set(TARGET_STRING "Target BSP: Hosted")
endif()
2020-12-29 01:09:59 +01:00
endif()
2021-02-03 13:38:04 +01:00
string(CONCAT POST_BUILD_COMMENT
"Build directory: ${CMAKE_BINARY_DIR}\n"
2021-07-15 01:25:32 +02:00
"Target OSAL: ${FSFW_OSAL}\n"
2021-02-03 13:38:04 +01:00
"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()