Skip to content

Commit ac44f1c

Browse files
committed
CMake: Refactor Freescale targets
Refactor all Freescale 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 ac44f1c

File tree

22 files changed

+283
-236
lines changed

22 files changed

+283
-236
lines changed
Lines changed: 7 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("KLXX" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_KLXX)
6-
elseif("MCUXpresso_MCUS" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_MCUXpresso_MCUS)
8-
endif()
4+
add_subdirectory(TARGET_KLXX EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_MCUXpresso_MCUS EXCLUDE_FROM_ALL)
96

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

15-
target_sources(mbed-core
14+
target_sources(mbed-freescale
1615
INTERFACE
1716
USBPhy_Kinetis.cpp
1817
)
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("KL25Z" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_KL25Z)
6-
elseif("KL46Z" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_KL46Z)
8-
endif()
4+
add_subdirectory(TARGET_KL25Z EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_KL46Z EXCLUDE_FROM_ALL)
96

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

15-
target_sources(mbed-core
14+
target_sources(mbed-klxx
1615
INTERFACE
1716
analogin_api.c
1817
analogout_api.c
@@ -25,3 +24,5 @@ target_sources(mbed-core
2524
sleep.c
2625
us_ticker.c
2726
)
27+
28+
target_link_libraries(mbed-klxx INTERFACE mbed-freescale)
Lines changed: 8 additions & 8 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,19 +9,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
99
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_MKL25Z4.S)
1010
endif()
1111

12-
set_property(
13-
GLOBAL PROPERTY
14-
MBED_TARGET_LINKER_FILE
15-
${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}
16-
)
12+
add_library(mbed-kl25z INTERFACE)
1713

18-
target_include_directories(mbed-core
14+
target_include_directories(mbed-kl25z
1915
INTERFACE
2016
.
2117
device
2218
)
2319

24-
target_sources(mbed-core
20+
target_sources(mbed-kl25z
2521
INTERFACE
2622
PeripheralPins.c
2723
gpio_irq_api.c
@@ -32,3 +28,7 @@ target_sources(mbed-core
3228
device/system_MKL25Z4.c
3329
${STARTUP_FILE}
3430
)
31+
32+
mbed_set_linker_script(mbed-kl25z ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
33+
34+
target_link_libraries(mbed-kl25z INTERFACE mbed-klxx)
Lines changed: 8 additions & 8 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,19 +9,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
99
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_MKL46Z4.S)
1010
endif()
1111

12-
set_property(
13-
GLOBAL PROPERTY
14-
MBED_TARGET_LINKER_FILE
15-
${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}
16-
)
12+
add_library(mbed-kl46z INTERFACE)
1713

18-
target_include_directories(mbed-core
14+
target_include_directories(mbed-kl46z
1915
INTERFACE
2016
.
2117
device
2218
)
2319

24-
target_sources(mbed-core
20+
target_sources(mbed-kl46z
2521
INTERFACE
2622
PeripheralPins.c
2723
flash_api.c
@@ -33,3 +29,7 @@ target_sources(mbed-core
3329
device/system_MKL46Z4.c
3430
${STARTUP_FILE}
3531
)
32+
33+
mbed_set_linker_script(mbed-kl46z ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
34+
35+
target_link_libraries(mbed-kl46z INTERFACE mbed-klxx)
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +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("K66F" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_K66F)
6-
elseif("K82F" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_K82F)
8-
elseif("KL27Z" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_KL27Z)
10-
elseif("KL43Z" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_KL43Z)
12-
elseif("KW41Z" IN_LIST MBED_TARGET_LABELS)
13-
add_subdirectory(TARGET_KW41Z)
14-
elseif("MCU_K22F" IN_LIST MBED_TARGET_LABELS)
15-
add_subdirectory(TARGET_MCU_K22F)
16-
elseif("MCU_K64F" IN_LIST MBED_TARGET_LABELS)
17-
add_subdirectory(TARGET_MCU_K64F)
18-
endif()
4+
add_subdirectory(TARGET_K66F EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_K82F EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_KL43Z EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_KW41Z EXCLUDE_FROM_ALL)
8+
add_subdirectory(TARGET_MCU_K22F EXCLUDE_FROM_ALL)
9+
add_subdirectory(TARGET_MCU_K64F EXCLUDE_FROM_ALL)
10+
add_subdirectory(middleware/wireless/TARGET_FRAMEWORK_5_3_3 EXCLUDE_FROM_ALL)
1911

20-
if("FRAMEWORK_5_3_3" IN_LIST MBED_TARGET_LABELS)
21-
add_subdirectory(middleware/wireless/TARGET_FRAMEWORK_5_3_3)
22-
endif()
12+
add_library(mbed-mcuxpresso-mcus INTERFACE)
2313

24-
target_include_directories(mbed-core
14+
target_include_directories(mbed-mcuxpresso-mcus
2515
INTERFACE
2616
api
2717
)
2818

29-
target_sources(mbed-core
19+
target_sources(mbed-mcuxpresso-mcus
3020
INTERFACE
3121
fsl_common.c
3222

@@ -44,3 +34,5 @@ target_sources(mbed-core
4434
api/rtc_api.c
4535
api/sleep.c
4636
)
37+
38+
target_link_libraries(mbed-mcuxpresso-mcus INTERFACE mbed-freescale)

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/CMakeLists.txt

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +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-
if("FRDM" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_FRDM
8-
)
9-
10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_FRDM/PeripheralPins.c
13-
TARGET_FRDM/crc.c
14-
TARGET_FRDM/fsl_clock_config.c
15-
TARGET_FRDM/fsl_phy.c
16-
TARGET_FRDM/mbed_overrides.c
17-
)
18-
endif()
4+
add_subdirectory(TARGET_FRDM EXCLUDE_FROM_ALL)
195

206
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
217
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/MK66FN2M0xxx18.sct)
@@ -25,20 +11,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2511
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_MK66F18.S)
2612
endif()
2713

28-
set_property(
29-
GLOBAL PROPERTY
30-
MBED_TARGET_LINKER_FILE
31-
${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}
32-
)
14+
add_library(mbed-k66f INTERFACE)
3315

34-
target_include_directories(mbed-core
16+
target_include_directories(mbed-k66f
3517
INTERFACE
3618
.
3719
device
3820
drivers
3921
)
4022

41-
target_sources(mbed-core
23+
target_sources(mbed-k66f
4224
INTERFACE
4325
pwmout_api.c
4426
serial_api.c
@@ -93,3 +75,7 @@ target_sources(mbed-core
9375
device/system_MK66F18.c
9476
${STARTUP_FILE}
9577
)
78+
79+
mbed_set_linker_script(mbed-k66f ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
80+
81+
target_link_libraries(mbed-k66f INTERFACE mbed-mcuxpresso-mcus mbed-frdm-k66f)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
add_library(mbed-frdm-k66f INTERFACE)
5+
6+
target_include_directories(mbed-frdm-k66f
7+
INTERFACE
8+
.
9+
)
10+
11+
target_sources(mbed-frdm-k66f
12+
INTERFACE
13+
PeripheralPins.c
14+
crc.c
15+
fsl_clock_config.c
16+
fsl_phy.c
17+
mbed_overrides.c
18+
)

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K82F/CMakeLists.txt

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +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-
if("FRDM" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_FRDM
8-
)
9-
10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_FRDM/PeripheralPins.c
13-
TARGET_FRDM/fsl_clock_config.c
14-
TARGET_FRDM/mbed_overrides.c
15-
)
16-
endif()
4+
add_subdirectory(TARGET_FRDM EXCLUDE_FROM_ALL)
175

186
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
197
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/MK82FN256xxx15.sct)
@@ -23,20 +11,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2311
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_MK82F25615.S)
2412
endif()
2513

26-
set_property(
27-
GLOBAL PROPERTY
28-
MBED_TARGET_LINKER_FILE
29-
${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}
30-
)
14+
add_library(mbed-k82f INTERFACE)
3115

32-
target_include_directories(mbed-core
16+
target_include_directories(mbed-k82f
3317
INTERFACE
3418
.
3519
device
3620
drivers
3721
)
3822

39-
target_sources(mbed-core
23+
target_sources(mbed-k82f
4024
INTERFACE
4125
pwmout_api.c
4226
serial_api.c
@@ -105,3 +89,7 @@ target_sources(mbed-core
10589
device/system_MK82F25615.c
10690
${STARTUP_FILE}
10791
)
92+
93+
mbed_set_linker_script(mbed-k82f ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
94+
95+
target_link_libraries(mbed-k82f INTERFACE mbed-mcuxpresso-mcus mbed-frdm-k82f)
Lines changed: 16 additions & 0 deletions
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-frdm-k82f INTERFACE)
5+
6+
target_include_directories(mbed-frdm-k82f
7+
INTERFACE
8+
.
9+
)
10+
11+
target_sources(mbed-frdm-k82f
12+
INTERFACE
13+
PeripheralPins.c
14+
fsl_clock_config.c
15+
mbed_overrides.c
16+
)

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_KL43Z/CMakeLists.txt

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +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-
if("FRDM" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_FRDM
8-
)
9-
10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_FRDM/PeripheralPins.c
13-
TARGET_FRDM/fsl_clock_config.c
14-
TARGET_FRDM/mbed_overrides.c
15-
)
16-
endif()
4+
add_subdirectory(TARGET_FRDM EXCLUDE_FROM_ALL)
175

186
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
197
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/MKL43Z256xxx4.sct)
@@ -23,20 +11,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2311
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_MKL43Z4.S)
2412
endif()
2513

26-
set_property(
27-
GLOBAL PROPERTY
28-
MBED_TARGET_LINKER_FILE
29-
${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}
30-
)
14+
add_library(mbed-kl43z INTERFACE)
3115

32-
target_include_directories(mbed-core
16+
target_include_directories(mbed-kl43z
3317
INTERFACE
3418
.
3519
device
3620
drivers
3721
)
3822

39-
target_sources(mbed-core
23+
target_sources(mbed-kl43z
4024
INTERFACE
4125
pwmout_api.c
4226
serial_api.c
@@ -85,3 +69,9 @@ target_sources(mbed-core
8569
device/system_MKL43Z4.c
8670
${STARTUP_FILE}
8771
)
72+
73+
target_link_libraries(mbed-kl43z INTERFACE mbed-mcuxpresso-mcus)
74+
75+
mbed_set_linker_script(mbed-kl43z ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
76+
77+
target_link_libraries(mbed-kl43z INTERFACE mbed-frdm-kl43z)

0 commit comments

Comments
 (0)