From 176e451c20657761ed682e148aab3155bae42bd0 Mon Sep 17 00:00:00 2001 From: Harrison Mutai Date: Thu, 11 Feb 2021 11:51:20 +0000 Subject: [PATCH] CMake: Refactor Toshiba targets Refactor all Toshiba targets to be CMake buildsystem targets. This removes the need for checking MBED_TARGET_LABELS repeatedly and allows us to be more flexible in the way we include MBED_TARGET source in the build. A side effect of this is it will allow us to support custom targets without breaking the build for 'standard' targets, as we use CMake's standard mechanism for adding build rules to the build system, rather than implementing our own layer of logic to exclude files not needed for the target being built. Using this approach, if an MBED_TARGET is not linked to using `target_link_libraries` its source files will not be added to the build. This means custom target source can be added to the user's application CMakeLists.txt without polluting the build system when trying to compile for a standard MBED_TARGET. --- targets/TARGET_TOSHIBA/CMakeLists.txt | 13 ++++++------- .../TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt | 12 ++++++++---- .../TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt | 12 ++++++++---- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/targets/TARGET_TOSHIBA/CMakeLists.txt b/targets/TARGET_TOSHIBA/CMakeLists.txt index ad409baa4c7..482c9752025 100644 --- a/targets/TARGET_TOSHIBA/CMakeLists.txt +++ b/targets/TARGET_TOSHIBA/CMakeLists.txt @@ -1,13 +1,12 @@ -# Copyright (c) 2020 ARM Limited. All rights reserved. +# Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if("TMPM46B" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_TMPM46B) -elseif("TMPM4G9" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_TMPM4G9) -endif() +add_subdirectory(TARGET_TMPM46B EXCLUDE_FROM_ALL) +add_subdirectory(TARGET_TMPM4G9 EXCLUDE_FROM_ALL) -target_include_directories(mbed-core +add_library(mbed-toshiba INTERFACE) + +target_include_directories(mbed-toshiba INTERFACE . ) diff --git a/targets/TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt b/targets/TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt index d69a6a784ce..09b904c1bba 100644 --- a/targets/TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt +++ b/targets/TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020 ARM Limited. All rights reserved. +# Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 if(${MBED_TOOLCHAIN} STREQUAL "ARM") @@ -9,16 +9,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM46b.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-tmpm46b INTERFACE) -target_include_directories(mbed-core +target_include_directories(mbed-tmpm46b INTERFACE . device Periph_Driver/inc ) -target_sources(mbed-core +target_sources(mbed-tmpm46b INTERFACE analogin_api.c flash_api.c @@ -52,3 +52,7 @@ target_sources(mbed-core ${STARTUP_FILE} ) + +mbed_set_linker_script(mbed-tmpm46b ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-tmpm46b INTERFACE mbed-toshiba) diff --git a/targets/TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt b/targets/TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt index 2222dbcdf77..e4437aa63e2 100644 --- a/targets/TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt +++ b/targets/TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020 ARM Limited. All rights reserved. +# Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 if(${MBED_TOOLCHAIN} STREQUAL "ARM") @@ -9,16 +9,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM4G9.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-tmpm4g9 INTERFACE) -target_include_directories(mbed-core +target_include_directories(mbed-tmpm4g9 INTERFACE . device Periph_Driver/inc ) -target_sources(mbed-core +target_sources(mbed-tmpm4g9 INTERFACE analogin_api.c analogout_api.c @@ -54,3 +54,7 @@ target_sources(mbed-core ${STARTUP_FILE} ) + +mbed_set_linker_script(mbed-tmpm4g9 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-tmpm4g9 INTERFACE mbed-toshiba)