
add_executable(${PROJECT_NAME}
    main.c
    ch32fun.c
)

target_include_directories(${PROJECT_NAME} PUBLIC
    ${CMAKE_SOURCE_DIR}
)

target_link_libraries(${PROJECT_NAME} PRIVATE 
    gcc
)


# The `-ffunction-sections` and `-fdata-sections` need to be used 
# in the compile and linker options otherwise it doesnt't
# correctly remove the unused functions.
target_compile_options(${PROJECT_NAME} PUBLIC
    -g
    -Os
    -flto
    -ffunction-sections
    -fdata-sections
    -fmessage-length=0
    -msmall-data-limit=8
    -march=rv32ec
    -mabi=ilp32e
    -DCH32V003=1
)

target_link_options(${PROJECT_NAME} PUBLIC
    -flto
    -ffunction-sections
    -fdata-sections
    -fmessage-length=0
    -msmall-data-limit=8
    -march=rv32ec
    -mabi=ilp32e
    -static-libgcc
    -nostdlib
    -L${CMAKE_SOURCE_DIR}/src
    -Wl,--print-memory-usage
    -Wl,-Map=${PROJECT_NAME}.map
    -Wl,--gc-sections
    -T${CMAKE_SOURCE_DIR}/src/linker_script.ld
)


set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf")


#add_subdirectory(attic)
add_subdirectory(ADC)
add_subdirectory(RegEdit)
