mirror of https://github.com/ARMmbed/mbed-os.git
CMake: Image format based on MBED_OUTPUT_EXT
Requires: https://github.com/ARMmbed/mbed-tools/pull/242 The optional `OUTPUT_EXT` field in Mbed OS `targets.json` specifies the format of the output image. This is important because * some targets only support one image format * each post-binary hook outputs one image only This avoids confusion of having both .hex and .bin images generated while only one of them is usable.pull/14472/head
parent
54a5fc5f15
commit
45a3c7193f
|
|
@ -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 $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
|
||||
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${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 $<TARGET_FILE:${target}> ${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 $<TARGET_FILE:${target}> ${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 $<TARGET_FILE:${target}>
|
||||
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 $<TARGET_FILE:${target}>
|
||||
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 $<TARGET_FILE:${target}>
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
|
||||
)
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET
|
||||
|
|
|
|||
Loading…
Reference in New Issue