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.
pull/14281/head
Harrison Mutai 2021-02-12 15:55:19 +00:00
parent 8284807a00
commit 33c35f791b
3 changed files with 49 additions and 40 deletions

View File

@ -1,13 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("GD32F30X" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_GD32F30X) add_subdirectory(TARGET_GD32F30X)
elseif("GD32F4XX" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_GD32F4XX) add_subdirectory(TARGET_GD32F4XX)
endif()
target_include_directories(mbed-core add_library(mbed-gigadevice INTERFACE)
target_include_directories(mbed-gigadevice
INTERFACE INTERFACE
. .
) )

View File

@ -1,14 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("GD32F307VG" IN_LIST MBED_TARGET_LABELS) add_library(mbed-gd32-f307vg INTERFACE)
target_include_directories(mbed-core
target_include_directories(mbed-gd32-f307vg
INTERFACE INTERFACE
TARGET_GD32F307VG TARGET_GD32F307VG
TARGET_GD32F307VG/device TARGET_GD32F307VG/device
) )
target_sources(mbed-core target_sources(mbed-gd32-f307vg
INTERFACE INTERFACE
TARGET_GD32F307VG/PeripheralPins.c TARGET_GD32F307VG/PeripheralPins.c
@ -22,17 +23,16 @@ if("GD32F307VG" IN_LIST MBED_TARGET_LABELS)
set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld) set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld)
set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S) set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S)
endif() endif()
endif()
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) add_library(mbed-gd32f30x INTERFACE)
target_include_directories(mbed-core target_include_directories(mbed-gd32f30x
INTERFACE INTERFACE
. .
GD32F30x_standard_peripheral/Include GD32F30x_standard_peripheral/Include
) )
target_sources(mbed-core target_sources(mbed-gd32f30x
INTERFACE INTERFACE
analogin_api.c analogin_api.c
analogout_api.c analogout_api.c
@ -77,3 +77,8 @@ target_sources(mbed-core
${STARTUP_FILE} ${STARTUP_FILE}
) )
mbed_set_linker_script(mbed-gd32f30x ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
target_link_libraries(mbed-gd32f30x INTERFACE mbed-gigadevice)
target_link_libraries(mbed-gd32-f307vg INTERFACE mbed-gd32f30x)

View File

@ -1,17 +1,17 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("GD32F450ZI" IN_LIST MBED_TARGET_LABELS) add_library(mbed-gd32-f450zi INTERFACE)
target_include_directories(mbed-core
target_include_directories(mbed-gd32-f450zi
INTERFACE INTERFACE
TARGET_GD32F450ZI TARGET_GD32F450ZI
) )
target_sources(mbed-core target_sources(mbed-gd32-f450zi
INTERFACE INTERFACE
TARGET_GD32F450ZI/PeripheralPins.c TARGET_GD32F450ZI/PeripheralPins.c
) )
endif()
if(${MBED_TOOLCHAIN} STREQUAL "ARM") if(${MBED_TOOLCHAIN} STREQUAL "ARM")
set(LINKER_FILE device/TOOLCHAIN_ARM_STD/gd32f450zi.sct) set(LINKER_FILE device/TOOLCHAIN_ARM_STD/gd32f450zi.sct)
@ -21,16 +21,16 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_gd32f450.S) set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_gd32f450.S)
endif() endif()
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) add_library(mbed-gd32f4xx INTERFACE)
target_include_directories(mbed-core target_include_directories(mbed-gd32f4xx
INTERFACE INTERFACE
. .
device device
GD32F4xx_standard_peripheral/Include GD32F4xx_standard_peripheral/Include
) )
target_sources(mbed-core target_sources(mbed-gd32f4xx
INTERFACE INTERFACE
analogin_api.c analogin_api.c
analogout_api.c analogout_api.c
@ -84,3 +84,8 @@ target_sources(mbed-core
${STARTUP_FILE} ${STARTUP_FILE}
) )
mbed_set_linker_script(mbed-gd32-f450zi ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
target_link_libraries(mbed-gd32f4xx INTERFACE mbed-gigadevice)
target_link_libraries(mbed-gd32-f450zi INTERFACE mbed-gd32f4xx)