Skip to content

Commit 2a6a840

Browse files
committed
CMake: Refactor Nuvoton targets
Refactor all Nuvoton 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 3174a4c commit 2a6a840

File tree

18 files changed

+186
-148
lines changed

18 files changed

+186
-148
lines changed

targets/TARGET_NUVOTON/CMakeLists.txt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
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("M2351" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_M2351)
6-
elseif("M251" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_M251)
8-
elseif("M261" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_M261)
10-
elseif("M451" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_M451)
12-
elseif("M480" IN_LIST MBED_TARGET_LABELS)
13-
add_subdirectory(TARGET_M480)
14-
elseif("NANO100" IN_LIST MBED_TARGET_LABELS)
15-
add_subdirectory(TARGET_NANO100)
16-
elseif("NUC472" IN_LIST MBED_TARGET_LABELS)
17-
add_subdirectory(TARGET_NUC472)
18-
endif()
4+
add_library(mbed-nuvoton INTERFACE)
195

20-
target_include_directories(mbed-core
6+
add_subdirectory(TARGET_M2351 EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_M251 EXCLUDE_FROM_ALL)
8+
add_subdirectory(TARGET_M261 EXCLUDE_FROM_ALL)
9+
add_subdirectory(TARGET_M451 EXCLUDE_FROM_ALL)
10+
add_subdirectory(TARGET_M480 EXCLUDE_FROM_ALL)
11+
add_subdirectory(TARGET_NANO100 EXCLUDE_FROM_ALL)
12+
add_subdirectory(TARGET_NUC472 EXCLUDE_FROM_ALL)
13+
14+
target_include_directories(mbed-nuvoton
2115
INTERFACE
2216
.
2317
)
2418

25-
target_sources(mbed-core
19+
target_sources(mbed-nuvoton
2620
INTERFACE
2721
nu_miscutil.c
2822
nu_modutil.c

targets/TARGET_NUVOTON/TARGET_M2351/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
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("M23_NS" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_M23_NS)
6-
elseif("M23_S" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_M23_S)
8-
elseif("NU_PFM_M2351" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_NU_PFM_M2351)
10-
endif()
4+
add_subdirectory(TARGET_M23_NS EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_M23_S EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_NU_PFM_M2351 EXCLUDE_FROM_ALL)
117

12-
target_sources(mbed-core
8+
add_library(mbed-m2351 INTERFACE)
9+
10+
target_sources(mbed-m2351
1311
INTERFACE
1412
dma_api.c
1513
flash_api.c
@@ -80,11 +78,13 @@ target_sources(mbed-core
8078
device/startup_M2351.c
8179
)
8280

83-
target_include_directories(mbed-core
81+
target_include_directories(mbed-m2351
8482
INTERFACE
8583
.
8684
device
8785
device/Reg
8886
device/StdDriver/inc
8987
crypto
9088
)
89+
90+
target_link_libraries(mbed-m2351 INTERFACE mbed-nuvoton)
Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
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("NU_PFM_M2351_NPSA_NS" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NU_PFM_M2351_NPSA_NS)
6-
elseif("NU_PFM_M2351_NS" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_NU_PFM_M2351_NS)
8-
elseif("TFM" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_TFM)
10-
endif()
4+
add_library(mbed-nu-pfm-m2351-npsa-ns INTERFACE)
5+
target_link_libraries(mbed-nu-pfm-m2351-npsa-ns
6+
INTERFACE
7+
TARGET_NU_PFM_M2351_NPSA_NS/TARGET_NU_PREBUILD_SECURE/cmse_lib.o
8+
)
9+
10+
add_library(mbed-nu-pfm-m2351-ns INTERFACE)
11+
target_link_libraries(mbed-nu-pfm-m2351-ns
12+
INTERFACE
13+
TARGET_NU_PFM_M2351_NS/TARGET_NU_PREBUILD_SECURE/cmse_lib.o
14+
)
15+
16+
add_library(mbed-nu-m23-ns-tfm INTERFACE)
17+
target_include_directories(mbed-nu-m23-ns-tfm
18+
INTERFACE
19+
device/TARGET_TFM
20+
)
21+
target_sources(mbed-nu-m23-ns-tfm
22+
INTERFACE
23+
TARGET_TFM/tfm_ns_lock_rtx.c
24+
device/TARGET_TFM/cmsis_nvic_virtual.c
25+
)
26+
1127

12-
add_subdirectory(device)
28+
add_library(mbed-m23-ns INTERFACE)
1329

14-
target_sources(mbed-core
30+
target_sources(mbed-m23-ns
1531
INTERFACE
1632
wait_ns.c
1733
)
34+
35+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
36+
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/M2351.ld)
37+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
38+
set(LINKER_FILE device/TOOLCHAIN_ARMC6/M2351.sct)
39+
endif()
40+
41+
mbed_set_linker_script(mbed-m23-ns ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
42+
43+
target_link_libraries(mbed-m23-ns INTERFACE mbed-2351)

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/TARGET_TFM/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/device/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
This file was deleted.

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_NS/device/TARGET_TFM/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
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("TFM" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_TFM)
6-
endif()
4+
add_library(mbed-nu-m23-s-tfm INTERFACE)
5+
target_include_directories(mbed-nu-m23-s-tfm
6+
INTERFACE
7+
TARGET_TFM
8+
)
9+
target_sources(mbed-nu-m23-s-tfm
10+
INTERFACE
11+
TARGET_TFM/spm_hal.c
12+
TARGET_TFM/target_cfg.cpp
13+
)
14+
15+
add_library(mbed-m23-s INTERFACE)
716

817
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
918
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/M2351.ld)
1019
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1120
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/M2351.sct)
1221
endif()
1322

14-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
23+
mbed_set_linker_script(mbed-m23-s ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
24+
25+
target_link_libraries(mbed-m23-s INTERFACE mbed-2351)

targets/TARGET_NUVOTON/TARGET_M2351/TARGET_M23_S/TARGET_TFM/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
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-
target_include_directories(mbed-core
4+
add_library(mbed-nu-pfm-m2351 INTERFACE)
5+
6+
target_include_directories(mbed-nu-pfm-m2351
57
INTERFACE
68
.
79
)

targets/TARGET_NUVOTON/TARGET_M251/CMakeLists.txt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
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("NUMAKER_IOT_M252" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUMAKER_IOT_M252)
6-
endif()
7-
84
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
95
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/M251.ld)
106
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
117
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/M251.sct)
128
endif()
139

14-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
10+
add_library(mbed-m251 INTERFACE)
1511

16-
target_sources(mbed-core
12+
target_sources(mbed-m251
1713
INTERFACE
1814
analogin_api.c
1915
analogout_api.c
@@ -66,10 +62,23 @@ target_sources(mbed-core
6662
us_ticker.c
6763
)
6864

69-
target_include_directories(mbed-core
65+
target_include_directories(mbed-m251
7066
INTERFACE
7167
.
7268
device
7369
device/Reg
7470
device/StdDriver/inc
7571
)
72+
73+
target_link_libraries(mbed-m251 INTERFACE mbed-nuvoton)
74+
75+
mbed_set_linker_script(mbed-m251 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
76+
77+
add_library(mbed-numaker-iot-m252 INTERFACE)
78+
79+
target_include_directories(mbed-numaker-iot-m252
80+
INTERFACE
81+
TARGET_NUMAKER_IOT_M252
82+
)
83+
84+
target_link_libraries(mbed-numaker-iot-m252 INTERFACE mbed-m251)

0 commit comments

Comments
 (0)