Skip to content

Commit d960d8f

Browse files
committed
CMake: Refactor Silicon Laboratories targets
Refactor all Silicon Laboratories 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 d960d8f

File tree

6 files changed

+83
-68
lines changed

6 files changed

+83
-68
lines changed
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +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("EFM32" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_EFM32)
6-
endif()
4+
add_subdirectory(TARGET_EFM32 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_SL_RAIL EXCLUDE_FROM_ALL)
76

8-
if("SL_RAIL" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_SL_RAIL)
10-
endif()
7+
add_library(mbed-silicon-labs INTERFACE)
118

12-
target_include_directories(mbed-core
9+
target_include_directories(mbed-silicon-labs
1310
INTERFACE
1411
.
1512
)

targets/TARGET_Silicon_Labs/TARGET_EFM32/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
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("EFM32GG" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_EFM32GG)
6-
elseif("EFM32GG11" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_EFM32GG11)
8-
elseif("EFR32MG12" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_EFR32MG12)
10-
endif()
4+
add_subdirectory(TARGET_EFM32GG EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_EFM32GG11 EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_EFR32MG12 EXCLUDE_FROM_ALL)
117

12-
target_include_directories(mbed-core
8+
add_library(mbed-efm32 INTERFACE)
9+
10+
target_include_directories(mbed-efm32
1311
INTERFACE
1412
.
1513
common
1614
emlib/inc
1715
trng
1816
)
1917

20-
target_sources(mbed-core
18+
target_sources(mbed-efm32
2119
INTERFACE
2220
analogin_api.c
2321
analogout_api.c
@@ -95,3 +93,5 @@ target_sources(mbed-core
9593
trng/sl_trng.c
9694
trng/trng_api.c
9795
)
96+
97+
target_link_libraries(mbed-efm32 INTERFACE mbed-silicon-labs)
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
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("EFM32GG_STK3700" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_EFM32GG_STK3700
8-
)
9-
endif()
4+
add_library(mbed-1024k INTERFACE)
105

11-
if("1024K" IN_LIST MBED_TARGET_LABELS)
12-
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
13-
set(LINKER_FILE device/TARGET_1024K/TOOLCHAIN_ARM_STD/efm32gg.sct)
14-
set(STARTUP_FILE device/TARGET_1024K/TOOLCHAIN_ARM_STD/startup_efm32gg.S)
15-
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
16-
set(LINKER_FILE device/TARGET_1024K/TOOLCHAIN_GCC_ARM/efm32gg.ld)
17-
set(STARTUP_FILE device/TARGET_1024K/TOOLCHAIN_GCC_ARM/startup_efm32gg.S)
18-
endif()
6+
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
7+
set(LINKER_FILE device/TARGET_1024K/TOOLCHAIN_ARM_STD/efm32gg.sct)
8+
set(STARTUP_FILE device/TARGET_1024K/TOOLCHAIN_ARM_STD/startup_efm32gg.S)
9+
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
10+
set(LINKER_FILE device/TARGET_1024K/TOOLCHAIN_GCC_ARM/efm32gg.ld)
11+
set(STARTUP_FILE device/TARGET_1024K/TOOLCHAIN_GCC_ARM/startup_efm32gg.S)
1912
endif()
2013

21-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
22-
23-
target_include_directories(mbed-core
14+
target_include_directories(mbed-1024k
2415
INTERFACE
2516
device
2617
)
2718

28-
target_sources(mbed-core
19+
target_sources(mbed-1024k
2920
INTERFACE
3021
PeripheralPins.c
3122

3223
device/system_efm32gg.c
3324
${STARTUP_FILE}
3425
)
26+
27+
mbed_set_linker_script(mbed-1024k ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
add_library(mbed-efm32gg990f1024 INTERFACE)
30+
31+
target_link_libraries(mbed-efm32gg990f1024 INTERFACE mbed-efm32 mbed-1024k)
32+
33+
add_library(mbed-efm32gg-stk3700 INTERFACE)
34+
35+
target_include_directories(mbed-efm32gg-stk3700
36+
INTERFACE
37+
TARGET_EFM32GG_STK3700
38+
)
39+
40+
target_link_libraries(mbed-efm32gg-stk3700 INTERFACE mbed-efm32gg990f1024)
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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("EFM32GG11_STK3701" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_EFM32GG11_STK3701
8-
)
9-
endif()
4+
add_library(mbed-efm32gg11 INTERFACE)
105

116
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
127
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/efm32gg11.sct)
@@ -16,17 +11,28 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
1611
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_efm32gg11.S)
1712
endif()
1813

19-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
20-
21-
target_include_directories(mbed-core
14+
target_include_directories(mbed-efm32gg11
2215
INTERFACE
2316
device
2417
)
2518

26-
target_sources(mbed-core
19+
target_sources(mbed-efm32gg11
2720
INTERFACE
2821
PeripheralPins.c
2922

3023
device/system_efm32gg11b.c
3124
${STARTUP_FILE}
3225
)
26+
27+
target_link_libraries(mbed-efm32gg11 INTERFACE mbed-efm32)
28+
29+
mbed_set_linker_script(mbed-efm32gg11 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
30+
31+
add_library(mbed-efm32gg11-stk3701 INTERFACE)
32+
33+
target_include_directories(mbed-efm32gg11-stk3701
34+
INTERFACE
35+
TARGET_EFM32GG11_STK3701
36+
)
37+
38+
target_link_libraries(mbed-efm32gg11-stk3701 INTERFACE mbed-efm32gg11)
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +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("TB_SENSE_12" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_TB_SENSE_12
8-
)
9-
endif()
4+
add_library(mbed-efm32mg12 INTERFACE)
105

116
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
127
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/efr32mg12p.sct)
@@ -16,17 +11,28 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
1611
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_efr32mg12p.S)
1712
endif()
1813

19-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
20-
21-
target_include_directories(mbed-core
14+
target_include_directories(mbed-efm32mg12
2215
INTERFACE
2316
device
2417
)
2518

26-
target_sources(mbed-core
19+
target_sources(mbed-efm32mg12
2720
INTERFACE
2821
PeripheralPins.c
2922

3023
device/system_efr32mg12p.c
3124
${STARTUP_FILE}
3225
)
26+
27+
target_link_libraries(mbed-efm32mg12 INTERFACE mbed-efm32)
28+
29+
mbed_set_linker_script(mbed-efm32mg12 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
30+
31+
add_library(mbed-tb-sense-12 INTERFACE)
32+
33+
target_include_directories(mbed-tb-sense-12
34+
INTERFACE
35+
TARGET_TB_SENSE_12
36+
)
37+
38+
target_link_libraries(mbed-tb-sense-12 INTERFACE mbed-efm32mg12 mbed-sl-rail-efr32-12)

targets/TARGET_Silicon_Labs/TARGET_SL_RAIL/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +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("EFR32_12" IN_LIST MBED_TARGET_LABELS)
5-
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
6-
set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.ar)
7-
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
8-
set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.a)
9-
endif()
4+
add_library(mbed-sl-rail-efr32-12 INTERFACE)
5+
6+
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
7+
set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.ar)
8+
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
9+
set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.a)
1010
endif()
1111

12-
target_link_libraries(mbed-core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_RAIL})
12+
target_link_libraries(mbed-sl-rail-efr32-12 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_RAIL})
1313

1414

15-
target_include_directories(mbed-core
15+
target_include_directories(mbed-sl-rail-efr32-12
1616
INTERFACE
1717
efr32-rf-driver/rail
1818
efr32-rf-driver/rail/ble

0 commit comments

Comments
 (0)