cmake_minimum_required(VERSION 3.19)
project(usbtest LANGUAGES C)

set(LIBOPENCM3_DIR ${CMAKE_SOURCE_DIR}/libopencm3)
set(CMAKE_C_STANDARD 99)

add_compile_options(
        -Wall
        -Wextra -Wshadow -Wno-unused-variable -Wimplicit-function-declaration
        -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes
        -ggdb3
        -O0
)

add_link_options(

)

add_compile_definitions(
        STM32F1
        STM32F103C8T6
        DEBUG
        TARGETS=stm32/f1
)
add_executable(usbtest src/main.c src/util.c src/cdcacm.c)

set_target_properties(usbtest PROPERTIES SUFFIX .elf)

add_custom_target(libopencm3 make TARGETS=stm32/f1 -j8 WORKING_DIRECTORY ${LIBOPENCM3_DIR})
#link_directories(${LIBOPENCM3_DIR}/lib)
target_link_libraries(usbtest PUBLIC ${LIBOPENCM3_DIR}/lib/libopencm3_stm32f1.a)

add_subdirectory(RTT)
target_link_libraries(usbtest PUBLIC RTT)

target_include_directories(usbtest PUBLIC
        RTT ${LIBOPENCM3_DIR}/include
)
