From 68b6e6ff9647cbdf79b7b96aadc15bbb47ad1de0 Mon Sep 17 00:00:00 2001 From: Hugues Kamba Date: Mon, 15 Feb 2021 17:39:27 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 4 ++-- .../TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt | 2 +- .../scripts/mbed_set_post_build_cypress.cmake | 8 ++++++-- .../TARGET_LPC11XX_11CXX/TARGET_LPC11XX/CMakeLists.txt | 2 -- .../TARGET_LPC176X/TARGET_ARCH_PRO/CMakeLists.txt | 2 +- .../TARGET_LPC176X/TARGET_MBED_LPC1768/CMakeLists.txt | 2 +- .../device/TARGET_LPC54114_M4/CMakeLists.txt | 2 +- .../TARGET_MCU_LPC546XX/CMakeLists.txt | 3 ++- targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake | 2 +- tools/cmake/mbed_set_post_build.cmake | 9 +++++---- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1967c3f65..ddd839ae69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,11 +195,11 @@ function(mbed_generate_bin_hex target) VERBATIM ) - if(TARGET mbed-post-build-bin) + if(TARGET mbed-post-build-bin-${MBED_TARGET}) add_custom_target(mbed-post-build ALL DEPENDS - mbed-post-build-bin + mbed-post-build-bin-${MBED_TARGET} ) endif() endfunction() diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt index 38e84e9ddb..14205ad81b 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt +++ b/targets/TARGET_Cypress/TARGET_PSOC6/TARGET_CYSBSYSKIT_01/CMakeLists.txt @@ -59,4 +59,4 @@ target_compile_definitions(mbed-cysbsyskit-01 "CY8C624AFNI_S2D43F" ) -mbed_post_build_psoc6_merge_hex() +mbed_post_build_psoc6_merge_hex("CYSBSYSKIT_01") diff --git a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake index 804a7ea5e1..759edc774f 100644 --- a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake +++ b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake @@ -6,14 +6,18 @@ include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake) # # 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) + # Copy ${ARGN} to a variable first as it cannot be used directly with + # the list() command 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) + # Get extra argument as `cortex_m0_hex` list(GET extra_macro_args 0 cortex_m0_hex) set(post_build_command COMMAND ${Python3_EXECUTABLE} ${MBED_PATH}/targets/TARGET_Cypress/scripts/PSOC6.py diff --git a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/CMakeLists.txt b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/CMakeLists.txt index bdfa738b8a..56b2ca8285 100644 --- a/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/CMakeLists.txt +++ b/targets/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/CMakeLists.txt @@ -16,5 +16,3 @@ target_sources(mbed-lpc11xx ) target_link_libraries(mbed-lpc11xx INTERFACE mbed-lpc11xx-11cxx) - -mbed_post_build_lpc_patch_vtable() diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_ARCH_PRO/CMakeLists.txt b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_ARCH_PRO/CMakeLists.txt index 4ce9d41663..2e0cf92a73 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_ARCH_PRO/CMakeLists.txt +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_ARCH_PRO/CMakeLists.txt @@ -12,4 +12,4 @@ target_include_directories(mbed-arch-pro target_link_libraries(mbed-arch-pro INTERFACE mbed-lpc176x) -mbed_post_build_lpc_patch_vtable() +mbed_post_build_lpc_patch_vtable("ARCH_PRO") diff --git a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/CMakeLists.txt b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/CMakeLists.txt index dfe564388b..6a08010927 100644 --- a/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/CMakeLists.txt +++ b/targets/TARGET_NXP/TARGET_LPC176X/TARGET_MBED_LPC1768/CMakeLists.txt @@ -16,4 +16,4 @@ add_library(mbed-lpc1768 INTERFACE) target_link_libraries(mbed-lpc1768 INTERFACE mbed-mbed-lpc1768) -mbed_post_build_lpc_patch_vtable() +mbed_post_build_lpc_patch_vtable("LPC1768") diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/device/TARGET_LPC54114_M4/CMakeLists.txt b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/device/TARGET_LPC54114_M4/CMakeLists.txt index 487d3a3fb2..a99e516b74 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/device/TARGET_LPC54114_M4/CMakeLists.txt +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC54114/device/TARGET_LPC54114_M4/CMakeLists.txt @@ -33,4 +33,4 @@ target_sources(mbed-lpc54114-m4 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") diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/CMakeLists.txt b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/CMakeLists.txt index e4f9a1e3da..bb472b03b2 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/CMakeLists.txt +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MCU_LPC546XX/CMakeLists.txt @@ -94,4 +94,5 @@ target_link_libraries(mbed-lpc546xx mbed-lpc546xx-xpresso ) -mbed_post_build_lpc_patch_vtable() +mbed_post_build_lpc_patch_vtable("LPC546XX") +mbed_post_build_lpc_patch_vtable("FF_LPC546XX") diff --git a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake index c1f9618b33..bfdc791e74 100644 --- a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake +++ b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake @@ -6,7 +6,7 @@ include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake) # # 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) set(post_build_command diff --git a/tools/cmake/mbed_set_post_build.cmake b/tools/cmake/mbed_set_post_build.cmake index ce914482b8..c5480ab81c 100644 --- a/tools/cmake/mbed_set_post_build.cmake +++ b/tools/cmake/mbed_set_post_build.cmake @@ -5,16 +5,17 @@ # Sets the post build operation for Mbed targets. # 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. - add_dependencies(mbed-post-build-bin ${APP_TARGET}) + add_dependencies(mbed-post-build-bin-${mbed_target_name} ${APP_TARGET}) add_custom_command( OUTPUT - ${CMAKE_BINARY_DIR}/${APP_TARGET}.bin + ${CMAKE_CURRENT_BINARY_DIR}/${APP_TARGET}.bin POST_BUILD COMMAND ${post_build_command}