Skip to content

Commit 222a556

Browse files
committed
cmake: Refactor ST targets
Refactor all ST 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 6f4206d commit 222a556

File tree

170 files changed

+1351
-836
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1351
-836
lines changed

targets/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
include(../tools/cmake/SetLinkerScript.cmake)
34

45
if("Ambiq_Micro" IN_LIST MBED_TARGET_LABELS)
56
add_subdirectory(TARGET_Ambiq_Micro)

targets/TARGET_STM/CMakeLists.txt

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("STM32F0" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_STM32F0)
6-
elseif("STM32F1" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_STM32F1)
8-
elseif("STM32F2" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_STM32F2)
10-
elseif("STM32F3" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_STM32F3)
12-
elseif("STM32F4" IN_LIST MBED_TARGET_LABELS)
13-
add_subdirectory(TARGET_STM32F4)
14-
elseif("STM32F7" IN_LIST MBED_TARGET_LABELS)
15-
add_subdirectory(TARGET_STM32F7)
16-
elseif("STM32G0" IN_LIST MBED_TARGET_LABELS)
17-
add_subdirectory(TARGET_STM32G0)
18-
elseif("STM32G4" IN_LIST MBED_TARGET_LABELS)
19-
add_subdirectory(TARGET_STM32G4)
20-
elseif("STM32H7" IN_LIST MBED_TARGET_LABELS)
21-
add_subdirectory(TARGET_STM32H7)
22-
elseif("STM32L0" IN_LIST MBED_TARGET_LABELS)
23-
add_subdirectory(TARGET_STM32L0)
24-
elseif("STM32L1" IN_LIST MBED_TARGET_LABELS)
25-
add_subdirectory(TARGET_STM32L1)
26-
elseif("STM32L4" IN_LIST MBED_TARGET_LABELS)
27-
add_subdirectory(TARGET_STM32L4)
28-
elseif("STM32L5" IN_LIST MBED_TARGET_LABELS)
29-
add_subdirectory(TARGET_STM32L5)
30-
elseif("STM32WB" IN_LIST MBED_TARGET_LABELS)
31-
add_subdirectory(TARGET_STM32WB)
32-
endif()
4+
add_subdirectory(TARGET_STM32F0 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_STM32F1 EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_STM32F2 EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_STM32F3 EXCLUDE_FROM_ALL)
8+
add_subdirectory(TARGET_STM32F4 EXCLUDE_FROM_ALL)
9+
add_subdirectory(TARGET_STM32F7 EXCLUDE_FROM_ALL)
10+
add_subdirectory(TARGET_STM32G0 EXCLUDE_FROM_ALL)
11+
add_subdirectory(TARGET_STM32G4 EXCLUDE_FROM_ALL)
12+
add_subdirectory(TARGET_STM32H7 EXCLUDE_FROM_ALL)
13+
add_subdirectory(TARGET_STM32L0 EXCLUDE_FROM_ALL)
14+
add_subdirectory(TARGET_STM32L1 EXCLUDE_FROM_ALL)
15+
add_subdirectory(TARGET_STM32L4 EXCLUDE_FROM_ALL)
16+
add_subdirectory(TARGET_STM32L5 EXCLUDE_FROM_ALL)
17+
add_subdirectory(TARGET_STM32WB EXCLUDE_FROM_ALL)
3318

34-
target_include_directories(mbed-core
19+
add_library(STM INTERFACE)
20+
21+
target_include_directories(STM
3522
INTERFACE
3623
.
3724
)
3825

39-
target_sources(mbed-core
26+
target_sources(STM
4027
INTERFACE
4128
USBPhy_STM32.cpp
4229
analogin_api.c
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("STM32F091xC" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_STM32F091xC)
6-
elseif("STM32F072xB" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_STM32F072xB)
8-
elseif("STM32F070xB" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_STM32F070xB)
10-
elseif("STM32F030x8" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_STM32F030x8)
12-
endif()
4+
add_subdirectory(TARGET_STM32F091xC EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_STM32F072xB EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_STM32F070xB EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_STM32F030x8 EXCLUDE_FROM_ALL)
8+
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)
139

14-
add_subdirectory(STM32Cube_FW)
10+
add_library(STM32F0 INTERFACE)
1511

16-
target_include_directories(mbed-core
12+
target_include_directories(STM32F0
1713
INTERFACE
1814
.
1915
)
2016

21-
target_sources(mbed-core
17+
target_sources(STM32F0
2218
INTERFACE
2319
analogin_device.c
2420
analogout_device.c
@@ -29,3 +25,5 @@ target_sources(mbed-core
2925
serial_device.c
3026
spi_api.c
3127
)
28+
29+
target_link_libraries(STM32F0 INTERFACE STM STM32F0Cube_FW)

targets/TARGET_STM/TARGET_STM32F0/STM32Cube_FW/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(STM32F0Cube_FW INTERFACE)
5+
6+
target_sources(STM32F0Cube_FW
57
INTERFACE
68
STM32F0xx_HAL_Driver/Legacy/stm32f0xx_hal_can_legacy.c
79
STM32F0xx_HAL_Driver/stm32f0xx_hal.c
@@ -66,7 +68,7 @@ target_sources(mbed-core
6668
system_stm32f0xx.c
6769
)
6870

69-
target_include_directories(mbed-core
71+
target_include_directories(STM32F0Cube_FW
7072
INTERFACE
7173
.
7274
CMSIS

targets/TARGET_STM/TARGET_STM32F0/TARGET_STM32F030x8/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
99
set(LINKER_FILE TOOLCHAIN_ARM/stm32f030x8.sct)
1010
endif()
1111

12-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_library(STM32F030x8 INTERFACE)
1313

14-
target_sources(mbed-core
14+
target_sources(STM32F030x8
1515
INTERFACE
1616
${STARTUP_FILE}
1717
)
1818

19-
target_include_directories(mbed-core
19+
target_include_directories(STM32F030x8
2020
INTERFACE
2121
.
2222
)
23+
24+
mbed_set_linker_script(STM32F030x8 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
25+
26+
target_link_libraries(STM32F030x8 INTERFACE STM32F0)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("NUCLEO_F070RB" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUCLEO_F070RB)
6-
endif()
4+
add_subdirectory(TARGET_NUCLEO_F070RB EXCLUDE_FROM_ALL)
75

86
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
97
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32f070xb.S)
@@ -13,15 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1311
set(LINKER_FILE TOOLCHAIN_ARM/stm32f070xb.sct)
1412
endif()
1513

16-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(STM32F070xB INTERFACE)
1715

18-
target_sources(mbed-core
16+
target_sources(STM32F070xB
1917
INTERFACE
2018
system_clock.c
2119
${STARTUP_FILE}
2220
)
2321

24-
target_include_directories(mbed-core
22+
target_include_directories(STM32F070xB
2523
INTERFACE
2624
.
2725
)
26+
27+
mbed_set_linker_script(STM32F070xB ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
target_link_libraries(STM32F070xB INTERFACE STM32F0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(NUCLEO_F070RB INTERFACE)
5+
6+
target_sources(NUCLEO_F070RB
57
INTERFACE
68
PeripheralPins.c
79
)
810

9-
target_include_directories(mbed-core
11+
target_include_directories(NUCLEO_F070RB
1012
INTERFACE
1113
.
1214
)
15+
16+
target_link_libraries(NUCLEO_F070RB INTERFACE STM32F070xB)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("NUCLEO_F072RB" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUCLEO_F072RB)
6-
endif()
4+
add_subdirectory(TARGET_NUCLEO_F072RB EXCLUDE_FROM_ALL)
75

86
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
97
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32f072xb.S)
@@ -13,15 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1311
set(LINKER_FILE TOOLCHAIN_ARM/stm32f072xb.sct)
1412
endif()
1513

16-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(STM32F072xB INTERFACE)
1715

18-
target_sources(mbed-core
16+
target_sources(STM32F072xB
1917
INTERFACE
2018
system_clock.c
2119
${STARTUP_FILE}
2220
)
2321

24-
target_include_directories(mbed-core
22+
target_include_directories(STM32F072xB
2523
INTERFACE
2624
.
2725
)
26+
27+
mbed_set_linker_script(STM32F072xB ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
target_link_libraries(STM32F072xB INTERFACE STM32F0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(NUCLEO_F072RB INTERFACE)
5+
6+
target_sources(NUCLEO_F072RB
57
INTERFACE
68
PeripheralPins.c
79
)
810

9-
target_include_directories(mbed-core
11+
target_include_directories(NUCLEO_F072RB
1012
INTERFACE
1113
.
1214
)
15+
16+
target_link_libraries(NUCLEO_F072RB INTERFACE STM32F072xB)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("NUCLEO_F091RC" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUCLEO_F091RC)
6-
endif()
4+
add_subdirectory(TARGET_NUCLEO_F091RC EXCLUDE_FROM_ALL)
75

86
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
97
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32f091xc.S)
@@ -13,15 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1311
set(LINKER_FILE TOOLCHAIN_ARM/stm32f091xc.sct)
1412
endif()
1513

16-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(STM32F091xC INTERFACE)
1715

18-
target_sources(mbed-core
16+
target_sources(STM32F091xC
1917
INTERFACE
2018
system_clock.c
2119
${STARTUP_FILE}
2220
)
2321

24-
target_include_directories(mbed-core
22+
target_include_directories(STM32F091xC
2523
INTERFACE
2624
.
2725
)
26+
27+
mbed_set_linker_script(STM32F091xC ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
target_link_libraries(STM32F091xC INTERFACE STM32F0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(NUCLEO_F091RC INTERFACE)
5+
6+
target_sources(NUCLEO_F091RC
57
INTERFACE
68
PeripheralPins.c
79
)
810

9-
target_include_directories(mbed-core
11+
target_include_directories(NUCLEO_F091RC
1012
INTERFACE
1113
.
1214
)
15+
16+
target_link_libraries(NUCLEO_F091RC INTERFACE STM32F091xC)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("STM32F103x8" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_STM32F103x8)
6-
elseif("STM32F103xB" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_STM32F103xB)
8-
endif()
4+
add_subdirectory(TARGET_STM32F103x8 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_STM32F103xB EXCLUDE_FROM_ALL)
6+
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)
97

10-
target_sources(mbed-core
8+
add_library(STM32F1 INTERFACE)
9+
10+
target_sources(STM32F1
1111
INTERFACE
1212
analogin_device.c
1313
flash_api.c
@@ -17,9 +17,9 @@ target_sources(mbed-core
1717
spi_api.c
1818
)
1919

20-
add_subdirectory(STM32Cube_FW)
21-
22-
target_include_directories(mbed-core
20+
target_include_directories(STM32F1
2321
INTERFACE
2422
.
2523
)
24+
25+
target_link_libraries(STM32F1 INTERFACE STM STM32F1Cube_FW)

targets/TARGET_STM/TARGET_STM32F1/STM32Cube_FW/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(STM32F1Cube_FW INTERFACE)
5+
6+
target_sources(STM32F1Cube_FW
57
INTERFACE
68
STM32F1xx_HAL_Driver/Legacy/stm32f1xx_hal_can_legacy.c
79
STM32F1xx_HAL_Driver/stm32f1xx_hal.c
@@ -65,7 +67,7 @@ target_sources(mbed-core
6567
system_stm32f1xx.c
6668
)
6769

68-
target_include_directories(mbed-core
70+
target_include_directories(STM32F1Cube_FW
6971
INTERFACE
7072
.
7173
CMSIS

targets/TARGET_STM/TARGET_STM32F1/TARGET_STM32F103x8/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
99
set(LINKER_FILE TOOLCHAIN_ARM/stm32f103x8.sct)
1010
endif()
1111

12-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_library(STM32F103x8 INTERFACE)
1313

14-
target_sources(mbed-core
14+
target_sources(STM32F103x8
1515
INTERFACE
1616
system_clock.c
1717
${STARTUP_FILE}
1818
)
1919

20-
target_include_directories(mbed-core
20+
target_include_directories(STM32F103x8
2121
INTERFACE
2222
.
2323
)
24+
25+
mbed_set_linker_script(STM32F103x8 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
26+
27+
target_link_libraries(STM32F103x8 INTERFACE STM32F1)

0 commit comments

Comments
 (0)