run_esptool.cmake 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # A CMake script to run esptool commands from within ninja or make
  2. # or another cmake-based build runner
  3. #
  4. # (Needed to expand environment variables, for backwards compatibility.)
  5. #
  6. # It is recommended to NOT USE this CMake script if you have the option of
  7. # running esptool.py directly. This script exists only for use inside CMake builds.
  8. #
  9. cmake_minimum_required(VERSION 3.5)
  10. if(NOT IDF_PATH OR NOT ESPTOOLPY OR NOT ESPTOOL_ARGS OR NOT ESPTOOL_WORKING_DIR)
  11. message(FATAL_ERROR "IDF_PATH, ESPTOOLPY, ESPTOOL_ARGS, and ESPTOOL_WORKING_DIR must "
  12. "be specified on the CMake command line. For direct esptool execution, it is "
  13. "strongly recommended to run esptool.py directly.")
  14. endif()
  15. # Note: we can't expand these environment variables in the main IDF CMake build,
  16. # because we want to expand them at flashing time not at CMake runtime (so they can change
  17. # without needing a CMake re-run)
  18. set(ESPPORT $ENV{ESPPORT})
  19. if(NOT ESPPORT)
  20. message("Note: esptool.py will search for a serial port. To specify a port, set the ESPPORT environment variable.")
  21. else()
  22. set(port_arg "-p ${ESPPORT}")
  23. endif()
  24. set(ESPBAUD $ENV{ESPBAUD})
  25. if(NOT ESPBAUD)
  26. message("Note: Using default baud rate 460800. To modify, set ESPBAUD environment variable.")
  27. set(ESPBAUD 460800)
  28. endif()
  29. include("${IDF_PATH}/tools/cmake/utilities.cmake")
  30. set(cmd "${ESPTOOLPY} ${port_arg} -b ${ESPBAUD} ${ESPTOOL_ARGS}")
  31. spaces2list(cmd)
  32. execute_process(COMMAND ${cmd}
  33. WORKING_DIRECTORY "${ESPTOOL_WORKING_DIR}"
  34. RESULT_VARIABLE result
  35. )
  36. if(${result})
  37. # No way to have CMake silently fail, unfortunately
  38. message(FATAL_ERROR "esptool.py failed")
  39. endif()