Skip to content

Convert the ELF output to hex

Felipe Torrezan edited this page Apr 13, 2024 · 2 revisions

Introduction

A CMake function can be used to convert an executable (*.elf or *.out) to the Intel Hexadecimal format (*.hex).

Applies to

  • CMake projects using the IAR C/C++ Compilers with the IAR ILINK technology.

Tasks

  • Add the following function() to the CMake project:
# Convert the ELF output to .hex
function(iar_elf_tool_hex TARGET)
  add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --ihex $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.hex)
endfunction()
  • Call the iar_elf_tool_hex(<target>) function replacing <target> by the actual executable target. Example:
iar_elf_tool_hex(MyTarget)
  • Build the target.

  • Find MyTarget.hex inside the build subdirectory.

Note

${CMAKE_IAR_ELFTOOL} is automatically detected by CMake

Clone this wiki locally