# 定义要创建的库列表及其对应的目录
set(LIBRARIES
        HW_LIB_List list list/inc
        HW_LIB_Task task task/inc
        HW_LIB_Printf printf printf/inc
        HW_LIB_Utils utils utils/inc
        HW_LIB_Font font font/inc
        HW_LIB_Iic iic iic/inc
        HW_LIB_Spi spi spi/inc
        HW_LIB_Key key key/inc
        HW_LIB_Oled oled oled/inc
        HW_LIB_Tft tft tft/inc
        HW_LIB_Flash flash flash/inc
        HW_LIB_Lui lui lui/inc
)

# 循环浏览库列表以创建它们
list(LENGTH LIBRARIES LIBRARIES_LENGTH)
math(EXPR LIBRARIES_LENGTH "${LIBRARIES_LENGTH}-1")

foreach (INDEX RANGE 0 ${LIBRARIES_LENGTH} 3)
    list(GET LIBRARIES ${INDEX} TARGET_NAME)
    MATH(EXPR SOURCE_DIR_INDEX "${INDEX}+1")
    MATH(EXPR INCLUDE_DIR_INDEX "${INDEX}+2")
    list(GET LIBRARIES ${SOURCE_DIR_INDEX} SOURCE_DIR)
    list(GET LIBRARIES ${INCLUDE_DIR_INDEX} INCLUDE_DIR)

    file(GLOB_RECURSE LIB_SOURCES "${SOURCE_DIR}/*.c" "${SOURCE_DIR}/*.cpp")
    add_library(${TARGET_NAME} STATIC ${LIB_SOURCES})
    target_include_directories(${TARGET_NAME} PUBLIC "${INCLUDE_DIR}")
endforeach ()

# 链接必要的库
target_link_libraries(HW_LIB_Spi HW_LIB_Utils)
target_link_libraries(HW_LIB_Oled HW_LIB_Font)
target_link_libraries(HW_LIB_Tft HW_LIB_Font)
