Author Topic: [SOLVED]ESP-IDF: how can you run a command after the build?  (Read 712 times)

0 Members and 1 Guest are viewing this topic.

Offline JPorticiTopic starter

  • Super Contributor
  • ***
  • Posts: 3912
  • Country: it
[SOLVED]ESP-IDF: how can you run a command after the build?
« on: February 06, 2026, 08:35:17 am »
Using ESP-IDF under VSCodium. I've been scratching my head but i haven't found a solution yet.
What i want is to rename and copy the firmware file from the build directory to another place, then run a small program to format it into a custom update file.

I've been looking at some threads in the ESP forum regarding the same issue (how to do stuff post build in CMake):
https://esp32.com/viewtopic.php?t=45081
https://esp32.com/viewtopic.php?t=33801

If i understood if correctly, i should just take the CMakeList.txt in the "main" folder and "add_custom_command", but i can't find what should i use for TARGET. Seems strange to me there weren't any direct pointers in the ESP documentation

The first thread i linked was actually helpful in the sense that it actually shows how to create a dummy target and run a script after the build, though it's not exactly what i want (creating files and whatever, i'm also getting warnings) but then there is another problem: if the COMMAND is "echo ${PROJECT_NAME}" i actually get the project name.. if instead if pass ${PROJECT_NAME} as an argument to the command "ESP-IDF" is passed instead.

Has anybody had to do the same?


EDIT:
Well, a couple of days of googling and reading took me nowhere.
I had a fluke so instead i searched for "esp python script after build"
which pointed at this github issue: https://github.com/espressif/esp-idf/issues/9885

So, for future reference, it's as simple as going to the project's global CMakeList.txt and add this

Code: [Select]
idf_build_get_property(elf EXECUTABLE)
add_custom_command(
  TARGET ${elf}
  POST_BUILD
  COMMAND echo "so much time wasted for something so simple"
)

well, actually
Code: [Select]
add_custom_command(
  TARGET app
  POST_BUILD
  COMMAND echo "the previous is after ELF generation, this one is after bin generation and happens every time"
)
« Last Edit: February 06, 2026, 11:35:02 am by JPortici »
 
The following users thanked this post: xvr


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf