set(headers
    accessorhelpers.h
    accessors/globalaccessors.h
    accessors/settingsaccessors.h
    accessors/wifiaccessors.h
    accessors/wifiapconfigaccessors.h
    accessors/wifistaconfigaccessors.h
    actions/assertaction.h
    actions/bluetoothbeginaction.h
    actions/bluetoothbeginmasteraction.h
    actions/bluetoothconnectbmsaction.h
    actions/bluetoothdisconnectaction.h
    actions/bluetoothendaction.h
    actions/bluetoothflushaction.h
    actions/bmsturnoffchargeaction.h
    actions/bmsturnoffdischargeaction.h
    actions/bmsturnonchargeaction.h
    actions/bmsturnondischargeaction.h
    actions/dividebyzeroaction.h
    actions/erasenvsaction.h
    actions/ledstripanimationactions.h
    actions/ledstripblinkactions.h
    actions/loadsettingsaction.h
    actions/modesettingsaction.h
    actions/qraction.h
    actions/rebootaction.h
    actions/savesettingsaction.h
    actions/switchprofileaction.h
    actions/tempomatmodeapplycurrentpeedaction.h
    actions/updateswapfrontbackaction.h
    actions/wifiscanaction.h
    actions/wifistascanaction.h
    actions/wifistascanclearaction.h
    battery.h
    ble_bobby.h
    bletexthelpers.h
    bluetooth_bobby.h
    bluetoothmode.h
    bluetoothtexthelpers.h
    bmsutils.h
    bobbyblinker.h
    bobbybuttons.h
    bobbycheckbox.h
    bobbyerrorhandler.h
    bobbyhupe.h
    bobbyquickactions.h
    bobbyschedulertask.h
    bobbytypesafeenum.h
    buildserver.h
    can.h
    changevaluedisplay_bluetoothmode.h
    changevaluedisplay_bobbyquickactions.h
    changevaluedisplay_controlmode.h
    changevaluedisplay_controltype.h
    changevaluedisplay_larsmmode_mode.h
    changevaluedisplay_unifiedmodelmode.h
    cloud.h
    cloudtexthelpers.h
    configutils_bobby.h
    controller.h
    debugcolorhelpers.h
    debuginputhandler.h
    debugtexthelpers.h
    displays/batterygraphdisplay.h
    displays/batteryinfodisplay.h
    displays/bmsdisplay.h
    displays/bobbychangevaluedisplay.h
    displays/bobbydisplay.h
    displays/bobbydisplaywithtitle.h
    displays/bobbygraphdisplay.h
    displays/bobbymenudisplay.h
    displays/bobbypopupdisplay.h
    displays/bobbysplitgraphdisplay.h
    displays/buttoncalibratedisplay.h
    displays/calibratevoltagedisplay.h
    displays/confiscationdisplay.h
    displays/gameoflifedisplay.h
    displays/gametrakcalibratedisplay.h
    displays/joystickdebugdisplay.h
    displays/ledstripcolorsdisplay.h
    displays/lockscreen.h
    displays/menudisplaywithtime.cpp
    displays/menudisplaywithtime.h
    displays/menus/aboutmenu.h
    displays/menus/batterydebugmenu.h
    displays/menus/batterymenu.h
    displays/menus/blesettingsmenu.h
    displays/menus/bluetoothsettingsmenu.h
    displays/menus/bmsmenu.h
    displays/menus/boardcomputerhardwaresettingsmenu.h
    displays/menus/buzzermenu.h
    displays/menus/candebugmenu.h
    displays/menus/cloudsettingsmenu.h
    displays/menus/commanddebugmenu.h
    displays/menus/controllerhardwaresettingsmenu.h
    displays/menus/crashmenu.h
    displays/menus/debugmenu.h
    displays/menus/defaultmodesettingsmenu.h
    displays/menus/demosmenu.h
    displays/menus/dynamicdebugmenu.h
    displays/menus/enablemenu.h
    displays/menus/espnowmenu.h
    displays/menus/espnowsettingsmenu.h
    displays/menus/extrabuttoncalibratemenu.h
    displays/menus/featureflagsmenu.h
    displays/menus/feedbackdebugmenu.h
    displays/menus/gametrakmodesettingsmenu.h
    displays/menus/garagemenu.h
    displays/menus/gitmenu.h
    displays/menus/graphsmenu.h
    displays/menus/greenpassmenu.h
    displays/menus/handbremssettingsmenu.h
    displays/menus/invertmenu.h
    displays/menus/larsmmodesettingsmenu.h
    displays/menus/ledstripmenu.h
    displays/menus/ledstripselectblinkmenu.h
    displays/menus/ledstripselectotamode.h
    displays/menus/limitssettingsmenu.h
    displays/menus/lockscreensettingsmenu.h
    displays/menus/mainmenu.h
    displays/menus/manageprofilesmenu.h
    displays/menus/mickmodesettingsmenu.h
    displays/menus/modessettingsmenu.h
    displays/menus/mosfetsmenu.h
    displays/menus/motorfeedbackdebugmenu.h
    displays/menus/motorstatedebugmenu.h
    displays/menus/motortestmodesettingsmenu.h
    displays/menus/networksettingsmenu.h
    displays/menus/otamenu.h
    displays/menus/profilesmenu.h
    displays/menus/remotecontrolmodesettingsmenu.h
    displays/menus/selectbuildserverbranch.h
    displays/menus/selectbuildservermenu.h
    displays/menus/selectmodemenu.h
    displays/menus/selectotabuildmenu.h
    displays/menus/settingsmenu.h
    displays/menus/setupquickactionsmenu.h
    displays/menus/statisticsmenu.h
    displays/menus/taskmanagermenu.h
    displays/menus/tempomatmodesettingsmenu.h
    displays/menus/timersmenu.h
    displays/menus/timesettingsmenu.h
    displays/menus/typesafeenumchangemenu.h
    displays/menus/udpcloudsettingsmenu.h
    displays/menus/wifiapclientsmenu.h
    displays/menus/wifiapsettingsmenu.h
    displays/menus/wifistaconfigentrymenu.h
    displays/menus/wifistaconfigsmenu.h
    displays/menus/wifistascanentrymenu.h
    displays/menus/wifistascanmenu.h
    displays/menus/wifistasettingsmenu.h
    displays/metersdisplay.h
    displays/pingpongdisplay.h
    displays/potiscalibratedisplay.h
    displays/poweroffdisplay.h
    displays/powersupplydisplay.h
    displays/qrcodedebug.h
    displays/qrdisplay.h
    displays/qrimportdisplay.h
    displays/speedinfodisplay.h
    displays/spirodisplay.h
    displays/starfielddisplay.h
    displays/statusdisplay.h
    displays/updatedisplay.h
    displays/xydebugdisplay.h
    dnsannounce.h
    dpad.h
    dpad3wire.h
    dpad5wire.h
    dpad5wire_2out.h
    dpad6wire.h
    dpad_boardcomputer_v2.h
    drivingstatistics.h
    espnowfunctions.h
    esptexthelpers.h
    feedbackparser.h
    globals.h
    handbremse.h
    icons/alert.h
    icons/battery.h
    icons/bluetooth.h
    icons/bms.h
    icons/bobbycar.h
    icons/buzzer.h
    icons/close.h
    icons/demos.h
    icons/git.h
    icons/graph.h
    icons/greenpass.h
    icons/hardware.h
    icons/info.h
    icons/lock.h
    icons/logo.h
    icons/modes.h
    icons/neopixel.h
    icons/poweroff.h
    icons/presets.h
    icons/reboot.h
    icons/scan.h
    icons/settings.h
    icons/shortcircuit.h
    icons/statistics.h
    icons/time.h
    icons/update.h
    icons/wifi.h
    ledstrip.h
    ledstripdefines.h
    macros_bobbycar.h
    modeinterface.h
    modes.h
    modes/defaultmode.h
    modes/gametrakmode.h
    modes/ignoreinputmode.h
    modes/larsmmode.h
    modes/mickmode.h
    modes/motortestmode.h
    modes/remotecontrolmode.h
    modes/tempomatmode.h
    modes/wheelchairmode.h
    mosfets.h
    motorpwmlimiter.h
    newsettings.h
    ota.h
    potis.h
    presets.h
    profilesettings.h
    qrimport.h
    rotary.h
    screens.h
    serial_bobby.h
    settingspersister.h
    settingsutils.h
    softpwmlimiter.h
    statistics.h
    statustexthelper.h
    taskmanager.h
    tempomat.h
    texthelpers/networktexthelpers.h
    texthelpers/wifiaptexthelpers.h
    texthelpers/wifistatexthelpers.h
    time_bobbycar.h
    types.h
    typeutils.h
    udpcloud.h
    unifiedmodelmode.h
    utils.h
    webserver.h
    webserver_displaycontrol.h
    webserver_dumpnvs.h
    webserver_lock.h
    webserver_newsettings.h
    webserver_ota.h
    webserver_settings.h
    widgets/doubleprogressbar.h
    wifi_bobbycar.h
    wifiguiutils.h
)

set(sources
    accessors/wifistaconfigaccessors.cpp
    actions/assertaction.cpp
    actions/bluetoothbeginaction.cpp
    actions/bluetoothbeginmasteraction.cpp
    actions/bluetoothconnectbmsaction.cpp
    actions/bluetoothdisconnectaction.cpp
    actions/bluetoothendaction.cpp
    actions/bluetoothflushaction.cpp
    actions/bmsturnoffchargeaction.cpp
    actions/bmsturnoffdischargeaction.cpp
    actions/bmsturnonchargeaction.cpp
    actions/bmsturnondischargeaction.cpp
    actions/dividebyzeroaction.cpp
    actions/erasenvsaction.cpp
    actions/ledstripanimationactions.cpp
    actions/ledstripblinkactions.cpp
    actions/loadsettingsaction.cpp
    actions/modesettingsaction.cpp
    actions/qraction.cpp
    actions/rebootaction.cpp
    actions/savesettingsaction.cpp
    actions/switchprofileaction.cpp
    actions/tempomatmodeapplycurrentpeedaction.cpp
    actions/updateswapfrontbackaction.cpp
    actions/wifiscanaction.cpp
    actions/wifistascanaction.cpp
    actions/wifistascanclearaction.cpp
    battery.cpp
    ble_bobby.cpp
    bletexthelpers.cpp
    bluetooth_bobby.cpp
    bluetoothmode.cpp
    bluetoothtexthelpers.cpp
    bmsutils.cpp
    bobbyblinker.cpp
    bobbybuttons.cpp
    bobbyerrorhandler.cpp
    bobbyhupe.cpp
    bobbyquickactions.cpp
    buildserver.cpp
    can.cpp
    changevaluedisplay_bluetoothmode.cpp
    changevaluedisplay_bobbyquickactions.cpp
    changevaluedisplay_controlmode.cpp
    changevaluedisplay_controltype.cpp
    changevaluedisplay_larsmmode_mode.cpp
    changevaluedisplay_unifiedmodelmode.cpp
    cloud.cpp
    cloudtexthelpers.cpp
    configwrapper_bobby.cpp
    controller.cpp
    debugcolorhelpers.cpp
    debuginputhandler.cpp
    debugtexthelpers.cpp
    displays/batterygraphdisplay.cpp
    displays/batteryinfodisplay.cpp
    displays/bmsdisplay.cpp
    displays/bobbychangevaluedisplay.cpp
    displays/bobbydisplay.cpp
    displays/bobbydisplaywithtitle.cpp
    displays/bobbygraphdisplay.cpp
    displays/bobbymenudisplay.cpp
    displays/bobbypopupdisplay.cpp
    displays/bobbysplitgraphdisplay.cpp
    displays/buttoncalibratedisplay.cpp
    displays/calibratevoltagedisplay.cpp
    displays/confiscationdisplay.cpp
    displays/gameoflifedisplay.cpp
    displays/gametrakcalibratedisplay.cpp
    displays/joystickdebugdisplay.cpp
    displays/ledstripcolorsdisplay.cpp
    displays/lockscreen.cpp
    displays/menus/aboutmenu.cpp
    displays/menus/batterydebugmenu.cpp
    displays/menus/batterymenu.cpp
    displays/menus/blesettingsmenu.cpp
    displays/menus/bluetoothsettingsmenu.cpp
    displays/menus/bmsmenu.cpp
    displays/menus/boardcomputerhardwaresettingsmenu.cpp
    displays/menus/buzzermenu.cpp
    displays/menus/candebugmenu.cpp
    displays/menus/cloudsettingsmenu.cpp
    displays/menus/commanddebugmenu.cpp
    displays/menus/controllerhardwaresettingsmenu.cpp
    displays/menus/crashmenu.cpp
    displays/menus/debugmenu.cpp
    displays/menus/defaultmodesettingsmenu.cpp
    displays/menus/demosmenu.cpp
    displays/menus/dynamicdebugmenu.cpp
    displays/menus/enablemenu.cpp
    displays/menus/espnowmenu.cpp
    displays/menus/espnowsettingsmenu.cpp
    displays/menus/extrabuttoncalibratemenu.cpp
    displays/menus/featureflagsmenu.cpp
    displays/menus/feedbackdebugmenu.cpp
    displays/menus/gametrakmodesettingsmenu.cpp
    displays/menus/garagemenu.cpp
    displays/menus/gitmenu.cpp
    displays/menus/graphsmenu.cpp
    displays/menus/greenpassmenu.cpp
    displays/menus/handbremssettingsmenu.cpp
    displays/menus/invertmenu.cpp
    displays/menus/larsmmodesettingsmenu.cpp
    displays/menus/ledstripmenu.cpp
    displays/menus/ledstripselectblinkmenu.cpp
    displays/menus/ledstripselectotamode.cpp
    displays/menus/limitssettingsmenu.cpp
    displays/menus/lockscreensettingsmenu.cpp
    displays/menus/mainmenu.cpp
    displays/menus/manageprofilesmenu.cpp
    displays/menus/mickmodesettingsmenu.cpp
    displays/menus/modessettingsmenu.cpp
    displays/menus/mosfetsmenu.cpp
    displays/menus/motorfeedbackdebugmenu.cpp
    displays/menus/motorstatedebugmenu.cpp
    displays/menus/motortestmodesettingsmenu.cpp
    displays/menus/networksettingsmenu.cpp
    displays/menus/otamenu.cpp
    displays/menus/profilesmenu.cpp
    displays/menus/remotecontrolmodesettingsmenu.cpp
    displays/menus/selectbuildserverbranch.cpp
    displays/menus/selectbuildservermenu.cpp
    displays/menus/selectmodemenu.cpp
    displays/menus/selectotabuildmenu.cpp
    displays/menus/settingsmenu.cpp
    displays/menus/setupquickactionsmenu.cpp
    displays/menus/statisticsmenu.cpp
    displays/menus/taskmanagermenu.cpp
    displays/menus/tempomatmodesettingsmenu.cpp
    displays/menus/timersmenu.cpp
    displays/menus/timesettingsmenu.cpp
    displays/menus/typesafeenumchangemenu.cpp
    displays/menus/udpcloudsettingsmenu.cpp
    displays/menus/wifiapclientsmenu.cpp
    displays/menus/wifiapsettingsmenu.cpp
    displays/menus/wifistaconfigentrymenu.cpp
    displays/menus/wifistaconfigsmenu.cpp
    displays/menus/wifistascanentrymenu.cpp
    displays/menus/wifistascanmenu.cpp
    displays/menus/wifistasettingsmenu.cpp
    displays/metersdisplay.cpp
    displays/pingpongdisplay.cpp
    displays/potiscalibratedisplay.cpp
    displays/poweroffdisplay.cpp
    displays/powersupplydisplay.cpp
    displays/qrcodedebug.cpp
    displays/qrdisplay.cpp
    displays/qrimportdisplay.cpp
    displays/speedinfodisplay.cpp
    displays/spirodisplay.cpp
    displays/starfielddisplay.cpp
    displays/statusdisplay.cpp
    displays/updatedisplay.cpp
    displays/xydebugdisplay.cpp
    dnsannounce.cpp
    dpad.cpp
    dpad3wire.cpp
    dpad5wire.cpp
    dpad5wire_2out.cpp
    dpad6wire.cpp
    dpad_boardcomputer_v2.cpp
    drivingstatistics.cpp
    espnowfunctions.cpp
    esptexthelpers.cpp
    feedbackparser.cpp
    globals.cpp
    handbremse.cpp
    icons/alert.cpp
    icons/battery.cpp
    icons/bluetooth.cpp
    icons/bms.cpp
    icons/bobbycar.cpp
    icons/buzzer.cpp
    icons/close.cpp
    icons/demos.cpp
    icons/git.cpp
    icons/graph.cpp
    icons/greenpass.cpp
    icons/hardware.cpp
    icons/info.cpp
    icons/lock.cpp
    icons/logo.cpp
    icons/modes.cpp
    icons/neopixel.cpp
    icons/poweroff.cpp
    icons/presets.cpp
    icons/reboot.cpp
    icons/scan.cpp
    icons/settings.cpp
    icons/shortcircuit.cpp
    icons/statistics.cpp
    icons/time.cpp
    icons/update.cpp
    icons/wifi.cpp
    ledstrip.cpp
    ledstripdefines.cpp
    macros_bobbycar.cpp
    main.cpp
    modeinterface.cpp
    modes.cpp
    modes/defaultmode.cpp
    modes/gametrakmode.cpp
    modes/ignoreinputmode.cpp
    modes/larsmmode.cpp
    modes/mickmode.cpp
    modes/motortestmode.cpp
    modes/remotecontrolmode.cpp
    modes/tempomatmode.cpp
    modes/wheelchairmode.cpp
    mosfets.cpp
    motorpwmlimiter.cpp
    newsettings.cpp
    ota.cpp
    potis.cpp
    presets.cpp
    profilesettings.cpp
    qrimport.cpp
    rotary.cpp
    screens.cpp
    serial_bobby.cpp
    settingspersister.cpp
    settingsutils.cpp
    softpwmlimiter.cpp
    statistics.cpp
    statustexthelper.cpp
    taskmanager.cpp
    tempomat.cpp
    texthelpers/networktexthelpers.cpp
    texthelpers/wifiaptexthelpers.cpp
    texthelpers/wifistatexthelpers.cpp
    time_bobbycar.cpp
    types.cpp
    udpcloud.cpp
    unifiedmodelmode.cpp
    utils.cpp
    webserver.cpp
    webserver_displaycontrol.cpp
    webserver_dumpnvs.cpp
    webserver_lock.cpp
    webserver_newsettings.cpp
    webserver_ota.cpp
    webserver_settings.cpp
    widgets/doubleprogressbar.cpp
    wifi_bobbycar.cpp
    wifiguiutils.cpp
)

set(dependencies
    freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver
    arduino-esp32 ArduinoJson esp-nimble-cpp FastLED-idf TFT_eSPI QRCode-esp32
    bobbycar-protocol cpputils cxx-ring-buffer date sunset
    espasynchttpreq espasyncota espchrono espcpputils espconfiglib esp-gui-lib esphttpdutils espwifistack expected fmt
)

idf_component_register(
    SRCS
        ${headers}
        ${sources}
    INCLUDE_DIRS
        .
    REQUIRES
        ${dependencies}
)

execute_process(COMMAND git rev-parse HEAD
        OUTPUT_VARIABLE GIT_REV ERROR_QUIET
)
execute_process(
        COMMAND git log -1 --pretty=%B
        OUTPUT_VARIABLE GIT_MESSAGE ERROR_QUIET
)
execute_process(
        COMMAND git rev-parse --abbrev-ref HEAD
        OUTPUT_VARIABLE GIT_BRANCH
)

string(STRIP "${GIT_REV}" GIT_REV)
string(SUBSTRING "${GIT_REV}" 1 7 GIT_SHORT_REV)
string(STRIP "${GIT_MESSAGE}" GIT_MESSAGE)
string(REPLACE "\n" " " GIT_MESSAGE "${GIT_MESSAGE}")
string(SUBSTRING "${GIT_MESSAGE}" 0 100 GIT_MESSAGE)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)

target_compile_options(${COMPONENT_TARGET}
    PRIVATE
        -fstack-reuse=all
        -fstack-protector-all
        -fdiagnostics-color=always
        -Wno-unused-function
        -Wno-deprecated-declarations
        -Wno-missing-field-initializers
        -Wno-parentheses
        -DGIT_REV="${GIT_REV}"
        -DGIT_SHORT_REV="${GIT_SHORT_REV}"
        -DGIT_MESSAGE="${GIT_MESSAGE}"
        -DGIT_BRANCH="${GIT_BRANCH}"
        -DBOBBY_DEFAULT_OTA_NAME="${BOBBY_DEFAULT_OTA_NAME}"
        ${BOBBYCAR_BUILDFLAGS}
)
