function(cph_init TARGET)
endfunction()



function(cph_component_handler TARGET COMPONENT)
    SET(CPH_SOURCES "")
    SET(DEFINES "")
    if(COMPONENT STREQUAL timer0)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/timer/timer0.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_TIMER0)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_TIMER0_OCRA) #to enable ISR
    elseif(COMPONENT STREQUAL timer1)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/timer/timer1.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_TIMER1)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_TIMER1_OCRA) #to enable ISR
    elseif(COMPONENT STREQUAL spi)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/spi/spi.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_SPI)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_SPI_ISR) #to enable ISR
    elseif(COMPONENT STREQUAL uart0)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/uart/uart0.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_UART0)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_USART0_RXC) #to enable ISR
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_USART0_TXE) #to enable ISR
    elseif(COMPONENT STREQUAL uart1)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/uart/uart1.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_UART1)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_USART1_RXC) #to enable ISR
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_INT_USART1_TXE) #to enable ISR
    elseif(COMPONENT STREQUAL usb)
        MESSAGE(FATAL_ERROR "USB component NYI")
    elseif(COMPONENT STREQUAL wake)
        check_var(${CPH_LIB_PATH}/cph/wake/wake.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/wake/crc.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
    elseif(COMPONENT STREQUAL exti)
            MESSAGE(FATAL_ERROR "Cmake CPH component exti not implemented for var")
    elseif(COMPONENT STREQUAL printf)
        check_var(${CPH_LIB_PATH}/cph/platform/avr/printf/platform_printf.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
    elseif(COMPONENT STREQUAL modbus)
        check_var(${CPH_LIB_PATH}/cph/modbus/mb.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbfunccoils.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbfuncdisc.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbfuncholding.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbfuncinput.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbfuncother.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbqueue.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbrtu.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/modbus/mbutils.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
    else()
        MESSAGE(FATAL_ERROR "Cmake CPH Component `${COMPONENT}` is not supported for avr")
    endif()
    #
    if (CPH_SOURCES)
        target_sources(${TARGET} PRIVATE "${CPH_SOURCES}")
    endif()
    if (DEFINES)
        target_compile_definitions(${TARGET} PUBLIC "${DEFINES}")
    endif()

endfunction()