include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_chibios_executable(usb-serial
    chconf.h
    halconf.h
    mcuconf.h
    main.cc
    ${PHOBOS_COMMON_SRC})

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Override default C/CXX debug optimization flag due to linking errors when both
# LTO and Debug mode are used. As stated in the gcc manual, the last -O option
# is used when there are multiple.
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")

add_chibios_executable(usb-serial
    chconf.h
    halconf.h
    mcuconf.h
    main.cc
    ${PHOBOS_COMMON_SRC})

Fix build error for usb-serial demo
Fix build error for usb-serial demo

The usb-serial demo fails at the linking stage when both LTO and Debug
mode are enabled, likely due to the combination of -flto, -O0, and
overriding syscalls. This is fixed by changing the optimization flag to
-Og for this target only.
