if(IDF_TARGET STREQUAL "linux")
    # Host build for led-simulator (sim-controller/): no Ethernet, Wi-Fi, mic or OTA. The sim
    # component has app_main and stands in for main.c, mic.c and ota.c.
    idf_component_register(SRCS "beat.c" "beat_dsp.c" "espnow_tx.c" "bridge.c" "store.c" "api.c" "web.c" "envelope.c" "engine.c" "rel.c" "bench.c" "audio.c"
                                "res_profile.c" "res_misc.c" "res_device.c" "res_group.c" "seqplay.c" "res_bundle.c" "audio_api.c" "patterns.c" "outputs.c" "dmx_wire.c" "ws.c" "ws_client.c" "wifi_drv.c" "bridge_serial.c" "bridge_dmx.c" "bridge_dmx_serial.c" "res_dmx.c" "auth.c"
                           INCLUDE_DIRS "." "../sim-controller/components/sim/include" "../bridge/main"
                           REQUIRES esp_http_server esp_timer esp_event cjson
                           PRIV_REQUIRES mbedtls lwip esp_app_format)
else()
    # Waveshare ESP32-P4-Nano (docs/P4_NANO.md): internal EMAC Ethernet, ES8311 mic, and the C6 next to it for
    # Wi-Fi (esp-hosted) and ESP-NOW (bridge_hosted.c talking to radio-c6/)
    idf_component_register(SRCS "main.c" "mic.c" "beat.c" "beat_dsp.c" "espnow_tx.c" "bridge.c" "store.c" "api.c" "web.c" "envelope.c" "engine.c" "rel.c" "bench.c" "audio.c" "ota.c"
                                "res_profile.c" "res_misc.c" "res_device.c" "res_group.c" "seqplay.c" "res_bundle.c" "audio_api.c" "patterns.c" "outputs.c" "dmx_wire.c" "ws.c" "ws_client.c" "wifi_drv.c" "res_dmx.c" "auth.c"
                                "bridge_hosted.c" "c6_update.c"
                                # the simulated rig at /sim/, shared with the host builds
                                "../sim-controller/components/sim/sim_rig.c" "../sim-controller/components/sim/sim_net.c"
                           INCLUDE_DIRS "." "../bridge/main"
                           PRIV_INCLUDE_DIRS "../sim-controller/components/sim"
                           REQUIRES esp_eth esp_netif esp_event esp_driver_gpio nvs_flash app_update esp_app_format
                                    esp_http_server esp_timer esp_driver_i2s esp_driver_i2c esp_wifi esp_rom cjson
                                    esp_hosted esp_wifi_remote esp_codec_dev esp_partition bootloader_support
                           PRIV_REQUIRES littlefs mdns mbedtls lwip)
endif()

# The gzipped web UI is embedded in the app image (run tools/build_web.sh first)
if(NOT EXISTS ${COMPONENT_DIR}/../www_dist/www.pack)
    message(FATAL_ERROR "www_dist/www.pack is missing: run tools/build_web.sh (make build does)")
endif()
target_add_binary_data(${COMPONENT_LIB} ${COMPONENT_DIR}/../www_dist/www.pack BINARY)

# The simulated rig's page and drivers (tools/build_sim_web.sh), served at /sim/. The host build embeds its own
# copy (the sim component). Without it the firmware still builds, and /sim/ says how to build the rig.
if(NOT IDF_TARGET STREQUAL "linux")
    set(SIM_PACK ${COMPONENT_DIR}/../www_dist/sim.pack)
    if(NOT EXISTS ${SIM_PACK})
        file(WRITE ${SIM_PACK} "WWW1")
    endif()
    target_add_binary_data(${COMPONENT_LIB} ${SIM_PACK} BINARY)
endif()
