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.
pull/14269/head
Harrison Mutai 2021-02-11 11:51:20 +00:00
parent 8284807a00
commit 176e451c20
3 changed files with 22 additions and 15 deletions

View File

@ -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 # SPDX-License-Identifier: Apache-2.0
if("TMPM46B" IN_LIST MBED_TARGET_LABELS) add_subdirectory(TARGET_TMPM46B EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_TMPM46B) add_subdirectory(TARGET_TMPM4G9 EXCLUDE_FROM_ALL)
elseif("TMPM4G9" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_TMPM4G9)
endif()
target_include_directories(mbed-core add_library(mbed-toshiba INTERFACE)
target_include_directories(mbed-toshiba
INTERFACE INTERFACE
. .
) )

View File

@ -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 # SPDX-License-Identifier: Apache-2.0
if(${MBED_TOOLCHAIN} STREQUAL "ARM") 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) set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM46b.S)
endif() 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 INTERFACE
. .
device device
Periph_Driver/inc Periph_Driver/inc
) )
target_sources(mbed-core target_sources(mbed-tmpm46b
INTERFACE INTERFACE
analogin_api.c analogin_api.c
flash_api.c flash_api.c
@ -52,3 +52,7 @@ target_sources(mbed-core
${STARTUP_FILE} ${STARTUP_FILE}
) )
mbed_set_linker_script(mbed-tmpm46b ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
target_link_libraries(mbed-tmpm46b INTERFACE mbed-toshiba)

View File

@ -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 # SPDX-License-Identifier: Apache-2.0
if(${MBED_TOOLCHAIN} STREQUAL "ARM") 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) set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM4G9.S)
endif() 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 INTERFACE
. .
device device
Periph_Driver/inc Periph_Driver/inc
) )
target_sources(mbed-core target_sources(mbed-tmpm4g9
INTERFACE INTERFACE
analogin_api.c analogin_api.c
analogout_api.c analogout_api.c
@ -54,3 +54,7 @@ target_sources(mbed-core
${STARTUP_FILE} ${STARTUP_FILE}
) )
mbed_set_linker_script(mbed-tmpm4g9 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
target_link_libraries(mbed-tmpm4g9 INTERFACE mbed-toshiba)