Skip to content

Commit 00cde38

Browse files
CMake: Refactor all Nordic 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 aa561ee commit 00cde38

File tree

10 files changed

+105
-85
lines changed

10 files changed

+105
-85
lines changed

targets/TARGET_NORDIC/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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("NRF5x" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NRF5x)
6-
endif()
4+
add_subdirectory(TARGET_NRF5x EXCLUDE_FROM_ALL)
75

8-
target_include_directories(mbed-core
6+
add_library(mbed-nordic INTERFACE)
7+
8+
target_include_directories(mbed-nordic
99
INTERFACE
1010
.
1111
)
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
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("NRF52" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NRF52)
6-
endif()
4+
add_subdirectory(TARGET_NRF52 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_SDK_15_0 EXCLUDE_FROM_ALL)
76

8-
if("SDK_15_0" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_SDK_15_0)
10-
endif()
7+
add_library(mbed-nrf5x INTERFACE)
118

12-
target_include_directories(mbed-core
9+
target_include_directories(mbed-nrf5x
1310
INTERFACE
1411
.
1512
)
1613

17-
target_sources(mbed-core
14+
target_sources(mbed-nrf5x
1815
INTERFACE
1916
lp_ticker.c
2017
pinmap.c
2118
port_api.c
2219
qspi_api.c
2320
rtc_api.c
2421
)
22+
23+
target_link_libraries(mbed-nrf5x INTERFACE mbed-nordic)

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
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("MCU_NRF52832" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_MCU_NRF52832)
6-
elseif("MCU_NRF52840" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_MCU_NRF52840)
8-
endif()
4+
add_subdirectory(TARGET_MCU_NRF52832 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_MCU_NRF52840 EXCLUDE_FROM_ALL)
96

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

15-
target_sources(mbed-core
14+
target_sources(mbed-nrf52
1615
INTERFACE
1716
PeripheralPinsDefault.c
1817
analogin_api.c
@@ -33,3 +32,5 @@ target_sources(mbed-core
3332
us_ticker.c
3433
watchdog_api.c
3534
)
35+
36+
target_link_libraries(mbed-nrf52 INTERFACE mbed-nrf5x)
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
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("NRF52_DK" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_NRF52_DK
8-
)
9-
elseif("SDT52832B" IN_LIST MBED_TARGET_LABELS)
10-
target_include_directories(mbed-core
11-
INTERFACE
12-
TARGET_SDT52832B
13-
)
14-
endif()
4+
add_library(mbed-nrf52-dk INTERFACE)
5+
add_library(mbed-sdt52832b INTERFACE)
6+
7+
target_include_directories(mbed-nrf52-dk
8+
INTERFACE
9+
TARGET_NRF52_DK
10+
)
11+
12+
target_include_directories(mbed-sdt52832b
13+
INTERFACE
14+
TARGET_SDT52832B
15+
)
1516

1617
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
1718
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/nRF52832.sct)
@@ -21,16 +22,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2122
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_NRF52832.S)
2223
endif()
2324

24-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
25+
add_library(mbed-mcu-nrf52832 INTERFACE)
2526

26-
target_include_directories(mbed-core
27+
target_include_directories(mbed-mcu-nrf52832
2728
INTERFACE
2829
.
2930
config
3031
device
3132
)
3233

33-
target_sources(mbed-core
34+
target_sources(mbed-mcu-nrf52832
3435
INTERFACE
3536
PeripheralPins.c
3637

@@ -39,3 +40,9 @@ target_sources(mbed-core
3940

4041
${STARTUP_FILE}
4142
)
43+
44+
mbed_set_linker_script(mbed-mcu-nrf52832 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
45+
46+
target_link_libraries(mbed-mcu-nrf52832 INTERFACE mbed-nrf52 mbed-sdk-15-0)
47+
target_link_libraries(mbed-nrf52-dk INTERFACE mbed-mcu-nrf52832)
48+
target_link_libraries(mbed-sdt52832b INTERFACE mbed-mcu-nrf52832)
Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
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 ("ARDUINO_NANO33BLE" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_ARDUINO_NANO33BLE
8-
)
9-
elseif("EP_AGORA" IN_LIST MBED_TARGET_LABELS)
10-
target_include_directories(mbed-core
11-
INTERFACE
12-
TARGET_EP_AGORA
13-
)
14-
target_sources(mbed-core
15-
INTERFACE
16-
TARGET_EP_AGORA/ONBOARD_TELIT_ME910.cpp
17-
)
18-
elseif("EP_ATLAS" IN_LIST MBED_TARGET_LABELS)
19-
target_include_directories(mbed-core
20-
INTERFACE
21-
TARGET_EP_ATLAS
22-
)
23-
elseif("NRF52840_DK" IN_LIST MBED_TARGET_LABELS)
24-
target_include_directories(mbed-core
25-
INTERFACE
26-
TARGET_NRF52840_DK
27-
)
28-
endif()
4+
add_library(mbed-arduino-nano33ble INTERFACE)
5+
add_library(mbed-ep-agora INTERFACE)
6+
add_library(mbed-ep-atlas INTERFACE)
7+
add_library(mbed-nrf52840-dk INTERFACE)
8+
9+
target_include_directories(mbed-arduino-nano33ble
10+
INTERFACE
11+
TARGET_ARDUINO_NANO33BLE
12+
)
13+
14+
target_include_directories(mbed-ep-agora
15+
INTERFACE
16+
TARGET_EP_AGORA
17+
)
18+
target_sources(mbed-ep-agora
19+
INTERFACE
20+
TARGET_EP_AGORA/ONBOARD_TELIT_ME910.cpp
21+
)
22+
23+
target_include_directories(mbed-ep-atlas
24+
INTERFACE
25+
TARGET_EP_ATLAS
26+
)
27+
28+
target_include_directories(mbed-nrf52840-dk
29+
INTERFACE
30+
TARGET_NRF52840_DK
31+
)
2932

3033
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
3134
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/nRF52840.sct)
@@ -35,16 +38,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
3538
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_NRF52840.S)
3639
endif()
3740

38-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
41+
add_library(mbed-mcu-nrf52840 INTERFACE)
3942

40-
target_include_directories(mbed-core
43+
target_include_directories(mbed-mcu-nrf52840
4144
INTERFACE
4245
.
4346
config
4447
device
4548
)
4649

47-
target_sources(mbed-core
50+
target_sources(mbed-mcu-nrf52840
4851
INTERFACE
4952
PeripheralPins.c
5053
USBPhy_Nordic.cpp
@@ -54,3 +57,11 @@ target_sources(mbed-core
5457

5558
${STARTUP_FILE}
5659
)
60+
61+
mbed_set_linker_script(mbed-mcu-nrf52840 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
62+
63+
target_link_libraries(mbed-mcu-nrf52840 INTERFACE mbed-nrf52 mbed-sdk-15-0)
64+
target_link_libraries(mbed-arduino-nano33ble INTERFACE mbed-mcu-nrf52840)
65+
target_link_libraries(mbed-ep-agora INTERFACE mbed-mcu-nrf52840)
66+
target_link_libraries(mbed-ep-atlas INTERFACE mbed-mcu-nrf52840) # TODO ask HK about this
67+
target_link_libraries(mbed-nrf52840-dk INTERFACE mbed-mcu-nrf52840)
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
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("SOFTDEVICE_NONE" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_SOFTDEVICE_NONE)
6-
endif()
4+
add_library(mbed-sdk-15-0 INTERFACE)
75

8-
add_subdirectory(components)
9-
add_subdirectory(integration)
10-
add_subdirectory(modules)
6+
add_subdirectory(TARGET_SOFTDEVICE_NONE EXCLUDE_FROM_ALL)
7+
add_subdirectory(components EXCLUDE_FROM_ALL)
8+
add_subdirectory(integration EXCLUDE_FROM_ALL)
9+
add_subdirectory(modules EXCLUDE_FROM_ALL)
10+
11+
target_link_libraries(mbed-sdk-15-0 INTERFACE mbed-softdevice-none)

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/TARGET_SOFTDEVICE_NONE/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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+
add_library(mbed-softdevice-none INTERFACE)
45

5-
target_include_directories(mbed-core
6+
target_include_directories(mbed-softdevice-none
67
INTERFACE
78
libraries
89
libraries/fstorage
910
nrf_soc_nosd
1011
)
1112

12-
target_sources(mbed-core
13+
target_sources(mbed-softdevice-none
1314
INTERFACE
1415
libraries/fstorage/nrf_fstorage_nvmc.c
1516

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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

5-
target_include_directories(mbed-core
5+
target_include_directories(mbed-sdk-15-0
66
INTERFACE
77
libraries
88
libraries/atomic
@@ -22,7 +22,7 @@ target_include_directories(mbed-core
2222
libraries/util
2323
)
2424

25-
target_sources(mbed-core
25+
target_sources(mbed-sdk-15-0
2626
INTERFACE
2727
libraries/atomic/nrf_atomic.c
2828

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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-
target_include_directories(mbed-core
4+
target_include_directories(mbed-sdk-15-0
55
INTERFACE
66
.
77
nrfx
88
nrfx/legacy
99
nrfx/legacy/ble_flash
1010
)
1111

12-
target_sources(mbed-core
12+
target_sources(mbed-sdk-15-0
1313
INTERFACE
1414
nrfx/legacy/nrf_drv_rng.c
1515
nrfx/legacy/nrf_drv_usbd.c

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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+
target_include_directories(mbed-sdk-15-0
55
INTERFACE
66
.
77
nrfx
@@ -16,7 +16,7 @@ target_include_directories(mbed-core
1616
softdevice/common
1717
)
1818

19-
target_sources(mbed-core
19+
target_sources(mbed-sdk-15-0
2020
INTERFACE
2121
nrfx/drivers/src/nrfx_adc.c
2222
nrfx/drivers/src/nrfx_clock.c

0 commit comments

Comments
 (0)