Merge pull request 'Add LTO support' (#616) from mueller/add-lto-support into development

Reviewed-on: fsfw/fsfw#616
This commit is contained in:
Steffen Gaisser 2022-05-12 16:56:54 +02:00
commit b99160e850
2 changed files with 37 additions and 6 deletions

View File

@ -46,6 +46,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Additions ## Additions
- LTO support: Allow using LTO/IPO by setting `FSFW_ENABLE_LTO=1`. CMake is able to detect whether
the user compiler supports IPO/LPO. LTO is on by default now. Most modern compilers support it,
can make good use of it and it usually makes the code faster and/or smaller.
After some more research:
Enabling LTO will actually cause the compiler to only produce thin LTO by adding
`-flto -fno-fat-lto-objects` to the compiler options. I am not sure this is an ideal choice
because if an application linking against the FSFW does not use LTO, there can be compile
issues (e.g. observed when compiling the FSFW tests without LTO). This is a known issue as
can be seen in the multiple CMake issues for it:
- https://gitlab.kitware.com/cmake/cmake/-/issues/22913,
- https://gitlab.kitware.com/cmake/cmake/-/issues/16808,
- https://gitlab.kitware.com/cmake/cmake/-/issues/21696
Easiest solution for now: Keep this option OFF by default.
PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616
- Linux HAL: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1 - Linux HAL: Add wiretapping option for I2C. Enabled with `FSFW_HAL_I2C_WIRETAPPING` defined to 1
- Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information - Dedicated Version class and constant `fsfw::FSFW_VERSION` containing version information
inside `fsfw/version.h` inside `fsfw/version.h`

View File

@ -17,6 +17,7 @@ set(FSFW_REVISION 0)
# Add the cmake folder so the FindSphinx module is found # Add the cmake folder so the FindSphinx module is found
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(FSFW_ETL_LIB_NAME etl)
set(FSFW_ETL_LIB_MAJOR_VERSION 20 CACHE STRING set(FSFW_ETL_LIB_MAJOR_VERSION 20 CACHE STRING
"ETL library major version requirement" "ETL library major version requirement"
) )
@ -32,7 +33,16 @@ set(FSFW_CATCH2_LIB_VERSION v${FSFW_CATCH2_LIB_MAJOR_VERSION}.0.0-preview5 CACHE
"Catch2 library exact version requirement" "Catch2 library exact version requirement"
) )
set(FSFW_ETL_LIB_NAME etl) # Keep this off by default for now. See PR: https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/616
# for information which keeping this on by default is problematic
option(FSFW_ENABLE_IPO "Enable interprocedural optimization or link-time optimization if available" OFF)
if(FSFW_ENABLE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_ERROR)
if(NOT IPO_SUPPORTED)
message(STATUS "FSFW | IPO/LTO not supported: ${IPO_ERROR}")
endif()
endif()
option(FSFW_GENERATE_SECTIONS option(FSFW_GENERATE_SECTIONS
"Generate function and data sections. Required to remove unused code" ON "Generate function and data sections. Required to remove unused code" ON
@ -71,6 +81,10 @@ set(FSFW_DUMMY_TGT fsfw-dummy)
add_library(${LIB_FSFW_NAME}) add_library(${LIB_FSFW_NAME})
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(FSFW_BUILD_UNITTESTS) if(FSFW_BUILD_UNITTESTS)
message(STATUS "Building the FSFW unittests in addition to the static library") message(STATUS "Building the FSFW unittests in addition to the static library")
# Check whether the user has already installed Catch2 first # Check whether the user has already installed Catch2 first
@ -95,6 +109,9 @@ if(FSFW_BUILD_UNITTESTS)
project(${FSFW_TEST_TGT} CXX C) project(${FSFW_TEST_TGT} CXX C)
add_executable(${FSFW_TEST_TGT}) add_executable(${FSFW_TEST_TGT})
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(FSFW_TESTS_GEN_COV) if(FSFW_TESTS_GEN_COV)
message(STATUS "Generating coverage data for the library") message(STATUS "Generating coverage data for the library")