cmake_minimum_required(VERSION 3.19)
set (CMAKE_SYSTEM_NAME Generic)
set (CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/sdk/gcc-arm-eabi.cmake")

if(NOT HC32_CHIP_SERIES)
    if("$ENV{HC32_CHIP_SERIES}")
        set(HC32_CHIP_SERIES "$ENV{HC32_CHIP_SERIES}")
    else()
        set(HC32_CHIP_SERIES "6")
    endif()
endif()

if(HC32_CHIP_SERIES STREQUAL "4")
    link_libraries("-T${CMAKE_CURRENT_LIST_DIR}/sdk/hc32l110x4.ld")
else()
    link_libraries("-T${CMAKE_CURRENT_LIST_DIR}/sdk/hc32l110x6.ld")
endif()
include_directories("${CMAKE_CURRENT_LIST_DIR}/sdk/include")
link_directories("${CMAKE_CURRENT_LIST_DIR}/sdk/lib")

link_libraries("hc32l110_ddl_core")
if(HC32_USE_DDL_GPIO)
    link_libraries("hc32l110_ddl_gpio")
    add_compile_definitions("HC32_USE_DDL_GPIO")
endif()
if(HC32_USE_DDL_BASIC_TIMERS)
    link_libraries("hc32l110_ddl_basic_timers")
    add_compile_definitions("HC32_USE_DDL_BASIC_TIMERS")
endif()
if(HC32_USE_DDL_DEBUG)
    link_libraries("hc32l110_ddl_debug")
    add_compile_definitions("HC32_USE_DDL_DEBUG")
endif()
if(HC32_USE_DDL_I2C)
    link_libraries("hc32l110_ddl_i2c")
    add_compile_definitions("HC32_USE_DDL_I2C")
endif()
if(HC32_USE_DDL_CLOCK_DYNAMIC)
    link_libraries("hc32l110_ddl_clock_dynamic")
    add_compile_definitions("HC32_USE_DDL_CLOCK_DYNAMIC")
endif()
if(HC32_USE_DDL_UTIL)
    link_libraries("hc32l110_ddl_util")
    add_compile_definitions("HC32_USE_DDL_UTIL")
endif()
link_libraries("gcc")
