From 21ca5b62c9d586a4ea17000f5042f2c5a085fe79 Mon Sep 17 00:00:00 2001 From: byq77 Date: Wed, 15 Jun 2022 17:03:53 +0200 Subject: [PATCH] update to mbed_generate_bin_hex cmake function --- tools/cmake/mbed_set_post_build.cmake | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/cmake/mbed_set_post_build.cmake b/tools/cmake/mbed_set_post_build.cmake index f381d0a4dcf..d68776db1bc 100644 --- a/tools/cmake/mbed_set_post_build.cmake +++ b/tools/cmake/mbed_set_post_build.cmake @@ -6,32 +6,39 @@ # function(mbed_generate_bin_hex target) get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) + get_target_property(artifact_name ${target} ARTIFACT_NAME) + + # set to the target name if the property is unset + if(artifact_name STREQUAL "artifact_name-NOTFOUND" OR artifact_name STREQUAL "") + set(artifact_name ${target}) + endif() + if (MBED_TOOLCHAIN STREQUAL "GCC_ARM") # The first condition is quoted in case MBED_OUTPUT_EXT is unset if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} -O binary $ ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" + COMMAND ${elf_to_bin} -O binary $ ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin" ) endif() if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} -O ihex $ ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" + COMMAND ${elf_to_bin} -O ihex $ ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex" ) endif() elseif(MBED_TOOLCHAIN STREQUAL "ARM") get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER) if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $ - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" + COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin $ + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin" ) endif() if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex $ - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" + COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex $ + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex" ) endif() endif()