fsfw/CMakeLists.txt

352 lines
10 KiB
CMake
Raw Permalink Normal View History

2020-12-07 01:40:10 +01:00
cmake_minimum_required(VERSION 3.13)
2022-02-02 18:41:44 +01:00
set(FSFW_VERSION 3)
set(FSFW_SUBVERSION 0)
2022-02-04 10:11:24 +01:00
set(FSFW_REVISION 1)
# Add the cmake folder so the FindSphinx module is found
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
2021-03-25 18:48:00 +01:00
option(FSFW_GENERATE_SECTIONS
"Generate function and data sections. Required to remove unused code" ON
)
if(FSFW_GENERATE_SECTIONS)
option(FSFW_REMOVE_UNUSED_CODE "Remove unused code" ON)
endif()
option(FSFW_BUILD_UNITTESTS "Build unittest binary in addition to static library" OFF)
option(FSFW_BUILD_DOCS "Build documentation with Sphinx and Doxygen" OFF)
if(FSFW_BUILD_UNITTESTS)
option(FSFW_TESTS_GEN_COV "Generate coverage data for unittests" ON)
endif()
2021-01-19 16:30:17 +01:00
option(FSFW_WARNING_SHADOW_LOCAL_GCC "Enable -Wshadow=local warning in GCC" ON)
# Options to exclude parts of the FSFW from compilation.
2021-07-14 10:22:58 +02:00
option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
2021-07-30 13:47:29 +02:00
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
2021-07-19 18:26:54 +02:00
# Optional sources
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
option(FSFW_ADD_MONITORING "Compile with monitoring components" ON)
option(FSFW_ADD_RMAP "Compile with RMAP" OFF)
option(FSFW_ADD_DATALINKLAYER "Compile with Data Link Layer" OFF)
option(FSFW_ADD_COORDINATES "Compile with coordinate components" OFF)
option(FSFW_ADD_TMSTORAGE "Compile with tm storage components" OFF)
# Contrib sources
2021-08-02 15:47:12 +02:00
option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
2021-01-19 16:30:17 +01:00
2020-12-07 01:40:10 +01:00
set(LIB_FSFW_NAME fsfw)
set(FSFW_TEST_TGT fsfw-tests)
set(FSFW_DUMMY_TGT fsfw-dummy)
project(${LIB_FSFW_NAME})
2020-12-07 01:40:10 +01:00
add_library(${LIB_FSFW_NAME})
if(FSFW_BUILD_UNITTESTS)
message(STATUS "Building the FSFW unittests in addition to the static library")
# Check whether the user has already installed Catch2 first
find_package(Catch2 3)
# Not installed, so use FetchContent to download and provide Catch2
if(NOT Catch2_FOUND)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.0.0-preview3
)
FetchContent_MakeAvailable(Catch2)
endif()
2021-10-11 14:56:42 +02:00
set(FSFW_CONFIG_PATH tests/src/fsfw_tests/unit/testcfg)
2021-10-11 15:07:52 +02:00
configure_file(tests/src/fsfw_tests/unit/testcfg/FSFWConfig.h.in FSFWConfig.h)
configure_file(tests/src/fsfw_tests/unit/testcfg/TestsConfig.h.in tests/TestsConfig.h)
2021-10-11 16:16:49 +02:00
2021-10-11 15:09:19 +02:00
project(${FSFW_TEST_TGT} CXX C)
add_executable(${FSFW_TEST_TGT})
if(FSFW_TESTS_GEN_COV)
message(STATUS "Generating coverage data for the library")
message(STATUS "Targets linking against ${LIB_FSFW_NAME} "
"will be compiled with coverage data as well"
)
include(FetchContent)
FetchContent_Declare(
cmake-modules
GIT_REPOSITORY https://github.com/bilke/cmake-modules.git
)
FetchContent_MakeAvailable(cmake-modules)
set(CMAKE_BUILD_TYPE "Debug")
list(APPEND CMAKE_MODULE_PATH ${cmake-modules_SOURCE_DIR})
include(CodeCoverage)
endif()
endif()
2021-07-13 20:22:54 +02:00
set(FSFW_CORE_INC_PATH "inc")
2020-12-07 01:40:10 +01:00
2021-07-13 18:53:07 +02:00
set_property(CACHE FSFW_OSAL PROPERTY STRINGS host linux rtems freertos)
2020-12-07 12:59:09 +01:00
# Configure Files
target_include_directories(${LIB_FSFW_NAME} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)
target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
)
2021-10-11 16:32:19 +02:00
2021-05-27 11:56:52 +02:00
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
elseif(${CMAKE_CXX_STANDARD} LESS 11)
message(FATAL_ERROR "Compiling the FSFW requires a minimum of C++11 support")
endif()
2021-07-13 18:58:31 +02:00
# Backwards comptability
2021-08-16 15:19:03 +02:00
if(OS_FSFW AND NOT FSFW_OSAL)
2021-07-13 18:58:31 +02:00
message(WARNING "Please pass the FSFW OSAL as FSFW_OSAL instead of OS_FSFW")
set(FSFW_OSAL OS_FSFW)
endif()
2021-07-13 18:53:07 +02:00
if(NOT FSFW_OSAL)
message(STATUS "No OS for FSFW via FSFW_OSAL set. Assuming host OS")
2020-12-17 11:46:50 +01:00
# Assume host OS and autodetermine from OS_FSFW
if(UNIX)
2021-07-13 18:53:07 +02:00
set(FSFW_OSAL "linux"
2020-12-17 11:46:50 +01:00
CACHE STRING
"OS abstraction layer used in the FSFW"
)
elseif(WIN32)
2021-07-13 18:53:07 +02:00
set(FSFW_OSAL "host"
2020-12-17 11:46:50 +01:00
CACHE STRING "OS abstraction layer used in the FSFW"
)
endif()
2020-12-17 20:18:16 +01:00
endif()
2020-12-17 11:46:50 +01:00
2021-07-14 10:22:58 +02:00
set(FSFW_OSAL_DEFINITION FSFW_OSAL_HOST)
2021-03-27 21:27:46 +01:00
2021-07-13 18:52:19 +02:00
if(FSFW_OSAL MATCHES host)
set(FSFW_OS_NAME "Host")
2021-08-16 11:23:44 +02:00
set(FSFW_OSAL_HOST ON)
2021-07-13 18:52:19 +02:00
elseif(FSFW_OSAL MATCHES linux)
set(FSFW_OS_NAME "Linux")
2021-08-16 11:23:44 +02:00
set(FSFW_OSAL_LINUX ON)
2021-07-13 18:52:19 +02:00
elseif(FSFW_OSAL MATCHES freertos)
set(FSFW_OS_NAME "FreeRTOS")
2021-08-16 11:23:44 +02:00
set(FSFW_OSAL_FREERTOS ON)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
${LIB_OS_NAME}
2021-08-16 11:23:44 +02:00
)
2021-07-13 18:52:19 +02:00
elseif(FSFW_OSAL STREQUAL rtems)
set(FSFW_OS_NAME "RTEMS")
2021-08-16 11:23:44 +02:00
set(FSFW_OSAL_RTEMS ON)
2020-12-07 12:59:09 +01:00
else()
2021-08-16 11:23:44 +02:00
message(WARNING
"Invalid operating system for FSFW specified! Setting to host.."
)
set(FSFW_OS_NAME "Host")
2021-08-16 11:23:44 +02:00
set(OS_FSFW "host")
2020-12-07 12:59:09 +01:00
endif()
if(FSFW_BUILD_UNITTESTS OR FSFW_BUILD_DOCS)
2021-10-27 17:10:37 +02:00
configure_file(src/fsfw/FSFW.h.in fsfw/FSFW.h)
configure_file(src/fsfw/FSFWVersion.h.in fsfw/FSFWVersion.h)
else()
configure_file(src/fsfw/FSFW.h.in FSFW.h)
configure_file(src/fsfw/FSFWVersion.h.in FSFWVersion.h)
endif()
message(STATUS "Compiling FSFW for the ${FSFW_OS_NAME} operating system.")
2020-12-07 12:59:09 +01:00
2021-07-13 18:52:19 +02:00
add_subdirectory(src)
2021-07-14 10:22:58 +02:00
add_subdirectory(tests)
2021-07-30 13:47:29 +02:00
if(FSFW_ADD_HAL)
add_subdirectory(hal)
endif()
2021-07-14 11:03:42 +02:00
add_subdirectory(contrib)
if(FSFW_BUILD_DOCS)
add_subdirectory(docs)
endif()
2020-12-07 01:40:10 +01:00
if(FSFW_BUILD_UNITTESTS)
if(FSFW_TESTS_GEN_COV)
if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
# Remove quotes.
separate_arguments(COVERAGE_COMPILER_FLAGS
NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}"
)
# Add compile options manually, we don't want coverage for Catch2
target_compile_options(${FSFW_TEST_TGT} PRIVATE
"${COVERAGE_COMPILER_FLAGS}"
)
target_compile_options(${LIB_FSFW_NAME} PRIVATE
"${COVERAGE_COMPILER_FLAGS}"
)
# Exclude directories here
if(WIN32)
set(GCOVR_ADDITIONAL_ARGS
"--exclude-throw-branches"
"--exclude-unreachable-branches"
)
set(COVERAGE_EXCLUDES
"/c/msys64/mingw64/*"
)
elseif(UNIX)
set(COVERAGE_EXCLUDES
"/usr/include/*" "/usr/bin/*" "Catch2/*"
2021-10-11 17:28:07 +02:00
"/usr/local/include/*" "*/fsfw_tests/*"
2021-10-11 17:51:13 +02:00
"*/catch2-src/*"
)
endif()
target_link_options(${FSFW_TEST_TGT} PRIVATE
-fprofile-arcs
-ftest-coverage
)
target_link_options(${LIB_FSFW_NAME} PRIVATE
-fprofile-arcs
-ftest-coverage
)
# Need to specify this as an interface, otherwise there will the compile issues
target_link_options(${LIB_FSFW_NAME} INTERFACE
-fprofile-arcs
-ftest-coverage
)
if(WIN32)
setup_target_for_coverage_gcovr_html(
NAME ${FSFW_TEST_TGT}_coverage
EXECUTABLE ${FSFW_TEST_TGT}
DEPENDENCIES ${FSFW_TEST_TGT}
)
else()
setup_target_for_coverage_lcov(
NAME ${FSFW_TEST_TGT}_coverage
EXECUTABLE ${FSFW_TEST_TGT}
DEPENDENCIES ${FSFW_TEST_TGT}
)
endif()
endif()
endif()
target_link_libraries(${FSFW_TEST_TGT} PRIVATE Catch2::Catch2 ${LIB_FSFW_NAME})
endif()
2020-12-07 01:40:10 +01:00
# The project CMakeLists file has to set the FSFW_CONFIG_PATH and add it.
# If this is not given, we include the default configuration and emit a warning.
if(NOT FSFW_CONFIG_PATH)
2021-10-11 13:57:00 +02:00
set(DEF_CONF_PATH misc/defaultcfg/fsfwconfig)
if(NOT FSFW_BUILD_DOCS)
message(WARNING "Flight Software Framework configuration path not set!")
message(WARNING "Setting default configuration from ${DEF_CONF_PATH} ..")
endif()
2021-10-11 13:57:00 +02:00
add_subdirectory(${DEF_CONF_PATH})
2021-10-11 15:03:03 +02:00
set(FSFW_CONFIG_PATH ${DEF_CONF_PATH})
2020-12-07 01:40:10 +01:00
endif()
2020-12-19 02:29:22 +01:00
# FSFW might be part of a possibly complicated folder structure, so we
# extract the absolute path of the fsfwconfig folder.
if(IS_ABSOLUTE ${FSFW_CONFIG_PATH})
2020-12-19 12:10:29 +01:00
set(FSFW_CONFIG_PATH_ABSOLUTE ${FSFW_CONFIG_PATH})
2020-12-19 02:29:22 +01:00
else()
2020-12-19 12:10:29 +01:00
get_filename_component(FSFW_CONFIG_PATH_ABSOLUTE
${FSFW_CONFIG_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR}
2020-12-19 02:29:22 +01:00
)
endif()
2021-05-31 16:46:32 +02:00
foreach(INCLUDE_PATH ${FSFW_ADDITIONAL_INC_PATHS})
if(IS_ABSOLUTE ${INCLUDE_PATH})
2021-05-31 17:00:51 +02:00
set(CURR_ABS_INC_PATH "${INCLUDE_PATH}")
else()
get_filename_component(CURR_ABS_INC_PATH
${INCLUDE_PATH} REALPATH BASE_DIR ${CMAKE_SOURCE_DIR})
endif()
if(CMAKE_VERBOSE)
message(STATUS "FSFW include path: ${CURR_ABS_INC_PATH}")
endif()
list(APPEND FSFW_ADD_INC_PATHS_ABS ${CURR_ABS_INC_PATH})
endforeach()
2021-01-13 11:47:04 +01:00
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2021-01-13 21:35:17 +01:00
if(NOT DEFINED FSFW_WARNING_FLAGS)
set(FSFW_WARNING_FLAGS
-Wall
-Wextra
-Wimplicit-fallthrough=1
-Wno-unused-parameter
-Wno-psabi
)
2021-01-19 16:39:12 +01:00
endif()
2021-03-25 18:48:00 +01:00
if(FSFW_GENERATE_SECTIONS)
target_compile_options(${LIB_FSFW_NAME} PRIVATE
"-ffunction-sections"
"-fdata-sections"
)
endif()
if(FSFW_REMOVE_UNUSED_CODE)
target_link_options(${LIB_FSFW_NAME} PRIVATE
"Wl,--gc-sections"
)
endif()
2021-01-19 16:39:12 +01:00
if(FSFW_WARNING_SHADOW_LOCAL_GCC)
list(APPEND WARNING_FLAGS "-Wshadow=local")
endif()
2021-01-19 16:13:10 +01:00
2020-12-20 15:32:03 +01:00
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(COMPILER_FLAGS "/permissive-")
endif()
2020-12-20 13:21:12 +01:00
2020-12-07 01:40:10 +01:00
# Required include paths to compile the FSFW
2020-12-19 02:29:22 +01:00
target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_SOURCE_DIR}
${FSFW_CONFIG_PATH_ABSOLUTE}
2021-07-13 20:22:54 +02:00
${FSFW_CORE_INC_PATH}
${FSFW_ADD_INC_PATHS_ABS}
2020-12-19 02:29:22 +01:00
)
# Includes path required to compile FSFW itself as well
# We assume that the fsfwconfig folder uses include relative to the project
# root here!
target_include_directories(${LIB_FSFW_NAME} PRIVATE
${CMAKE_SOURCE_DIR}
${FSFW_CONFIG_PATH_ABSOLUTE}
2021-07-13 20:22:54 +02:00
${FSFW_CORE_INC_PATH}
${FSFW_ADD_INC_PATHS_ABS}
2020-12-07 01:40:10 +01:00
)
2020-12-19 18:38:02 +01:00
target_compile_options(${LIB_FSFW_NAME} PRIVATE
2021-01-13 21:35:17 +01:00
${FSFW_WARNING_FLAGS}
2020-12-20 15:32:03 +01:00
${COMPILER_FLAGS}
2020-12-19 18:38:02 +01:00
)
target_link_libraries(${LIB_FSFW_NAME} PRIVATE
${FSFW_ADDITIONAL_LINK_LIBS}
)
string(CONCAT POST_BUILD_COMMENT
"######################################################################\n"
2021-10-11 16:06:12 +02:00
"Built FSFW v${FSFW_VERSION}.${FSFW_SUBVERSION}.${FSFW_REVISION}, "
"Target OSAL: ${FSFW_OS_NAME}\n"
"######################################################################\n"
)
add_custom_command(
TARGET ${LIB_FSFW_NAME}
POST_BUILD
COMMENT ${POST_BUILD_COMMENT}
)