Skip to content

Commit 176e451

Browse files
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.
1 parent 8284807 commit 176e451

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

targets/TARGET_TOSHIBA/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# Copyright (c) 2020 ARM Limited. All rights reserved.
1+
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("TMPM46B" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_TMPM46B)
6-
elseif("TMPM4G9" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_TMPM4G9)
8-
endif()
4+
add_subdirectory(TARGET_TMPM46B EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_TMPM4G9 EXCLUDE_FROM_ALL)
96

10-
target_include_directories(mbed-core
7+
add_library(mbed-toshiba INTERFACE)
8+
9+
target_include_directories(mbed-toshiba
1110
INTERFACE
1211
.
1312
)

targets/TARGET_TOSHIBA/TARGET_TMPM46B/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020 ARM Limited. All rights reserved.
1+
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
@@ -9,16 +9,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
99
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM46b.S)
1010
endif()
1111

12-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_library(mbed-tmpm46b INTERFACE)
1313

14-
target_include_directories(mbed-core
14+
target_include_directories(mbed-tmpm46b
1515
INTERFACE
1616
.
1717
device
1818
Periph_Driver/inc
1919
)
2020

21-
target_sources(mbed-core
21+
target_sources(mbed-tmpm46b
2222
INTERFACE
2323
analogin_api.c
2424
flash_api.c
@@ -52,3 +52,7 @@ target_sources(mbed-core
5252

5353
${STARTUP_FILE}
5454
)
55+
56+
mbed_set_linker_script(mbed-tmpm46b ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
57+
58+
target_link_libraries(mbed-tmpm46b INTERFACE mbed-toshiba)

targets/TARGET_TOSHIBA/TARGET_TMPM4G9/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020 ARM Limited. All rights reserved.
1+
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

44
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
@@ -9,16 +9,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
99
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_TMPM4G9.S)
1010
endif()
1111

12-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_library(mbed-tmpm4g9 INTERFACE)
1313

14-
target_include_directories(mbed-core
14+
target_include_directories(mbed-tmpm4g9
1515
INTERFACE
1616
.
1717
device
1818
Periph_Driver/inc
1919
)
2020

21-
target_sources(mbed-core
21+
target_sources(mbed-tmpm4g9
2222
INTERFACE
2323
analogin_api.c
2424
analogout_api.c
@@ -54,3 +54,7 @@ target_sources(mbed-core
5454

5555
${STARTUP_FILE}
5656
)
57+
58+
mbed_set_linker_script(mbed-tmpm4g9 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
59+
60+
target_link_libraries(mbed-tmpm4g9 INTERFACE mbed-toshiba)

0 commit comments

Comments
 (0)