diff --git a/CMakeLists.txt b/CMakeLists.txt index ad61efd96b5..03ac543a450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,21 +144,34 @@ target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED}) # function(mbed_generate_bin_hex target) get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) - if(MBED_TOOLCHAIN STREQUAL "GCC_ARM") - set(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 ihex $ ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" - ) + 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" + ) + 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" + ) + endif() elseif(MBED_TOOLCHAIN STREQUAL "ARM") get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER) - set(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" + 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" + ) + 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" - ) + ) + endif() endif() add_custom_command( TARGET diff --git a/targets/targets.json b/targets/targets.json index ef62982274e..2b68f7ac3a9 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -4855,7 +4855,8 @@ "ARMCLANG", "GNUARM" ], - "tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_B1" + "tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_B1", + "OUTPUT_EXT": "bin" }, "ARM_MUSCA_S1": { "inherits": [ @@ -4910,7 +4911,8 @@ "tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_S1", "detect_code": [ "5009" - ] + ], + "OUTPUT_EXT": "bin" }, "RZ_A1XX": { "inherits": [