Skip to content

Commit 33c35f7

Browse files
CMake: refactor GigaDevice targets
Refactor all GigaDevice 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 33c35f7

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("GD32F30X" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_GD32F30X)
6-
elseif("GD32F4XX" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_GD32F4XX)
8-
endif()
4+
add_subdirectory(TARGET_GD32F30X)
5+
add_subdirectory(TARGET_GD32F4XX)
96

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

targets/TARGET_GigaDevice/TARGET_GD32F30X/CMakeLists.txt

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

4-
if("GD32F307VG" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_GD32F307VG
8-
TARGET_GD32F307VG/device
9-
)
4+
add_library(mbed-gd32-f307vg INTERFACE)
105

11-
target_sources(mbed-core
12-
INTERFACE
13-
TARGET_GD32F307VG/PeripheralPins.c
6+
target_include_directories(mbed-gd32-f307vg
7+
INTERFACE
8+
TARGET_GD32F307VG
9+
TARGET_GD32F307VG/device
10+
)
1411

15-
TARGET_GD32F307VG/device/system_gd32f30x.c
16-
)
12+
target_sources(mbed-gd32-f307vg
13+
INTERFACE
14+
TARGET_GD32F307VG/PeripheralPins.c
1715

18-
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
19-
set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/gd32f307vg.sct)
20-
set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/startup_gd32f30x_cl.S)
21-
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
22-
set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld)
23-
set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S)
24-
endif()
16+
TARGET_GD32F307VG/device/system_gd32f30x.c
17+
)
18+
19+
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
20+
set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/gd32f307vg.sct)
21+
set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/startup_gd32f30x_cl.S)
22+
elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
23+
set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld)
24+
set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S)
2525
endif()
2626

27-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
27+
add_library(mbed-gd32f30x INTERFACE)
2828

29-
target_include_directories(mbed-core
29+
target_include_directories(mbed-gd32f30x
3030
INTERFACE
3131
.
3232
GD32F30x_standard_peripheral/Include
3333
)
3434

35-
target_sources(mbed-core
35+
target_sources(mbed-gd32f30x
3636
INTERFACE
3737
analogin_api.c
3838
analogout_api.c
@@ -77,3 +77,8 @@ target_sources(mbed-core
7777

7878
${STARTUP_FILE}
7979
)
80+
81+
mbed_set_linker_script(mbed-gd32f30x ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
82+
83+
target_link_libraries(mbed-gd32f30x INTERFACE mbed-gigadevice)
84+
target_link_libraries(mbed-gd32-f307vg INTERFACE mbed-gd32f30x)

targets/TARGET_GigaDevice/TARGET_GD32F4XX/CMakeLists.txt

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

4-
if("GD32F450ZI" IN_LIST MBED_TARGET_LABELS)
5-
target_include_directories(mbed-core
6-
INTERFACE
7-
TARGET_GD32F450ZI
8-
)
4+
add_library(mbed-gd32-f450zi INTERFACE)
95

10-
target_sources(mbed-core
11-
INTERFACE
12-
TARGET_GD32F450ZI/PeripheralPins.c
13-
)
14-
endif()
6+
target_include_directories(mbed-gd32-f450zi
7+
INTERFACE
8+
TARGET_GD32F450ZI
9+
)
10+
11+
target_sources(mbed-gd32-f450zi
12+
INTERFACE
13+
TARGET_GD32F450ZI/PeripheralPins.c
14+
)
1515

1616
if(${MBED_TOOLCHAIN} STREQUAL "ARM")
1717
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/gd32f450zi.sct)
@@ -21,16 +21,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
2121
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_gd32f450.S)
2222
endif()
2323

24-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
24+
add_library(mbed-gd32f4xx INTERFACE)
2525

26-
target_include_directories(mbed-core
26+
target_include_directories(mbed-gd32f4xx
2727
INTERFACE
2828
.
2929
device
3030
GD32F4xx_standard_peripheral/Include
3131
)
3232

33-
target_sources(mbed-core
33+
target_sources(mbed-gd32f4xx
3434
INTERFACE
3535
analogin_api.c
3636
analogout_api.c
@@ -84,3 +84,8 @@ target_sources(mbed-core
8484

8585
${STARTUP_FILE}
8686
)
87+
88+
mbed_set_linker_script(mbed-gd32-f450zi ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
89+
90+
target_link_libraries(mbed-gd32f4xx INTERFACE mbed-gigadevice)
91+
target_link_libraries(mbed-gd32-f450zi INTERFACE mbed-gd32f4xx)

0 commit comments

Comments
 (0)