I'm trying to add a post-build command to a small project which will automatically take my build output file (ELF) and convert it to an Intel HEX format for flashing on a microcontroller.
When I add this command however, the build fails. It repeats the command with all of the CMake variable strings substituted in that is run by the shell and post-fixes it with : not found.
When I run that exact line in the terminal after a normal successful build of the ELF, it works as expected. Is there a gotcha I'm missing somewhere with how CMake handles this?
I've added the target to my CMakeLists.txt as follows:
add_custom_command(
TARGET ${EXECUTABLE_NAME}
POST_BUILD
COMMAND "${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME} ${PROJECT_NAME}.hex"
)
The command ends up resolving to <absolute-path>/avr-objcopy -O ihex test_blink.elf test_blink.hex which I can verify since it's printed by CMake out to the terminal.
This string is wrong:
COMMAND "${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_NAME} ${PROJECT_NAME}.hex"
You should use the ARGS keyword:
COMMAND ${CMAKE_OBJCOPY} ARGS -O ihex ${EXECUTABLE_NAME} ${PROJECT_NAME}.hex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With