Update presets and integrate testing concept

This commit is contained in:
Robin Dietzel 2025-06-18 13:13:14 +02:00
parent b47e962ce9
commit c91a78a91d
6 changed files with 85 additions and 29 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
/.out/ /build/

View File

@ -10,11 +10,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
# General Project # General Project
add_subdirectory(floatpump) if(NOT ENABLE_UNITTESTS)
add_subdirectory(floatpump)
endif ()
# Testing Project # Testing Project
if(ENABLE_UNITTESTS) if(ENABLE_UNITTESTS)
message(STATUS "Enabled Unit Tests") message(STATUS "Enabled Unit Tests")
add_subirectory(Catch2) add_subdirectory(Catch2)
add_subdirectory(Tests) add_subdirectory(Tests)
endif() endif()

View File

@ -1,4 +1,9 @@
{ {
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22
},
"configurePresets": [ "configurePresets": [
{ {
"name": "debug@firmware", "name": "debug@firmware",
@ -10,24 +15,61 @@
}, },
"binaryDir": "build/debug@firmware" "binaryDir": "build/debug@firmware"
}, },
{
"name": "release@firmware",
"description": "Firmware Release Build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "toolchain/arm-none-eabi-stm32f411ceu6-toolchain.cmake",
"CMAKE_BUILD_TYPE": "Release"
},
"binaryDir": "build/release@firmware"
},
{
"name": "minrelease@firmware",
"description": "Firmware Minimized Release Build",
"inherits": ["release@firmware"],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "MinSizeRel"
},
"binaryDir": "build/minrelease@firmware"
},
{ {
"name": "debug@tests", "name": "debug@tests",
"description": "UnitTests Debug Buil", "description": "UnitTests Debug Build",
"generator": "Ninja", "generator": "Ninja",
"cacheVariables": { "cacheVariables": {
"ENABLE_UNITTESTS": "ON" "ENABLE_UNITTESTS": "ON"
} },
"binaryDir": "build/debug@tests"
} }
], ],
"buildPresets": [ "buildPresets": [
{ {
"name": "build-debug@firmware", "name": "build-debug",
"description": "Builds the debugging firmware", "description": "Builds the debugging firmware",
"cleanFirst": false, "cleanFirst": false,
"configuration": "debug@firmware", "configurePreset": "debug@firmware",
"targets": [ "targets": [
"FloatPUMP.elf" "FloatPUMP.elf"
] ]
},
{
"name": "build-release",
"description": "Builds the normal release firmware",
"cleanFirst": true,
"configurePreset": "minrelease@firmware",
"targets": [
"FloatPUMP.elf"
]
},
{
"name": "build-tests",
"description": "Creates a debug build of all tests",
"configurePreset": "debug@tests",
"targets": [
"testtests"
]
} }
] ]
} }

View File

@ -1,4 +1,10 @@
find_package(Catch2 REQUIRED) # Catch 2 is already loaded from the main CMakeLists.txt as a subdirectory
add_executable(testtests experiments/example-test.cpp) add_executable(testtests experiments/example-test.cpp)
target_link_libraries(testtests PRIVATE Catch2::Catch2WithMain) target_link_libraries(testtests PRIVATE Catch2::Catch2WithMain)
# General catch configuration
include(CTest)
include(Catch)
catch_discover_tests(testtests)

View File

@ -0,0 +1,14 @@
# Obtain the short git hash for burning it into the firmware
set(GIT_HASH "undefined")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
message(STATUS "Burning in git hash: ${GIT_HASH}")
else ()
message(WARNING "Cannot obtain git hash for burning into firmware")
endif()

View File

@ -1,22 +1,6 @@
set(GIT_HASH "undefined") include(CMake/githash.cmake)
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
message(STATUS "Burning in git hash: ${GIT_HASH}")
add_definitions("-DGIT_HASH=\"${GIT_HASH}\"")
#include(${CMAKE_CURRENT_LIST_DIR}/../toolchain/arm-none-eabi-stm32f411ceu6-toolchain.cmake)
# uncomment to mitigate c++17 absolute addresses warnings
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
# All required source definitions
file(GLOB_RECURSE SOURCES file(GLOB_RECURSE SOURCES
"Core/*.*" "Core/*.*"
"Middlewares/*.*" "Middlewares/*.*"
@ -24,9 +8,17 @@ file(GLOB_RECURSE SOURCES
"USB_DEVICE/*.*" "USB_DEVICE/*.*"
) )
message(WARNING "linker script is : ${LINKER_SCRIPT}") # Check if the correct toolchain was used and the LINKER_SCRIPT is defined
if(NOT DEFINED LINKER_SCRIPT)
message(FATAL_ERROR "You need to define the LINKER_SCRIPT variable from within the toolchain for the correct MCU")
endif()
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT}) add_executable(FloatPUMP.elf ${SOURCES} ${LINKER_SCRIPT})
# Custom target options
target_compile_definitions(FloatPUMP.elf PUBLIC
"-DGIT_HASH=\"${GIT_HASH}\""
)
target_include_directories(${PROJECT_NAME}.elf PUBLIC target_include_directories(${PROJECT_NAME}.elf PUBLIC
USB_DEVICE/App USB_DEVICE/App