add_executable(stm32f407-training.elf)

target_include_directories(stm32f407-training.elf
    PRIVATE
        ${CMAKE_SOURCE_DIR}/src/bsp
        ${CMAKE_SOURCE_DIR}/src/modules/printf
        ${CMAKE_SOURCE_DIR}/src
)

target_sources(stm32f407-training.elf
    PRIVATE
        src/bsp/bsp_general.cpp
        src/bsp/bsp_clocks.cpp
        src/bsp/bsp_gpio.cpp
        src/bsp/bsp_uart.cpp
        src/assertions.cpp
        src/modules/printf/printf.c
        src/interrupts.c
        src/main.cpp
)

target_link_libraries(stm32f407-training.elf
    PUBLIC
        stm32f4-drivers
        freertos
)

set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/src/stm32f4-drivers/STM32F407VGTx_FLASH.ld)

target_link_options(stm32f407-training.elf PRIVATE -T${LINKER_SCRIPT} -specs=nosys.specs -lnosys -lc -lm -Wl,-Map=${PROJECT_NAME}.map,--gc-sections,--cref,--print-memory-usage)

add_custom_command(
    TARGET stm32f407-training.elf
    POST_BUILD
        COMMAND echo ***** Memory sections *****
        COMMAND ${CMAKE_SIZE_UTIL} stm32f407-training.elf --radix=10
        COMMAND ${CMAKE_OBJCOPY} -Osrec stm32f407-training.elf stm32f407-training.srec
        COMMAND ${CMAKE_OBJCOPY} -Oihex stm32f407-training.elf stm32f407-training.hex
)
