run_size_tool.cmake 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # A CMake script to run size tool commands supporting SIZE_OUTPUT_FORMAT and
  2. # OUTPUT_JSON environment variables from within ninja or make or another
  3. # cmake-based build runner.
  4. #
  5. # It is recommended to NOT USE this CMake script if you have the option of
  6. # running the tool directly. This script exists only for use inside CMake builds.
  7. cmake_minimum_required(VERSION 3.16)
  8. # Main purpose of this script: we can't expand these environment variables in the main IDF CMake build,
  9. # because we want to expand them at CMake target build time not at CMake configuration time
  10. # (so they can change without needing a CMake re-run)
  11. set(IDF_SIZE_CMD ${IDF_SIZE_TOOL})
  12. if(NOT DEFINED ENV{SIZE_OUTPUT_FORMAT} OR "$ENV{SIZE_OUTPUT_FORMAT}" STREQUAL "default")
  13. # Format not passed to "idf.py size" explicitly, or this target was invoked
  14. # from make/ninja directly (without idf.py)
  15. if(DEFINED OUTPUT_JSON AND OUTPUT_JSON)
  16. # honor the legacy OUTPUT_JSON variable, if set
  17. list(APPEND IDF_SIZE_CMD "--format=json")
  18. endif()
  19. elseif(DEFINED ENV{SIZE_OUTPUT_FORMAT})
  20. # specific format was requested
  21. list(APPEND IDF_SIZE_CMD "--format=$ENV{SIZE_OUTPUT_FORMAT}")
  22. endif()
  23. if(DEFINED ENV{SIZE_OUTPUT_FILE})
  24. list(APPEND IDF_SIZE_CMD "--output-file=$ENV{SIZE_OUTPUT_FILE}")
  25. endif()
  26. if(DEFINED IDF_SIZE_MODE)
  27. list(APPEND IDF_SIZE_CMD ${IDF_SIZE_MODE})
  28. endif()
  29. list(APPEND IDF_SIZE_CMD ${MAP_FILE})
  30. execute_process(COMMAND ${IDF_SIZE_CMD}
  31. RESULT_VARIABLE result
  32. )
  33. if(${result})
  34. message(FATAL_ERROR "${IDF_SIZE_TOOL} failed")
  35. endif()