if("${ARDUINO_ESP8266_TOOLS}" STREQUAL "" AND NOT "$ENV{ARDUINO_ESP8266_TOOLS}" STREQUAL "")
    set(ARDUINO_ESP8266_TOOLS "$ENV{ARDUINO_ESP8266_TOOLS}" CACHE PATH "Path to the directory containing ESP8266 tools")
else()
    if("${ARDUINO_ESP8266_TOOLS}" STREQUAL "")
        if(EXISTS "${ARDUINO_ESP8266_DIR}/tools/xtensa-lx106-elf-gcc")
            set(ARDUINO_ESP8266_TOOLS "${ARDUINO_ESP8266_DIR}/tools" CACHE PATH "Path to the directory containing ESP8266 tools")
        endif()
    endif()
    if("${ARDUINO_ESP8266_TOOLS}" STREQUAL "" AND NOT "${ARDUINO_USER}" STREQUAL "")
        if(EXISTS "${ARDUINO_USER}/packages/esp8266/tools/xtensa-lx106-elf-gcc")
            set(ARDUINO_ESP8266_TOOLS "${ARDUINO_USER}/packages/esp8266/tools" CACHE PATH "Path to the directory containing ESP8266 tools")
        endif()
    endif()
endif()
if(NOT "${ARDUINO_ESP8266_TOOLS}" STREQUAL "")
    message(STATUS "Using ARDUINO_ESP8266_TOOLS ${ARDUINO_ESP8266_TOOLS}")
else()
    message(FATAL_ERROR "ARDUINO_ESP8266_TOOLS is not set and ESP8266 tools could not be found")
endif()
