mirror of https://github.com/ARMmbed/mbed-os.git
Cypress: Improve `mbed_post_build_psoc6_merge_hex()`
The CMake macro `mbed_post_build_psoc6_merge_hex()` takes the name of a Cypress target and an optional Cortex-M0 hex image as arguments. The proper way to define and parse optional arguments of a function or macro is `cmake_parse_arguments()`, which allows the caller to indicate what they are passing rather than rely on an argument's relative position within `${ARGN}` which is not rigorous. Also, avoid duplicating the common part of the post build command when the optional argument is passed/not passed.pull/14953/head
parent
351680fb18
commit
91b8186615
|
@ -59,4 +59,7 @@ target_compile_definitions(mbed-cysbsyskit-01
|
|||
"CY8C624AFNI_S2D43F"
|
||||
)
|
||||
|
||||
mbed_post_build_psoc6_merge_hex("CYSBSYSKIT_01")
|
||||
mbed_post_build_psoc6_merge_hex(
|
||||
PSOC6_TARGET
|
||||
"CYSBSYSKIT_01"
|
||||
)
|
||||
|
|
|
@ -6,34 +6,35 @@ include(mbed_set_post_build)
|
|||
#
|
||||
# Merge Cortex-M4 HEX and a Cortex-M0 HEX.
|
||||
#
|
||||
macro(mbed_post_build_psoc6_merge_hex cypress_psoc6_target)
|
||||
if("${cypress_psoc6_target}" STREQUAL "${MBED_TARGET}")
|
||||
macro(mbed_post_build_psoc6_merge_hex)
|
||||
set(prefix "CYPRESS")
|
||||
set(options)
|
||||
set(oneValueArgs
|
||||
PSOC6_TARGET
|
||||
CORTEX_M0_HEX
|
||||
)
|
||||
set(multiValueArgs)
|
||||
cmake_parse_arguments(
|
||||
"${prefix}"
|
||||
"${options}"
|
||||
"${oneValueArgs}"
|
||||
"${multipleValueArgs}"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
if("${CYPRESS_PSOC6_TARGET}" STREQUAL "${MBED_TARGET}")
|
||||
function(mbed_post_build_function target)
|
||||
find_package(Python3)
|
||||
set(post_build_command
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
|
||||
merge
|
||||
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
|
||||
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
|
||||
)
|
||||
|
||||
# Copy ${ARGN} to a variable first as it cannot be used directly with
|
||||
# the list() command
|
||||
set (extra_macro_args ${ARGN})
|
||||
|
||||
# Get the number of arguments past the last expected argument
|
||||
list(LENGTH extra_macro_args num_extra_args)
|
||||
|
||||
if(${num_extra_args} GREATER 0)
|
||||
# Get extra argument as `cortex_m0_hex`
|
||||
list(GET extra_macro_args 0 cortex_m0_hex)
|
||||
set(post_build_command
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
|
||||
merge
|
||||
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
|
||||
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
|
||||
--m0hex ${cortex_m0_hex}
|
||||
)
|
||||
else()
|
||||
set(post_build_command
|
||||
${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py
|
||||
merge
|
||||
--elf $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.elf
|
||||
--m4hex $<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_BASE_NAME:${target}>.hex
|
||||
if(NOT "${CYPRESS_CORTEX_M0_HEX}" STREQUAL "")
|
||||
list(APPEND post_build_command
|
||||
--m0hex ${CYPRESS_CORTEX_M0_HEX}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in New Issue