1# For armclang the elfconvert command is made into a script. 2# Reason for that is because not a single command covers all use cases, 3# and it must therefore be possible to call individual commands, depending 4# on the arguments used. 5cmake_minimum_required(VERSION 3.20.0) 6 7# Handle stripping 8if (STRIP_DEBUG OR STRIP_ALL) 9 set(obj_copy_target_output "--elf") 10 if(STRIP_ALL) 11 set(obj_copy_strip "--strip=all") 12 elseif(STRIP_DEBUG) 13 set(obj_copy_strip "--strip=debug") 14 endif() 15endif() 16 17# Unknown support of --srec-len in arm-ds 18 19# Handle Input and Output target types 20if(DEFINED OUTTARGET) 21 if(${OUTTARGET} STREQUAL "srec") 22 set(obj_copy_target_output "--m32") 23 elseif(${OUTTARGET} STREQUAL "ihex") 24 set(obj_copy_target_output "--i32combined") 25 elseif(${OUTTARGET} STREQUAL "binary") 26 set(obj_copy_target_output "--bincombined") 27 if(GAP_FILL) 28 set(obj_copy_gap_fill "--bincombined_padding=1,${GAP_FILL}") 29 endif() 30 endif() 31endif() 32 33if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary") 34 set(obj_copy_target_output "--bin") 35 set(outfile_dir .dir) 36 string(REGEX REPLACE "^[\.]" "" only_section_clean "${ONLY_SECTION}") 37endif() 38 39# Note: fromelf is a little special regarding bin output, as each section gets 40# its own file. This means that when only a specific section is required 41# then that section must be moved to correct location. 42execute_process( 43 COMMAND ${FROMELF} 44 ${obj_copy_strip} 45 ${obj_copy_gap_fill} ${obj_copy_target_output} 46 --output ${OUTFILE}${outfile_dir} ${INFILE} 47) 48 49if(DEFINED ONLY_SECTION AND "${OUTTARGET}" STREQUAL "binary") 50 execute_process( 51 COMMAND ${CMAKE_COMMAND} -E copy 52 ${OUTFILE}${outfile_dir}/${only_section_clean} ${OUTFILE} 53 ) 54endif() 55