set(BOBBY_HEADERS
    accessorhelpers.h
    antbms.h
    antbmsmanager.h
    accessors/globalaccessors.h
    accessors/settingsaccessors.h
    accessors/wifiaccessors.h
    accessors/wifiapconfigaccessors.h
    accessors/wifistaconfigaccessors.h
    actions/assertaction.h
    actions/bmsclearscanaction.h
    actions/bmsscanaction.h
    actions/dividebyzeroaction.h
    actions/erasenvsaction.h
    actions/ledstripanimationactions.h
    actions/ledstripblinkactions.h
    actions/loadsettingsaction.h
    actions/modesettingsaction.h
    actions/qraction.h
    actions/resetnvsaction.h
    actions/savesettingsaction.h
    actions/setupactions.h
    actions/switchprofileaction.h
    actions/tempomatmodeapplycurrentpeedaction.h
    actions/updateswapfrontbackaction.h
    actions/wifiscanaction.h
    actions/wifistascanaction.h
    actions/wifistascanclearaction.h
    battery.h
    ble_bobby.h
    bmsutils.h
    bobbyblinker.h
    bobbybuttons.h
    bobbyhupe.h
    bobbyquickactions.h
    bobbyschedulertask.h
    bobbytypesafeenum.h
    buildserver.h
    can.h
    changevaluedisplay_bobbyquickactions.h
    changevaluedisplay_controlmode.h
    changevaluedisplay_controltype.h
    changevaluedisplay_larsmmode_mode.h
    changevaluedisplay_unifiedmodelmode.h
    cloud.h
    configutils_bobby.h
    controller.h
    debugcolorhelpers.h
    debuginputhandler.h
    dnsannounce.h
    dpad.h
    dpad3wire.h
    dpad5wire.h
    dpad5wire_2out.h
    dpad6wire.h
    dpad_boardcomputer_v2.h
    drivingstatistics.h
    espnowfunctions.h
    feedbackemulator.h
    feedbackparser.h
    globals.h
    guihelpers/bobbychangevaluedisplay.h
    guihelpers/bobbycheckbox.h
    guihelpers/bobbycheckboxicon.h
    guihelpers/bobbydisplay.h
    guihelpers/bobbydisplaywithtitle.h
    guihelpers/bobbyerrorhandler.h
    guihelpers/bobbygraphdisplay.h
    guihelpers/bobbymenudisplay.h
    guihelpers/bobbypopupdisplay.h
    guihelpers/bobbysplitgraphdisplay.h
    guihelpers/menudisplaywithtime.cpp
    guihelpers/menudisplaywithtime.h
    handbremse.h
    icons/alert.h
    icons/back.h
    icons/battery.h
    icons/bluetooth.h
    icons/bms.h
    icons/bobbycar.h
    icons/buzzer.h
    icons/checked.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/unchecked.h
    icons/update.h
    icons/wifi.h
    ledstrip.h
    ledstripdefines.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
    screens/aboutmenu.h
    screens/batterydebugmenu.h
    screens/batterygraphdisplay.h
    screens/batteryinfodisplay.h
    screens/batterymenu.h
    screens/blesettingsmenu.h
    screens/bmsscanmenu.h
    screens/boardcomputerhardwaresettingsmenu.h
    screens/buzzermenu.h
    screens/calibratevoltagedisplay.h
    screens/candebugmenu.h
    screens/cloudsettingsmenu.h
    screens/commanddebugmenu.h
    screens/confiscationdisplay.h
    screens/controllerhardwaresettingsmenu.h
    screens/crashmenu.h
    screens/debugmenu.h
    screens/defaultmodesettingsmenu.h
    screens/demosmenu.h
    screens/dynamicdebugmenu.h
    screens/enablemenu.h
    screens/espnowmenu.h
    screens/espnowsettingsmenu.h
    screens/extrabuttoncalibratemenu.h
    screens/featureflagsmenu.h
    screens/feedbackdebugmenu.h
    screens/gameoflifedisplay.h
    screens/gametrakcalibratedisplay.h
    screens/gametrakmodesettingsmenu.h
    screens/garagemenu.h
    screens/gitmenu.h
    screens/graphsmenu.h
    screens/greenpassmenu.h
    screens/handbremssettingsmenu.h
    screens/invertmenu.h
    screens/joystickdebugdisplay.h
    screens/larsmmodesettingsmenu.h
    screens/ledstripcolorsdisplay.h
    screens/ledstripmenu.h
    screens/ledstripselectblinkmenu.h
    screens/ledstripselectotamode.h
    screens/limitssettingsmenu.h
    screens/lockscreen.h
    screens/lockscreensettingsmenu.h
    screens/mainmenu.h
    screens/manageprofilesmenu.h
    screens/metersdisplay.h
    screens/mickmodesettingsmenu.h
    screens/modessettingsmenu.h
    screens/mosfetsmenu.h
    screens/motorfeedbackdebugmenu.h
    screens/motorstatedebugmenu.h
    screens/motortestmodesettingsmenu.h
    screens/networksettingsmenu.h
    screens/otamenu.h
    screens/pingpongdisplay.h
    screens/poweroffdisplay.h
    screens/powersupplydisplay.h
    screens/profilesmenu.h
    screens/qrcodedebug.h
    screens/qrdisplay.h
    screens/qrimportdisplay.h
    screens/rebootscreen.h
    screens/recoverymenu.h
    screens/remotecontrolmodesettingsmenu.h
    screens/resetnvsscreen.h
    screens/selectbuildserverbranch.h
    screens/selectbuildservermenu.h
    screens/selectmodemenu.h
    screens/selectotabuildmenu.h
    screens/settingsmenu.h
    screens/setup/ask_calibrate_other_buttons.h
    screens/setup/ask_setup_clouds.h
    screens/setup/basic_buttons.h
    screens/setup/calibrate_potis.h
    screens/setup/final_information.h
    screens/setup/information.h
    screens/setup/setup_cloud.h
    screens/setupquickactionsmenu.h
    screens/speedinfodisplay.h
    screens/spirodisplay.h
    screens/starfielddisplay.h
    screens/statisticsmenu.h
    screens/statusdisplay.h
    screens/taskmanagermenu.h
    screens/tempomatmodesettingsmenu.h
    screens/timersmenu.h
    screens/timesettingsmenu.h
    screens/typesafeenumchangemenu.h
    screens/udpcloudsettingsmenu.h
    screens/updatedisplay.h
    screens/wifiapclientsmenu.h
    screens/wifiapsettingsmenu.h
    screens/wifistaconfigentrymenu.h
    screens/wifistaconfigsmenu.h
    screens/wifistascanentrymenu.h
    screens/wifistascanmenu.h
    screens/wifistasettingsmenu.h
    screens/xydebugdisplay.h
    serial_bobby.h
    settingspersister.h
    settingsutils.h
    setup.h
    softpwmlimiter.h
    statistics.h
    taskmanager.h
    tempomat.h
    texthelpers/bletexthelpers.h
    texthelpers/cloudtexthelpers.h
    texthelpers/debugtexthelpers.h
    texthelpers/esptexthelpers.h
    texthelpers/networktexthelpers.h
    texthelpers/statustexthelper.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(BOBBY_SOURCES
    antbms.cpp
    antbmsmanager.cpp
    accessors/wifistaconfigaccessors.cpp
    actions/assertaction.cpp
    actions/bmsclearscanaction.cpp
    actions/bmsscanaction.cpp
    actions/dividebyzeroaction.cpp
    actions/ledstripanimationactions.cpp
    actions/ledstripblinkactions.cpp
    actions/modesettingsaction.cpp
    actions/qraction.cpp
    actions/setupactions.cpp
    actions/wifistascanaction.cpp
    actions/wifistascanclearaction.cpp
    battery.cpp
    ble_bobby.cpp
    bmsutils.cpp
    bobbyblinker.cpp
    bobbybuttons.cpp
    bobbyhupe.cpp
    bobbyquickactions.cpp
    buildserver.cpp
    can.cpp
    changevaluedisplay_bobbyquickactions.cpp
    changevaluedisplay_controlmode.cpp
    changevaluedisplay_controltype.cpp
    changevaluedisplay_larsmmode_mode.cpp
    changevaluedisplay_unifiedmodelmode.cpp
    cloud.cpp
    configwrapper_bobby.cpp
    controller.cpp
    debuginputhandler.cpp
    dnsannounce.cpp
    dpad5wire.cpp
    dpad5wire_2out.cpp
    dpad6wire.cpp
    dpad_boardcomputer_v2.cpp
    drivingstatistics.cpp
    espnowfunctions.cpp
    feedbackemulator.cpp
    globals.cpp
    guihelpers/bobbychangevaluedisplay.cpp
    guihelpers/bobbydisplay.cpp
    guihelpers/bobbydisplaywithtitle.cpp
    guihelpers/bobbyerrorhandler.cpp
    guihelpers/bobbygraphdisplay.cpp
    guihelpers/bobbymenudisplay.cpp
    guihelpers/bobbypopupdisplay.cpp
    guihelpers/bobbysplitgraphdisplay.cpp
    handbremse.cpp
    icons/alert.cpp
    icons/back.cpp
    icons/battery.cpp
    icons/bluetooth.cpp
    icons/bms.cpp
    icons/bobbycar.cpp
    icons/buzzer.cpp
    icons/checked.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/unchecked.cpp
    icons/update.cpp
    icons/wifi.cpp
    ledstrip.cpp
    main.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
    qrimport.cpp
    screens.cpp
    screens/aboutmenu.cpp
    screens/batterydebugmenu.cpp
    screens/batterygraphdisplay.cpp
    screens/batteryinfodisplay.cpp
    screens/batterymenu.cpp
    screens/blesettingsmenu.cpp
    screens/bmsscanmenu.cpp
    screens/boardcomputerhardwaresettingsmenu.cpp
    screens/buzzermenu.cpp
    screens/calibratevoltagedisplay.cpp
    screens/candebugmenu.cpp
    screens/cloudsettingsmenu.cpp
    screens/confiscationdisplay.cpp
    screens/controllerhardwaresettingsmenu.cpp
    screens/crashmenu.cpp
    screens/debugmenu.cpp
    screens/defaultmodesettingsmenu.cpp
    screens/demosmenu.cpp
    screens/dynamicdebugmenu.cpp
    screens/enablemenu.cpp
    screens/espnowmenu.cpp
    screens/espnowsettingsmenu.cpp
    screens/extrabuttoncalibratemenu.cpp
    screens/featureflagsmenu.cpp
    screens/gameoflifedisplay.cpp
    screens/garagemenu.cpp
    screens/gitmenu.cpp
    screens/graphsmenu.cpp
    screens/greenpassmenu.cpp
    screens/handbremssettingsmenu.cpp
    screens/invertmenu.cpp
    screens/joystickdebugdisplay.cpp
    screens/larsmmodesettingsmenu.cpp
    screens/ledstripcolorsdisplay.cpp
    screens/ledstripmenu.cpp
    screens/ledstripselectblinkmenu.cpp
    screens/ledstripselectotamode.cpp
    screens/limitssettingsmenu.cpp
    screens/lockscreen.cpp
    screens/lockscreensettingsmenu.cpp
    screens/mainmenu.cpp
    screens/manageprofilesmenu.cpp
    screens/metersdisplay.cpp
    screens/mickmodesettingsmenu.cpp
    screens/modessettingsmenu.cpp
    screens/mosfetsmenu.cpp
    screens/motortestmodesettingsmenu.cpp
    screens/networksettingsmenu.cpp
    screens/otamenu.cpp
    screens/pingpongdisplay.cpp
    screens/poweroffdisplay.cpp
    screens/powersupplydisplay.cpp
    screens/profilesmenu.cpp
    screens/qrcodedebug.cpp
    screens/qrdisplay.cpp
    screens/qrimportdisplay.cpp
    screens/rebootscreen.cpp
    screens/recoverymenu.cpp
    screens/remotecontrolmodesettingsmenu.cpp
    screens/resetnvsscreen.cpp
    screens/selectbuildserverbranch.cpp
    screens/selectbuildservermenu.cpp
    screens/selectmodemenu.cpp
    screens/selectotabuildmenu.cpp
    screens/settingsmenu.cpp
    screens/setup/ask_calibrate_other_buttons.cpp
    screens/setup/ask_setup_clouds.cpp
    screens/setup/basic_buttons.cpp
    screens/setup/calibrate_potis.cpp
    screens/setup/final_information.cpp
    screens/setup/information.cpp
    screens/setup/setup_cloud.cpp
    screens/setupquickactionsmenu.cpp
    screens/speedinfodisplay.cpp
    screens/spirodisplay.cpp
    screens/starfielddisplay.cpp
    screens/statisticsmenu.cpp
    screens/statusdisplay.cpp
    screens/taskmanagermenu.cpp
    screens/tempomatmodesettingsmenu.cpp
    screens/timersmenu.cpp
    screens/timesettingsmenu.cpp
    screens/typesafeenumchangemenu.cpp
    screens/udpcloudsettingsmenu.cpp
    screens/updatedisplay.cpp
    screens/wifiapclientsmenu.cpp
    screens/wifiapsettingsmenu.cpp
    screens/wifistaconfigentrymenu.cpp
    screens/wifistaconfigsmenu.cpp
    screens/wifistascanentrymenu.cpp
    screens/wifistascanmenu.cpp
    screens/wifistasettingsmenu.cpp
    screens/xydebugdisplay.cpp
    serial_bobby.cpp
    settingspersister.cpp
    settingsutils.cpp
    setup.cpp
    softpwmlimiter.cpp
    statistics.cpp
    taskmanager.cpp
    tempomat.cpp
    texthelpers/cloudtexthelpers.cpp
    texthelpers/networktexthelpers.cpp
    texthelpers/wifiaptexthelpers.cpp
    texthelpers/wifistatexthelpers.cpp
    time_bobbycar.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 esp_adc
    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
        ${BOBBY_HEADERS}
        ${BOBBY_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
)
execute_process(
        COMMAND git status --short
        OUTPUT_VARIABLE GIT_STATUS
)

if (NOT GIT_STATUS STREQUAL "")
    set(GIT_STATUS "dirty")
else()
    set(GIT_STATUS "clean")
endif()

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(REPLACE "\"" "\\\"" GIT_MESSAGE "${GIT_MESSAGE}")
string(REPLACE ";" " " GIT_MESSAGE "${GIT_MESSAGE}")
string(SUBSTRING "${GIT_MESSAGE}" 0 100 GIT_MESSAGE)
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)

message(WARNING "Git revision: ${GIT_REV}")
message(WARNING "Git short revision: ${GIT_SHORT_REV}")
message(WARNING "Git message: ${GIT_MESSAGE}")
message(WARNING "Git branch: ${GIT_BRANCH}")
message(WARNING "Git status: ${GIT_STATUS}")

if(NOT DEFINED BOBBY_DEFAULT_USERNAME)
    message(FATAL_ERROR "Please define BOBBY_DEFAULT_USERNAME")
endif()

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_USERNAME="${BOBBY_DEFAULT_USERNAME}"
        ${BOBBYCAR_BUILDFLAGS}
        -Werror=unused-but-set-variable
)
