update to mbed_generate_bin_hex cmake function

pull/15297/head
byq77 2022-06-15 17:03:53 +02:00
parent 54e8693ef4
commit 21ca5b62c9
1 changed files with 15 additions and 8 deletions

View File

@ -6,32 +6,39 @@
# #
function(mbed_generate_bin_hex target) function(mbed_generate_bin_hex target)
get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) 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") if (MBED_TOOLCHAIN STREQUAL "GCC_ARM")
# The first condition is quoted in case MBED_OUTPUT_EXT is unset # The first condition is quoted in case MBED_OUTPUT_EXT is unset
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
list(APPEND CMAKE_POST_BUILD_COMMAND list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
) )
endif() endif()
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
list(APPEND CMAKE_POST_BUILD_COMMAND list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
) )
endif() endif()
elseif(MBED_TOOLCHAIN STREQUAL "ARM") elseif(MBED_TOOLCHAIN STREQUAL "ARM")
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER) get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
list(APPEND CMAKE_POST_BUILD_COMMAND list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $<TARGET_FILE:${target}> COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin $<TARGET_FILE:${target}>
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin"
) )
endif() endif()
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
list(APPEND CMAKE_POST_BUILD_COMMAND list(APPEND CMAKE_POST_BUILD_COMMAND
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex $<TARGET_FILE:${target}> COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex $<TARGET_FILE:${target}>
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex"
) )
endif() endif()
endif() endif()