diff --git a/.github/workflows/test_building_multiple_executables.yml b/.github/workflows/test_building_multiple_executables.yml new file mode 100644 index 00000000000..7e3f64595d9 --- /dev/null +++ b/.github/workflows/test_building_multiple_executables.yml @@ -0,0 +1,28 @@ +name: test building multiple executables with CMake + +on: [pull_request] + +jobs: + multiple-executables-example: + runs-on: ubuntu-latest + container: mbedos/mbed-os-env:latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Build the multiple_executables example + run: | + mbedtools compile \ + -t GCC_ARM \ + -m ARM_MUSCA_S1 \ + --program-path tools/cmake/tests/multiple_executables/ \ + --mbed-os-path . + + - name: Verify the post-build command has run successfully on each image + run: | + APP1=tools/cmake/tests/multiple_executables/cmake_build/ARM_MUSCA_S1/develop/GCC_ARM/app1/app1.bin + APP2=tools/cmake/tests/multiple_executables/cmake_build/ARM_MUSCA_S1/develop/GCC_ARM/app2/app2.bin + BOOTLOADER=targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/bl2.bin + BOOTLOADER_SIZE=`du -b targets/TARGET_ARM_SSG/TARGET_MUSCA_S1/bl2.bin | cut -f1` + cmp -n $BOOTLOADER_SIZE $APP1 $BOOTLOADER + cmp -n $BOOTLOADER_SIZE $APP2 $BOOTLOADER diff --git a/CMakeLists.txt b/CMakeLists.txt index 186825ad08f..e91ccf6388b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,12 +144,16 @@ target_include_directories(mbed-core add_library(mbed-device_key INTERFACE) add_library(mbed-rtos INTERFACE) +# Include targets/ first, because any post-build hook needs to be defined +# before other parts of Mbed OS can add greentea tests which require +# mbed_set_post_build(). +add_subdirectory(targets) + add_subdirectory(cmsis) add_subdirectory(drivers) add_subdirectory(hal) add_subdirectory(platform) add_subdirectory(rtos) -add_subdirectory(targets) add_subdirectory(storage) add_subdirectory(events) add_subdirectory(connectivity) @@ -171,122 +175,6 @@ if(${CMAKE_CROSSCOMPILING}) target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED}) endif() -# -# Converts output file of `target` to binary file and to Intel HEX file. -# -function(mbed_generate_bin_hex target) - get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) - 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 $ ${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 $ ${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) - 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 $ - 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 $ - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" - ) - endif() - endif() - add_custom_command( - TARGET - ${target} - POST_BUILD - ${CMAKE_POST_BUILD_COMMAND} - COMMENT - "executable:" - VERBATIM - ) - - if(TARGET mbed-post-build-bin-${MBED_TARGET}) - # Remove the .elf file to force regenerate the application binaries - # (including .bin and .hex). This ensures that the post-build script runs - # on a raw application instead of a previous build that already went - # through the post-build process once. - file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${target}.elf) - - # Pass the application's name to the Mbed target's post build operation - set_target_properties(mbed-post-build-bin-${MBED_TARGET} - PROPERTIES - application ${target} - ) - - # The artefacts must be created before they can be further manipulated - add_dependencies(mbed-post-build-bin-${MBED_TARGET} ${target}) - - # Add a post-build hook to the top-level CMake target in the form of a - # CMake custom target. The hook depends on Mbed target specific - # post-build CMake target which has a custom command attached to it. - add_custom_target(mbed-post-build ALL DEPENDS mbed-post-build-bin-${MBED_TARGET}) - endif() -endfunction() - -# -# Parse toolchain generated map file of `target` and display a readable table format. -# -function(mbed_generate_map_file target) - add_custom_command( - TARGET - ${target} - POST_BUILD - COMMAND ${Python3_EXECUTABLE} ${mbed-os_SOURCE_DIR}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map - WORKING_DIRECTORY - ${CMAKE_CURRENT_BINARY_DIR} - COMMENT - "Displaying memory map for ${target}" -) -endfunction() - -# -# Validate selected application profile. -# -function(mbed_validate_application_profile target) - get_target_property(app_link_libraries ${target} LINK_LIBRARIES) - string(FIND "${app_link_libraries}" "mbed-baremetal" string_found_position) - if(${string_found_position} GREATER_EQUAL 0) - if(NOT "bare-metal" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES) - message(FATAL_ERROR - "Use full profile as baremetal profile is not supported for this Mbed target") - endif() - elseif(NOT "full" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES) - message(FATAL_ERROR - "The full profile is not supported for this Mbed target") - endif() -endfunction() - -# -# Set post build operations -# -function(mbed_set_post_build target) - # The mapfile name includes the top-level target name and the - # executable suffix for all toolchains as CMake hardcodes the name of the - # diagnostic output file for some toolchains. - mbed_configure_memory_map(${target} "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map") - mbed_validate_application_profile(${target}) - mbed_generate_bin_hex(${target}) - - if(HAVE_MEMAP_DEPS) - mbed_generate_map_file(${target}) - endif() -endfunction() - # Ninja requires to be forced for response files if ("${CMAKE_GENERATOR}" MATCHES "Ninja") # known issue ARMClang and Ninja with response files for windows diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake index 6bce525f6fa..577ad916776 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake @@ -3,28 +3,30 @@ include(mbed_set_post_build) -set(MBED_POST_BUILD_TFM_DIR "${CMAKE_CURRENT_LIST_DIR}") - # # Sign TF-M secure and non-secure images and combine them with the bootloader # -function(mbed_post_build_tfm_sign_image - mbed_target +macro(mbed_post_build_tfm_sign_image + mbed_tfm_target tfm_target target_path secure_bin ) - find_package(Python3) - - set(mbed_target_name ${mbed_target}) - set(post_build_command - COMMAND ${Python3_EXECUTABLE} - ${MBED_POST_BUILD_TFM_DIR}/generate_mbed_image.py - --tfm-target ${tfm_target} - --target-path ${target_path} - --secure-bin ${secure_bin} - --non-secure-bin ${CMAKE_BINARY_DIR}/$.bin - ) - - mbed_set_post_build_operation() -endfunction() + if("${mbed_tfm_target}" STREQUAL "${MBED_TARGET}") + function(mbed_post_build_function target) + find_package(Python3) + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND + ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/generate_mbed_image.py + --tfm-target ${tfm_target} + --target-path ${target_path} + --secure-bin ${secure_bin} + --non-secure-bin $/$.bin + ) + endfunction() + endif() +endmacro() 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 2245ac28092..f05b307b71c 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,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" +) 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 7888736d056..5dbe9e24b49 100644 --- a/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake +++ b/targets/TARGET_Cypress/scripts/mbed_set_post_build_cypress.cmake @@ -3,72 +3,91 @@ include(mbed_set_post_build) -set(MBED_POST_BUILD_CYPRESS_DIR "${CMAKE_CURRENT_LIST_DIR}") - # # Merge Cortex-M4 HEX and a Cortex-M0 HEX. # -function(mbed_post_build_psoc6_merge_hex mbed_target_name) - find_package(Python3) +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} + ) - # Copy ${ARGN} to a variable first as it cannot be used directly with - # the list() command - set (extra_macro_args ${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 $/$.elf + --m4hex $/$.hex + ) - # Get the number of arguments past the last expected argument - list(LENGTH extra_macro_args num_extra_args) + if(NOT "${CYPRESS_CORTEX_M0_HEX}" STREQUAL "") + list(APPEND post_build_command + --m0hex ${CYPRESS_CORTEX_M0_HEX} + ) + endif() - 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_POST_BUILD_CYPRESS_DIR}/PSOC6.py - merge - --elf ${CMAKE_BINARY_DIR}/$.elf - --m4hex ${CMAKE_BINARY_DIR}/$.hex - --m0hex ${cortex_m0_hex} - ) - else() - set(post_build_command - COMMAND ${Python3_EXECUTABLE} ${MBED_POST_BUILD_CYPRESS_DIR}/PSOC6.py - merge - --elf ${CMAKE_BINARY_DIR}/$.elf - --m4hex ${CMAKE_BINARY_DIR}/$.hex - ) + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND + ${post_build_command} + ) + endfunction() endif() - - mbed_set_post_build_operation() -endfunction() +endmacro() # # Sign a Cortex-M4 HEX with Cortex-M0 HEX. # -function(mbed_post_build_psoc6_sign_image +macro(mbed_post_build_psoc6_sign_image m0hex_filename - mbed_target_name + cypress_psoc6_target policy_file_name boot_scheme cm0_img_id cm4_img_id cortex_m0_hex ) - find_package(Python3) + if("${cypress_psoc6_target}" STREQUAL "${MBED_TARGET}") + function(mbed_post_build_function target) + find_package(Python3) - set(post_build_command - COMMAND ${Python3_EXECUTABLE} ${MBED_POST_BUILD_CYPRESS_DIR}/PSOC6.py - sign - --build-dir ${CMAKE_BINARY_DIR} - --m0hex-filename ${m0hex_filename} - --target-name ${mbed_target_name} - --policy-file-name ${policy_file_name} - --boot-scheme ${boot_scheme} - --cm0-img-id ${cm0_img_id} - --cm4-img-id ${cm4_img_id} - --elf ${CMAKE_BINARY_DIR}/$.elf - --m4hex ${CMAKE_BINARY_DIR}/$.hex - --m0hex ${cortex_m0_hex} - ) + set(post_build_command + ${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PSOC6.py + sign + --build-dir ${CMAKE_BINARY_DIR} + --m0hex-filename ${m0hex_filename} + --target-name ${cypress_psoc6_target} + --policy-file-name ${policy_file_name} + --boot-scheme ${boot_scheme} + --cm0-img-id ${cm0_img_id} + --cm4-img-id ${cm4_img_id} + --elf $/$.elf + --m4hex $/$.hex + --m0hex ${cortex_m0_hex} + ) - mbed_set_post_build_operation() -endfunction() + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND + ${post_build_command} + ) + endfunction() + endif() +endmacro() diff --git a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake index 3169ad5c356..9f7a3cb9c9c 100644 --- a/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake +++ b/targets/TARGET_NUVOTON/scripts/mbed_set_post_build_nuvoton.cmake @@ -6,22 +6,27 @@ include(${MBED_PATH}/tools/cmake/mbed_set_post_build.cmake) # # Sign TF-M secure and non-secure images and combine them with the bootloader # -function(mbed_post_build_nuvoton_tfm_sign_image_tgt - mbed_target +macro(mbed_post_build_nuvoton_tfm_sign_image_tgt + nuvoton_target tfm_import_path signing_key ) - find_package(Python3) + if("${nuvoton_target}" STREQUAL "${MBED_TARGET}") + function(mbed_post_build_function target) + find_package(Python3) - set(mbed_target_name ${mbed_target}) - set(post_build_command - COMMAND ${Python3_EXECUTABLE} - ${MBED_PATH}/targets/TARGET_NUVOTON/scripts/NUVOTON.py - tfm_sign_image_tgt - --tfm-import-path ${tfm_import_path} - --signing_key ${signing_key} - --non-secure-bin ${CMAKE_BINARY_DIR}/$.bin - ) - - mbed_set_post_build_operation() -endfunction() + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND + ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/NUVOTON.py + tfm_sign_image_tgt + --tfm-import-path ${tfm_import_path} + --signing_key ${signing_key} + --non-secure-bin $/$.bin + ) + endfunction() + endif() +endmacro() 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 fdf5e38217d..12f0b47d615 100644 --- a/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake +++ b/targets/TARGET_NXP/scripts/mbed_set_post_build_nxp.cmake @@ -3,18 +3,21 @@ include(mbed_set_post_build) -set(MBED_POST_BUILD_NXP_DIR "${CMAKE_CURRENT_LIST_DIR}") - # # Patch an LPC target vector table in the binary file. # -function(mbed_post_build_lpc_patch_vtable mbed_target_name) - find_package(Python3) - - set(post_build_command - COMMAND ${Python3_EXECUTABLE} ${MBED_POST_BUILD_NXP_DIR}/LPC.py - ${CMAKE_BINARY_DIR}/$.bin - ) - - mbed_set_post_build_operation() -endfunction() +macro(mbed_post_build_lpc_patch_vtable nxp_lpc_target) + if("${nxp_lpc_target}" STREQUAL "${MBED_TARGET}") + function(mbed_post_build_function target) + find_package(Python3) + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND + ${Python3_EXECUTABLE} ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/LPC.py + $/$.bin + ) + endfunction() + endif() +endmacro() diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index 500e477a4c4..60f9f855ff6 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -11,6 +11,7 @@ if(CCACHE) endif() include(${MBED_CONFIG_PATH}/mbed_config.cmake) +include(mbed_set_post_build) # Load toolchain file if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) diff --git a/tools/cmake/mbed_set_post_build.cmake b/tools/cmake/mbed_set_post_build.cmake index 22363e7f524..ac9b2795143 100644 --- a/tools/cmake/mbed_set_post_build.cmake +++ b/tools/cmake/mbed_set_post_build.cmake @@ -2,18 +2,100 @@ # SPDX-License-Identifier: Apache-2.0 # -# Sets the post build operation for Mbed targets. +# Converts output file of `target` to binary file and to Intel HEX file. # -macro(mbed_set_post_build_operation) - - add_custom_target(mbed-post-build-bin-${mbed_target_name}) - +function(mbed_generate_bin_hex target) + get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) + 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 $ ${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 $ ${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) + 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 $ + 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 $ + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" + ) + endif() + endif() add_custom_command( TARGET - mbed-post-build-bin-${mbed_target_name} + ${target} POST_BUILD COMMAND - ${post_build_command} + ${CMAKE_POST_BUILD_COMMAND} + COMMENT + "executable:" VERBATIM ) -endmacro() +endfunction() + +# +# Parse toolchain generated map file of `target` and display a readable table format. +# +function(mbed_generate_map_file target) + add_custom_command( + TARGET + ${target} + POST_BUILD + COMMAND ${Python3_EXECUTABLE} ${mbed-os_SOURCE_DIR}/tools/memap.py -t ${MBED_TOOLCHAIN} ${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map + WORKING_DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR} + COMMENT + "Displaying memory map for ${target}" +) +endfunction() + +# +# Validate selected application profile. +# +function(mbed_validate_application_profile target) + get_target_property(app_link_libraries ${target} LINK_LIBRARIES) + string(FIND "${app_link_libraries}" "mbed-baremetal" string_found_position) + if(${string_found_position} GREATER_EQUAL 0) + if(NOT "bare-metal" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES) + message(FATAL_ERROR + "Use full profile as baremetal profile is not supported for this Mbed target") + endif() + elseif(NOT "full" IN_LIST MBED_TARGET_SUPPORTED_APPLICATION_PROFILES) + message(FATAL_ERROR + "The full profile is not supported for this Mbed target") + endif() +endfunction() + +# +# Set post build operations +# +function(mbed_set_post_build target) + # The mapfile name includes the top-level target name and the + # executable suffix for all toolchains as CMake hardcodes the name of the + # diagnostic output file for some toolchains. + mbed_configure_memory_map(${target} "${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map") + mbed_validate_application_profile(${target}) + mbed_generate_bin_hex(${target}) + + if(COMMAND mbed_post_build_function) + mbed_post_build_function(${target}) + endif() + + if(HAVE_MEMAP_DEPS) + mbed_generate_map_file(${target}) + endif() +endfunction() diff --git a/tools/cmake/tests/multiple_executables/CMakeLists.txt b/tools/cmake/tests/multiple_executables/CMakeLists.txt new file mode 100644 index 00000000000..0070dfcf225 --- /dev/null +++ b/tools/cmake/tests/multiple_executables/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.19.0) + +set(MBED_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../..") +set(MBED_CONFIG_PATH "${CMAKE_CURRENT_BINARY_DIR}") + +include("${MBED_PATH}/tools/cmake/app.cmake") + +project(multiple_executables) + +add_subdirectory("${MBED_PATH}" "mbed-os-build") + +add_subdirectory(app1) +add_subdirectory(app2) diff --git a/tools/cmake/tests/multiple_executables/app1/CMakeLists.txt b/tools/cmake/tests/multiple_executables/app1/CMakeLists.txt new file mode 100644 index 00000000000..70e97c3c6d0 --- /dev/null +++ b/tools/cmake/tests/multiple_executables/app1/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_executable(app1 main.cpp) + +target_link_libraries(app1 mbed-os) + +mbed_set_post_build(app1) diff --git a/tools/cmake/tests/multiple_executables/app1/main.cpp b/tools/cmake/tests/multiple_executables/app1/main.cpp new file mode 100644 index 00000000000..b6b6d65383b --- /dev/null +++ b/tools/cmake/tests/multiple_executables/app1/main.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2021 Arm Limited + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mbed.h" + +int main() +{ + printf("Application 1\n"); + return 0; +} diff --git a/tools/cmake/tests/multiple_executables/app2/CMakeLists.txt b/tools/cmake/tests/multiple_executables/app2/CMakeLists.txt new file mode 100644 index 00000000000..51d899cc1d4 --- /dev/null +++ b/tools/cmake/tests/multiple_executables/app2/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_executable(app2 main.cpp) + +target_link_libraries(app2 mbed-os) + +mbed_set_post_build(app2) diff --git a/tools/cmake/tests/multiple_executables/app2/main.cpp b/tools/cmake/tests/multiple_executables/app2/main.cpp new file mode 100644 index 00000000000..cc435032563 --- /dev/null +++ b/tools/cmake/tests/multiple_executables/app2/main.cpp @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2021 Arm Limited + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "mbed.h" + +int main() +{ + printf("Application 2\n"); + return 0; +}