Fix post build mechanism with unique CMake custom targets

The CMake custom target must be unique to avoid more than one
Mbed target adding the same. Only the CMake custom command added for the
Mbed target being built is run as the custom CMake target now includes
the Mbed target name.
pull/14289/head
Hugues Kamba 2021-02-15 17:39:27 +00:00
parent ea6955bd1c
commit 68b6e6ff96
10 changed files with 20 additions and 16 deletions

View File

@ -195,11 +195,11 @@ function(mbed_generate_bin_hex target)
VERBATIM VERBATIM
) )
if(TARGET mbed-post-build-bin) if(TARGET mbed-post-build-bin-${MBED_TARGET})
add_custom_target(mbed-post-build add_custom_target(mbed-post-build
ALL ALL
DEPENDS DEPENDS
mbed-post-build-bin mbed-post-build-bin-${MBED_TARGET}
) )
endif() endif()
endfunction() endfunction()

View File

@ -59,4 +59,4 @@ target_compile_definitions(mbed-cysbsyskit-01
"CY8C624AFNI_S2D43F" "CY8C624AFNI_S2D43F"
) )
mbed_post_build_psoc6_merge_hex() mbed_post_build_psoc6_merge_hex("CYSBSYSKIT_01")

View File

@ -6,14 +6,18 @@ include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake)
# #
# Merge Cortex-M4 HEX and a Cortex-M0 HEX. # Merge Cortex-M4 HEX and a Cortex-M0 HEX.
# #
function(mbed_post_build_psoc6_merge_hex) function(mbed_post_build_psoc6_merge_hex mbed_target_name)
find_package(Python3) find_package(Python3)
# Copy ${ARGN} to a variable first as it cannot be used directly with
# the list() command
set (extra_macro_args ${ARGN}) set (extra_macro_args ${ARGN})
list(LENGTH cortex_m0_hex num_extra_args) # Get the number of arguments past the last expected argument
list(LENGTH extra_macro_args num_extra_args)
if(${num_extra_args} GREATER 0) if(${num_extra_args} GREATER 0)
# Get extra argument as `cortex_m0_hex`
list(GET extra_macro_args 0 cortex_m0_hex) list(GET extra_macro_args 0 cortex_m0_hex)
set(post_build_command set(post_build_command
COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py

View File

@ -16,5 +16,3 @@ target_sources(mbed-lpc11xx
) )
target_link_libraries(mbed-lpc11xx INTERFACE mbed-lpc11xx-11cxx) target_link_libraries(mbed-lpc11xx INTERFACE mbed-lpc11xx-11cxx)
mbed_post_build_lpc_patch_vtable()

View File

@ -12,4 +12,4 @@ target_include_directories(mbed-arch-pro
target_link_libraries(mbed-arch-pro INTERFACE mbed-lpc176x) target_link_libraries(mbed-arch-pro INTERFACE mbed-lpc176x)
mbed_post_build_lpc_patch_vtable() mbed_post_build_lpc_patch_vtable("ARCH_PRO")

View File

@ -16,4 +16,4 @@ add_library(mbed-lpc1768 INTERFACE)
target_link_libraries(mbed-lpc1768 INTERFACE mbed-mbed-lpc1768) target_link_libraries(mbed-lpc1768 INTERFACE mbed-mbed-lpc1768)
mbed_post_build_lpc_patch_vtable() mbed_post_build_lpc_patch_vtable("LPC1768")

View File

@ -33,4 +33,4 @@ target_sources(mbed-lpc54114-m4
mbed_set_linker_script(mbed-lpc54114-m4 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) mbed_set_linker_script(mbed-lpc54114-m4 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
mbed_post_build_lpc_patch_vtable() mbed_post_build_lpc_patch_vtable("LPC54114")

View File

@ -94,4 +94,5 @@ target_link_libraries(mbed-lpc546xx
mbed-lpc546xx-xpresso mbed-lpc546xx-xpresso
) )
mbed_post_build_lpc_patch_vtable() mbed_post_build_lpc_patch_vtable("LPC546XX")
mbed_post_build_lpc_patch_vtable("FF_LPC546XX")

View File

@ -6,7 +6,7 @@ include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake)
# #
# Patch an LPC target vector table in the binary file. # Patch an LPC target vector table in the binary file.
# #
function(mbed_post_build_lpc_patch_vtable) function(mbed_post_build_lpc_patch_vtable mbed_target_name)
find_package(Python3) find_package(Python3)
set(post_build_command set(post_build_command

View File

@ -5,16 +5,17 @@
# Sets the post build operation for Mbed targets. # Sets the post build operation for Mbed targets.
# #
macro(mbed_set_post_build_operation) macro(mbed_set_post_build_operation)
add_custom_target(mbed-post-build-bin
DEPENDS ${CMAKE_BINARY_DIR}/${APP_TARGET}.bin add_custom_target(mbed-post-build-bin-${mbed_target_name}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${APP_TARGET}.bin
) )
# Ensures the application artefacts are created before manipulating them. # Ensures the application artefacts are created before manipulating them.
add_dependencies(mbed-post-build-bin ${APP_TARGET}) add_dependencies(mbed-post-build-bin-${mbed_target_name} ${APP_TARGET})
add_custom_command( add_custom_command(
OUTPUT OUTPUT
${CMAKE_BINARY_DIR}/${APP_TARGET}.bin ${CMAKE_CURRENT_BINARY_DIR}/${APP_TARGET}.bin
POST_BUILD POST_BUILD
COMMAND COMMAND
${post_build_command} ${post_build_command}