Skip to content

Convert the ELF output to srec

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 motorola SRecord format (*.srec).

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 .srec
function(iar_elf_tool_srec TARGET)
  add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_IAR_ELFTOOL} --silent --srec $<TARGET_FILE:${TARGET}> $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>>,$<TARGET_PROPERTY:${TARGET},OUTPUT_NAME>,$<TARGET_PROPERTY:${TARGET},NAME>>.srec)
endfunction()
  • Call the iar_elf_tool_srec(<target>) function replacing <target> by the actual executable target. Example:
iar_elf_tool_srec(MyTarget)
  • Build the target.

  • Find MyTarget.srec inside the build subdirectory.

Note

${CMAKE_IAR_ELFTOOL} is automatically detected by CMake

Clone this wiki locally