function(cph_init TARGET)
endfunction()


function(cph_component_handler TARGET COMPONENT)
    if(COMPONENT STREQUAL gpio)
        #ADD GPIO
    elseif(COMPONENT STREQUAL timer_core)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/timer/CortexM4/timer_core.cpp outvar)
        LIST(APPEND DEFINES CPH_ENABLE_TIMER_CORE)
        LIST(APPEND CPH_SOURCES ${outvar})
        #ADD GPIO
    elseif(COMPONENT STREQUAL timer1)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/timer/CortexM4/timer1.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_TIMER1)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_TIMER1_ISR)
        #ADD GPIO
    elseif(COMPONENT STREQUAL timer_rtc)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/timer/CortexM4/timer_rtc.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_TIMER1)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_TIMER_RTC_ISR) #
    elseif(COMPONENT STREQUAL uart1)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/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_UART1_ISR) #to enable ISR
    elseif(COMPONENT STREQUAL uart3)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/uart/uart3.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_UART3)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_UART3_ISR) #to enable ISR
      elseif(COMPONENT STREQUAL uart4)
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/uart/uart4.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_UART4)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_UART4_ISR) #to enable ISR
    elseif(COMPONENT STREQUAL "usb")
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/usb/CortexM4/usb_it.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/usb/CortexM4/usb_lowlevel.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        target_include_directories(${TARGET} PUBLIC ${CPH_LIB_PATH}/cph/platform/stm32/usb/CortexM4/Inc)
        LIST(APPEND DEFINES CPH_ENABLE_USB0)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_USB0_ISR)
    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 "printf")
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/printf/platform_printf.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
    elseif(COMPONENT STREQUAL "i2c1")
        MESSAGE(WARNING "Check that i2c ISR is linked to main program")
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/i2c/platform_i2c.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        LIST(APPEND DEFINES CPH_ENABLE_I2C1)
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_I2C1)
    elseif(COMPONENT STREQUAL "exti")
        MESSAGE(WARNING "Check that EXTI ISR is linked to main program")
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/exti/CortexM4/exti.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_EXTI_ISR)
    elseif(COMPONENT STREQUAL "adc1")
        MESSAGE(WARNING "Check that ADC ISR is linked to main program")
        check_var(${CPH_LIB_PATH}/cph/platform/stm32/adc/adc_impl.cpp outvar)
        LIST(APPEND CPH_SOURCES ${outvar})
        target_link_options(${new_target} PUBLIC -Wl,-u,tag_CPH_ADC1_2_ISR) #to enable ISR
    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})
    elseif(COMPONENT STREQUAL "graphics")
        MESSAGE(FATAL_ERROR "graphics component NYI")
    else()
        MESSAGE(FATAL_ERROR "Cmake CPH Component `${COMPONENT}` is not supported for stm32")
    endif()
    #
    if (CPH_SOURCES)
        target_sources(${TARGET} PRIVATE "${CPH_SOURCES}")
    endif()
    if (DEFINES)
        target_compile_definitions(${TARGET} PUBLIC "${DEFINES}")
    endif()



endfunction()