Skip to content

Commit 8075b23

Browse files
authored
Merge pull request #14472 from LDong-Arm/cmake_output_ext
CMake: support `OUTPUT_EXT` from `targets.json`
2 parents 616f0b7 + 45a3c71 commit 8075b23

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

CMakeLists.txt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,34 @@ target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
144144
#
145145
function(mbed_generate_bin_hex target)
146146
get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN)
147-
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
148-
set(CMAKE_POST_BUILD_COMMAND
149-
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin
150-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
151-
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex
152-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
153-
)
147+
if (MBED_TOOLCHAIN STREQUAL "GCC_ARM")
148+
# The first condition is quoted in case MBED_OUTPUT_EXT is unset
149+
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
150+
list(APPEND CMAKE_POST_BUILD_COMMAND
151+
COMMAND ${elf_to_bin} -O binary $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin
152+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
153+
)
154+
endif()
155+
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
156+
list(APPEND CMAKE_POST_BUILD_COMMAND
157+
COMMAND ${elf_to_bin} -O ihex $<TARGET_FILE:${target}> ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex
158+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
159+
)
160+
endif()
154161
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
155162
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
156-
set(CMAKE_POST_BUILD_COMMAND
157-
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $<TARGET_FILE:${target}>
158-
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
163+
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin")
164+
list(APPEND CMAKE_POST_BUILD_COMMAND
165+
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $<TARGET_FILE:${target}>
166+
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
167+
)
168+
endif()
169+
if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex")
170+
list(APPEND CMAKE_POST_BUILD_COMMAND
159171
COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex $<TARGET_FILE:${target}>
160172
COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex"
161-
)
173+
)
174+
endif()
162175
endif()
163176
add_custom_command(
164177
TARGET

targets/targets.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,7 +4855,8 @@
48554855
"ARMCLANG",
48564856
"GNUARM"
48574857
],
4858-
"tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_B1"
4858+
"tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_B1",
4859+
"OUTPUT_EXT": "bin"
48594860
},
48604861
"ARM_MUSCA_S1": {
48614862
"inherits": [
@@ -4910,7 +4911,8 @@
49104911
"tfm_delivery_dir": "TARGET_ARM_SSG/TARGET_MUSCA_S1",
49114912
"detect_code": [
49124913
"5009"
4913-
]
4914+
],
4915+
"OUTPUT_EXT": "bin"
49144916
},
49154917
"RZ_A1XX": {
49164918
"inherits": [

0 commit comments

Comments
 (0)