Skip to content

Commit f6837ce

Browse files
committed
CMake: Refactor NXP targets
Refactor all NXP targets to be CMake build system 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 f6837ce

File tree

18 files changed

+269
-179
lines changed

18 files changed

+269
-179
lines changed

targets/TARGET_NXP/CMakeLists.txt

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +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("LPC11XX_11CXX" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_LPC11XX_11CXX)
6-
elseif("LPC176X" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_LPC176X)
8-
elseif("MCUXpresso_MCUS" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_MCUXpresso_MCUS)
10-
endif()
4+
add_subdirectory(TARGET_LPC11XX_11CXX EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_LPC176X EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_MCUXpresso_MCUS EXCLUDE_FROM_ALL)
117

12-
target_include_directories(mbed-core
8+
add_library(mbed-nxp INTERFACE)
9+
10+
target_include_directories(mbed-nxp
1311
INTERFACE
1412
.
1513
)
1614

17-
target_sources(mbed-core
15+
target_sources(mbed-nxp
1816
INTERFACE
1917
USBHAL_LPC17.cpp
2018
)
Original file line numberDiff line numberDiff line change
@@ -1,35 +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("LPC11XX" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_LPC11XX
8-
)
9-
10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_LPC11XX/device/system_LPC11xx.c
13-
)
14-
15-
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
16-
set(STARTUP_FILE device/TOOLCHAIN_ARM_STD/TARGET_LPC11XX/startup_LPC11xx.S)
17-
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/TARGET_LPC11XX/LPC1114.sct)
18-
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
19-
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_LPC11xx.S)
20-
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/TARGET_LPC11XX/LPC1114.ld)
21-
endif()
4+
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
5+
set(STARTUP_FILE device/TOOLCHAIN_ARM_STD/TARGET_LPC11XX/startup_LPC11xx.S)
6+
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/TARGET_LPC11XX/LPC1114.sct)
7+
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
8+
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_LPC11xx.S)
9+
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/TARGET_LPC11XX/LPC1114.ld)
2210
endif()
2311

24-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_subdirectory(TARGET_LPC11XX EXCLUDE_FROM_ALL)
2513

26-
target_include_directories(mbed-core
14+
add_library(mbed-lpc11xx-11cxx INTERFACE)
15+
16+
target_include_directories(mbed-lpc11xx-11cxx
2717
INTERFACE
2818
.
2919
device
3020
)
3121

32-
target_sources(mbed-core
22+
target_sources(mbed-lpc11xx-11cxx
3323
INTERFACE
3424
analogin_api.c
3525
gpio_api.c
@@ -46,3 +36,11 @@ target_sources(mbed-core
4636
device/cmsis_nvic.c
4737
${STARTUP_FILE}
4838
)
39+
40+
target_link_libraries(mbed-lpc11xx-11cxx INTERFACE mbed-nxp)
41+
42+
add_library(mbed-lpc1114 INTERFACE)
43+
44+
mbed_set_linker_script(mbed-lpc1114 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
45+
46+
target_link_libraries(mbed-lpc1114 INTERFACE mbed-lpc11xx)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-lpc11xx INTERFACE)
5+
6+
target_include_directories(mbed-lpc11xx
7+
INTERFACE
8+
.
9+
)
10+
11+
target_sources(mbed-lpc11xx
12+
INTERFACE
13+
device/system_LPC11xx.c
14+
)
15+
16+
target_link_libraries(mbed-lpc11xx INTERFACE mbed-lpc11xx-11cxx)

targets/TARGET_NXP/TARGET_LPC176X/CMakeLists.txt

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
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("ARCH_PRO" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_ARCH_PRO
8-
)
9-
elseif("MBED_LPC1768" IN_LIST MBED_TARGET_LABELS)
10-
target_include_directories(mbed-core
11-
INTERFACE
12-
TARGET_MBED_LPC1768
13-
)
14-
endif()
4+
add_subdirectory(TARGET_ARCH_PRO EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_MBED_LPC1768 EXCLUDE_FROM_ALL)
6+
7+
add_library(mbed-lpc176x INTERFACE)
158

169
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
1710
set(STARTUP_FILE device/TOOLCHAIN_ARM_STD/startup_LPC17xx.S)
@@ -21,15 +14,13 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2114
set(LINKER_FILE device/TOOLCHAIN_GCC_ARM/LPC1768.ld)
2215
endif()
2316

24-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
25-
26-
target_include_directories(mbed-core
17+
target_include_directories(mbed-lpc176x
2718
INTERFACE
2819
.
2920
device
3021
)
3122

32-
target_sources(mbed-core
23+
target_sources(mbed-lpc176x
3324
INTERFACE
3425
analogin_api.c
3526
analogout_api.c
@@ -53,3 +44,8 @@ target_sources(mbed-core
5344
device/system_LPC17xx.c
5445
${STARTUP_FILE}
5546
)
47+
48+
target_link_libraries(mbed-lpc176x INTERFACE mbed-nxp)
49+
50+
mbed_set_linker_script(mbed-arch-pro ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
51+
mbed_set_linker_script(mbed-lpc1768 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-arch-pro INTERFACE)
5+
6+
target_include_directories(mbed-arch-pro
7+
INTERFACE
8+
.
9+
)
10+
11+
target_link_libraries(mbed-arch-pro INTERFACE mbed-lpc176x)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-mbed-lpc1768 INTERFACE)
5+
6+
target_include_directories(mbed-mbed-lpc1768
7+
INTERFACE
8+
.
9+
)
10+
11+
target_link_libraries(mbed-mbed-lpc1768 INTERFACE mbed-lpc176x)
12+
13+
add_library(mbed-lpc1768 INTERFACE)
14+
15+
target_link_libraries(mbed-lpc1768 INTERFACE mbed-mbed-lpc1768)
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
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("IMX" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_IMX)
6-
endif()
4+
add_subdirectory(TARGET_IMX EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_LPC EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_LPC54114 EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_MCU_LPC546XX EXCLUDE_FROM_ALL)
8+
add_subdirectory(TARGET_MIMXRT1050 EXCLUDE_FROM_ALL)
9+
add_subdirectory(middleware/TARGET_USB EXCLUDE_FROM_ALL)
710

8-
if("LPC" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_LPC)
10-
endif()
11+
add_library(mbed-mcuxpresso-mcus INTERFACE)
1112

12-
if("LPC54114" IN_LIST MBED_TARGET_LABELS)
13-
add_subdirectory(TARGET_LPC54114)
14-
endif()
15-
16-
if("MCU_LPC546XX" IN_LIST MBED_TARGET_LABELS)
17-
add_subdirectory(TARGET_MCU_LPC546XX)
18-
endif()
19-
20-
if("MIMXRT1050" IN_LIST MBED_TARGET_LABELS)
21-
add_subdirectory(TARGET_MIMXRT1050)
22-
endif()
23-
24-
if("USB" IN_LIST MBED_TARGET_LABELS)
25-
add_subdirectory(middleware/TARGET_USB)
26-
endif()
27-
28-
target_include_directories(mbed-core
13+
target_include_directories(mbed-mcuxpresso-mcus
2914
INTERFACE
3015
.
3116
middleware/osa
3217
)
3318

34-
target_sources(mbed-core
19+
target_sources(mbed-mcuxpresso-mcus
3520
INTERFACE
3621
USBPhy_MCUXpresso.cpp
3722

3823
middleware/osa/fsl_os_abstraction_mbed.c
3924
)
25+
26+
target_link_libraries(mbed-mcuxpresso-mcus INTERFACE mbed-nxp)

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_IMX/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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-imx INTERFACE)
5+
6+
target_include_directories(mbed-imx
57
INTERFACE
68
.
79
)
810

9-
target_sources(mbed-core
11+
target_sources(mbed-imx
1012
INTERFACE
1113
analogin_api.c
1214
flash_api.c

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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-lpc INTERFACE)
5+
6+
target_include_directories(mbed-lpc
57
INTERFACE
68
.
79
)
810

9-
target_sources(mbed-core
11+
target_sources(mbed-lpc
1012
INTERFACE
1113
analogin_api.c
1214
gpio_api.c
Original file line numberDiff line numberDiff line change
@@ -1,53 +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("LPCXpresso" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_LPCXpresso
8-
)
4+
add_subdirectory(device/TARGET_LPC54114_M4 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_LPCXpresso EXCLUDE_FROM_ALL)
96

10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_LPCXpresso/PeripheralPins.c
13-
TARGET_LPCXpresso/clock_config.c
14-
TARGET_LPCXpresso/mbed_overrides.c
15-
)
16-
endif()
7+
add_library(mbed-lpc54114 INTERFACE)
178

18-
if("LPC54114_M4" IN_LIST MBED_TARGET_LABELS)
19-
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
20-
set(STARTUP_FILE device/TARGET_LPC54114_M4/TOOLCHAIN_ARM_STD/startup_LPC54114_cm4.S)
21-
set(LINKER_FILE device/TARGET_LPC54114_M4/TOOLCHAIN_ARM_STD/LPC54114J256_cm4.sct)
22-
set(LIB_POWER device/TARGET_LPC54114_M4/TOOLCHAIN_ARM_STD/libpower.ar)
23-
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
24-
set(STARTUP_FILE device/TARGET_LPC54114_M4/TOOLCHAIN_GCC_ARM/startup_LPC54114_cm4.S)
25-
set(LINKER_FILE device/TARGET_LPC54114_M4/TOOLCHAIN_GCC_ARM/LPC54114J256_cm4_flash.ld)
26-
set(LIB_POWER device/TARGET_LPC54114_M4/TOOLCHAIN_GCC_ARM/libpower.a)
27-
endif()
28-
29-
target_link_libraries(mbed-core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_POWER})
30-
31-
target_include_directories(mbed-core
32-
INTERFACE
33-
device/TARGET_LPC54114_M4
34-
)
35-
36-
target_sources(mbed-core
37-
INTERFACE
38-
device/TARGET_LPC54114_M4/system_LPC54114_cm4.c
39-
)
40-
endif()
41-
42-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
43-
44-
target_include_directories(mbed-core
9+
target_include_directories(mbed-lpc54114
4510
INTERFACE
4611
device
4712
drivers
4813
)
4914

50-
target_sources(mbed-core
15+
target_sources(mbed-lpc54114
5116
INTERFACE
5217
flash_api.c
5318

@@ -81,6 +46,12 @@ target_sources(mbed-core
8146
drivers/fsl_usart_dma.c
8247
drivers/fsl_utick.c
8348
drivers/fsl_wwdt.c
49+
)
8450

85-
${STARTUP_FILE}
51+
target_link_libraries(mbed-lpc54114
52+
INTERFACE
53+
mbed-mcuxpresso-mcus
54+
mbed-lpc5114-xpresso
55+
mbed-lpc
56+
mbed-lpc54114-m4
8657
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-lpc5114-xpresso INTERFACE)
5+
6+
target_include_directories(mbed-lpc5114-xpresso
7+
INTERFACE
8+
.
9+
)
10+
11+
target_sources(mbed-lpc5114-xpresso
12+
INTERFACE
13+
PeripheralPins.c
14+
clock_config.c
15+
mbed_overrides.c
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
5+
set(STARTUP_FILE TOOLCHAIN_ARM_STD/startup_LPC54114_cm4.S)
6+
set(LINKER_FILE TOOLCHAIN_ARM_STD/LPC54114J256_cm4.sct)
7+
set(LIB_POWER TOOLCHAIN_ARM_STD/libpower.ar)
8+
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
9+
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_LPC54114_cm4.S)
10+
set(LINKER_FILE TOOLCHAIN_GCC_ARM/LPC54114J256_cm4_flash.ld)
11+
set(LIB_POWER TOOLCHAIN_GCC_ARM/libpower.a)
12+
endif()
13+
14+
add_library(mbed-lpc54114-m4 INTERFACE)
15+
16+
target_link_libraries(mbed-lpc54114-m4
17+
INTERFACE
18+
${CMAKE_CURRENT_SOURCE_DIR}/${LIB_POWER}
19+
)
20+
21+
target_include_directories(mbed-lpc54114-m4
22+
INTERFACE
23+
.
24+
)
25+
26+
target_sources(mbed-lpc54114-m4
27+
INTERFACE
28+
system_LPC54114_cm4.c
29+
${STARTUP_FILE}
30+
)
31+
32+
mbed_set_linker_script(mbed-lpc54114-m4 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

0 commit comments

Comments
 (0)