cmake_minimum_required(VERSION 3.28)
include(cmake/toolchain.cmake)

set(PROJECT_NAME "XLSW_3DP_US-IR")

project(${PROJECT_NAME})

set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
set(VERSION_PATCH 0)
set(VERSION "V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")

# Options 1
set(OPT1 "_[12V]")
#set(OPT1 "_[SW_IIC]")

# Options 2
set(OPT2 "_[HW_IIC]")
#set(OPT2 "_[NO_LED]")

enable_language(C)
enable_language(CXX)
enable_language(ASM)

# Use custom startup.S
set(TARGET_STARTUP_ASM ${CMAKE_SOURCE_DIR}/startup/startup_gd32e23x.S)
# Use custom linker script
set(TARGET_LD_SCRIPT ${CMAKE_SOURCE_DIR}/ld/gd32e23x_gcc.ld)
# Add GD SDK
add_subdirectory(sdk)

set(TARGET_C_SRC
        ${CMAKE_SOURCE_DIR}/src/main.c
        ${CMAKE_SOURCE_DIR}/src/gd32e23x_it.c
        ${CMAKE_SOURCE_DIR}/src/systick.c
        ${CMAKE_SOURCE_DIR}/src/led.c
        ${CMAKE_SOURCE_DIR}/src/usart.c
        ${CMAKE_SOURCE_DIR}/src/soft_i2c.c
        ${CMAKE_SOURCE_DIR}/src/i2c.c
        ${CMAKE_SOURCE_DIR}/src/fwdgt.c
        ${CMAKE_SOURCE_DIR}/src/rs485_protocol.c
        ${CMAKE_SOURCE_DIR}/src/ultrasonic_analog.c
        ${CMAKE_SOURCE_DIR}/src/gd60914.c
)

add_executable(${PROJECT_NAME} ${TARGET_C_SRC})

target_link_libraries(${PROJECT_NAME} GD32E23X_SDK)
target_include_directories(${PROJECT_NAME} PUBLIC inc)

# Generate .bin and .hex
generate_binary_file(${PROJECT_NAME})
generate_hex_file(${PROJECT_NAME})
