Skip to content

Commit 21ca5b6

Browse files
committed
update to mbed_generate_bin_hex cmake function
1 parent 54e8693 commit 21ca5b6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tools/cmake/mbed_set_post_build.cmake

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,39 @@
66
#
77
function(mbed_generate_bin_hex target)
88
get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN)
9+
get_target_property(artifact_name ${target} ARTIFACT_NAME)
10+
11+
# set to the target name if the property is unset
12+
if(artifact_name STREQUAL "artifact_name-NOTFOUND" OR artifact_name STREQUAL "")
13+
set(artifact_name ${target})
14+
endif()
15+
916
if (MBED_TOOLCHAIN STREQUAL "GCC_ARM")
1017
# The first condition is quoted in case MBED_OUTPUT_EXT is unset
1118
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
1219
list(APPEND CMAKE_POST_BUILD_COMMAND
13-
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin
14-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
20+
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin
21+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
1522
)
1623
endif()
1724
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
1825
list(APPEND CMAKE_POST_BUILD_COMMAND
19-
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex
20-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
26+
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
27+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
2128
)
2229
endif()
2330
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
2431
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
2532
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
2633
list(APPEND CMAKE_POST_BUILD_COMMAND
27-
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $<TARGET_FILE:${target}>
28-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
34+
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin $<TARGET_FILE:${target}>
35+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
2936
)
3037
endif()
3138
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
3239
list(APPEND CMAKE_POST_BUILD_COMMAND
33-
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex $<TARGET_FILE:${target}>
34-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
40+
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex $<TARGET_FILE:${target}>
41+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
3542
)
3643
endif()
3744
endif()

0 commit comments

Comments
 (0)