From 33c35f791b5af4dd7f5af19aed5e558a32be803b Mon Sep 17 00:00:00 2001 From: Harrison Mutai Date: Fri, 12 Feb 2021 15:55:19 +0000 Subject: [PATCH] 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. --- targets/TARGET_GigaDevice/CMakeLists.txt | 11 ++--- .../TARGET_GD32F30X/CMakeLists.txt | 47 ++++++++++--------- .../TARGET_GD32F4XX/CMakeLists.txt | 31 +++++++----- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/targets/TARGET_GigaDevice/CMakeLists.txt b/targets/TARGET_GigaDevice/CMakeLists.txt index d5e58bffd7..254cec521d 100644 --- a/targets/TARGET_GigaDevice/CMakeLists.txt +++ b/targets/TARGET_GigaDevice/CMakeLists.txt @@ -1,13 +1,12 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if("GD32F30X" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_GD32F30X) -elseif("GD32F4XX" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_GD32F4XX) -endif() +add_subdirectory(TARGET_GD32F30X) +add_subdirectory(TARGET_GD32F4XX) -target_include_directories(mbed-core +add_library(mbed-gigadevice INTERFACE) + +target_include_directories(mbed-gigadevice INTERFACE . ) diff --git a/targets/TARGET_GigaDevice/TARGET_GD32F30X/CMakeLists.txt b/targets/TARGET_GigaDevice/TARGET_GD32F30X/CMakeLists.txt index 9969a267ee..9a83cd17a6 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32F30X/CMakeLists.txt +++ b/targets/TARGET_GigaDevice/TARGET_GD32F30X/CMakeLists.txt @@ -1,38 +1,38 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if("GD32F307VG" IN_LIST MBED_TARGET_LABELS) - target_include_directories(mbed-core - INTERFACE - TARGET_GD32F307VG - TARGET_GD32F307VG/device - ) +add_library(mbed-gd32-f307vg INTERFACE) - target_sources(mbed-core - INTERFACE - TARGET_GD32F307VG/PeripheralPins.c +target_include_directories(mbed-gd32-f307vg + INTERFACE + TARGET_GD32F307VG + TARGET_GD32F307VG/device +) - TARGET_GD32F307VG/device/system_gd32f30x.c - ) +target_sources(mbed-gd32-f307vg + INTERFACE + TARGET_GD32F307VG/PeripheralPins.c - if(${MBED_TOOLCHAIN} STREQUAL "ARM") - set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/gd32f307vg.sct) - set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/startup_gd32f30x_cl.S) - elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") - set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld) - set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S) - endif() + TARGET_GD32F307VG/device/system_gd32f30x.c +) + +if(${MBED_TOOLCHAIN} STREQUAL "ARM") + set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/gd32f307vg.sct) + set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_ARM_STD/startup_gd32f30x_cl.S) +elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") + set(LINKER_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/GD32F307xG.ld) + set(STARTUP_FILE TARGET_GD32F307VG/device/TOOLCHAIN_GCC_ARM/startup_gd32f30x_cl.S) 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 . GD32F30x_standard_peripheral/Include ) -target_sources(mbed-core +target_sources(mbed-gd32f30x INTERFACE analogin_api.c analogout_api.c @@ -77,3 +77,8 @@ target_sources(mbed-core ${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) diff --git a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/CMakeLists.txt b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/CMakeLists.txt index 9f83eb67e4..a8299468bb 100644 --- a/targets/TARGET_GigaDevice/TARGET_GD32F4XX/CMakeLists.txt +++ b/targets/TARGET_GigaDevice/TARGET_GD32F4XX/CMakeLists.txt @@ -1,17 +1,17 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if("GD32F450ZI" IN_LIST MBED_TARGET_LABELS) - target_include_directories(mbed-core - INTERFACE - TARGET_GD32F450ZI - ) +add_library(mbed-gd32-f450zi INTERFACE) - target_sources(mbed-core - INTERFACE - TARGET_GD32F450ZI/PeripheralPins.c - ) -endif() +target_include_directories(mbed-gd32-f450zi + INTERFACE + TARGET_GD32F450ZI +) + +target_sources(mbed-gd32-f450zi + INTERFACE + TARGET_GD32F450ZI/PeripheralPins.c +) if(${MBED_TOOLCHAIN} STREQUAL "ARM") 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) 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 . device GD32F4xx_standard_peripheral/Include ) -target_sources(mbed-core +target_sources(mbed-gd32f4xx INTERFACE analogin_api.c analogout_api.c @@ -84,3 +84,8 @@ target_sources(mbed-core ${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)