set(LIB_NAME ${MCU_SERIES}_HAL_DRIVER)
string (TOLOWER ${MCU_SERIES}  MCU_SERIES)

if (NOT DEFINED HAL_DRIVER_CONFIG)
    message(WARNING "HAL_DRIVER_CONFIG not defined \r\n Project will be generate with default config. You can choose full path to configuration file ${MCU_SERIES}_hal_conf.h
filename should be - ${MCU_SERIES}_hal_conf.h" )
    message(WARNING "PROJECT WILL BE GENERATED WITH DEFAULT CONFIG" )
    if (NOT EXISTS default_config)
        file(MAKE_DIRECTORY default_config)
        endif()
    if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/default_config/${MCU_SERIES}_hal.h)
    file(COPY Inc/${MCU_SERIES}_hal_conf_template.h DESTINATION ${CMAKE_CURRENT_LIST_DIR}/default_config)
    file(RENAME ${CMAKE_CURRENT_LIST_DIR}/default_config/${MCU_SERIES}_hal_conf_template.h ${CMAKE_CURRENT_LIST_DIR}/default_config/${MCU_SERIES}_hal_conf.h )
    endif()
    set (${HAL_DRIVER_CONFIG} ${CMAKE_CURRENT_LIST_DIR}/default_config)
else()
    string(FIND ${HAL_DRIVER_CONFIG} "${MCU_SERIES}_hal_conf.h" RESULT)
    if (${RESULT} EQUAL -1)
        message(FATAL_ERROR "filename should be - ${MCU_SERIES}_hal_conf.h")
    endif()
    file(MAKE_DIRECTORY config)
    file(COPY ${HAL_DRIVER_CONFIG} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/config)
    set (HAL_DRIVER_CONFIG config)
endif()
project(${LIB_NAME}
        LANGUAGES C ASM
        )

add_definitions(-DUSE_HAL_DRIVER -D${MCU})
file(GLOB_RECURSE SOURCES "Src/*.c")

add_library(${LIB_NAME} STATIC ${SOURCES})
add_library(${LIB_NAME}_INTERFACE INTERFACE)
if (GTEST)
    target_include_directories(${LIB_NAME}_INTERFACE INTERFACE Inc)
else()
    target_include_directories(${LIB_NAME} PUBLIC Inc default_config)
endif()
target_link_libraries(${LIB_NAME} PRIVATE CMSIS)
