From 9033d9b6320c4f8103da0d0da0808f7c8a074be3 Mon Sep 17 00:00:00 2001 From: Harrison Mutai Date: Tue, 9 Feb 2021 15:04:01 +0000 Subject: [PATCH] CMake: refactor Renesas targets Refactor all Renesas 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_RENESAS/CMakeLists.txt | 11 +++++------ .../TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt | 15 ++++++++------- .../TARGET_GR_LYCHEE/CMakeLists.txt | 9 ++++++--- .../TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt | 11 +++++++---- .../TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt | 12 +++++++----- .../TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt | 11 +++++++---- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/targets/TARGET_RENESAS/CMakeLists.txt b/targets/TARGET_RENESAS/CMakeLists.txt index 6a1854ad4b..b526fd3fe3 100644 --- a/targets/TARGET_RENESAS/CMakeLists.txt +++ b/targets/TARGET_RENESAS/CMakeLists.txt @@ -1,13 +1,12 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if ("RZ_A1XX" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_RZ_A1XX) -elseif("RZ_A2XX" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_RZ_A2XX) -endif() +add_subdirectory(TARGET_RZ_A1XX EXCLUDE_FROM_ALL) +add_subdirectory(TARGET_RZ_A2XX EXCLUDE_FROM_ALL) -target_include_directories(mbed-core +add_library(mbed-renesas INTERFACE) + +target_include_directories(mbed-renesas INTERFACE . ) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt index 1e4838420d..29472e227f 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt @@ -1,19 +1,18 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if ("GR_LYCHEE" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_GR_LYCHEE) -elseif("RZ_A1H" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_RZ_A1H) -endif() +add_subdirectory(TARGET_GR_LYCHEE EXCLUDE_FROM_ALL) +add_subdirectory(TARGET_RZ_A1H EXCLUDE_FROM_ALL) -target_include_directories(mbed-core +add_library(mbed-rz-a1xx INTERFACE) + +target_include_directories(mbed-rz-a1xx INTERFACE . common ) -target_sources(mbed-core +target_sources(mbed-rz-a1xx INTERFACE analogin_api.c can_api.c @@ -35,3 +34,5 @@ target_sources(mbed-core common/rza_io_regrw.c ) + +target_link_libraries(mbed-rz-a1xx INTERFACE mbed-renesas) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/CMakeLists.txt b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/CMakeLists.txt index 76d8377e6f..eb162ed851 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/CMakeLists.txt +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/CMakeLists.txt @@ -11,10 +11,10 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-gr-lychee INTERFACE) -target_include_directories(mbed-core +target_include_directories(mbed-gr-lychee INTERFACE . device @@ -23,7 +23,7 @@ target_include_directories(mbed-core device/inc/iodefines ) -target_sources(mbed-core +target_sources(mbed-gr-lychee INTERFACE trng_api_esp32.cpp PeripheralPins.c @@ -40,3 +40,6 @@ target_sources(mbed-core ${WEAK_HANDLER_FILE} ) +mbed_set_linker_script(mbed-gr-lychee ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-gr-lychee INTERFACE mbed-rz-a1xx) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt index e05e6ba7f3..7418562830 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt +++ b/targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt @@ -11,10 +11,9 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-rz-a1h INTERFACE) - -target_include_directories(mbed-core +target_include_directories(mbed-rz-a1h INTERFACE . device @@ -23,7 +22,7 @@ target_include_directories(mbed-core device/inc/iodefines ) -target_sources(mbed-core +target_sources(mbed-rz-a1h INTERFACE PeripheralPins.c @@ -38,3 +37,7 @@ target_sources(mbed-core ${STARTUP_FILE} ${WEAK_HANDLER_FILE} ) + +mbed_set_linker_script(mbed-rz-a1h ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-rz-a1h INTERFACE mbed-rz-a1xx) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt b/targets/TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt index 3793a26340..0a474ff845 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt +++ b/targets/TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt @@ -1,11 +1,11 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if ("GR_MANGO" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_GR_MANGO) -endif() +add_subdirectory(TARGET_GR_MANGO EXCLUDE_FROM_ALL) -target_include_directories(mbed-core +add_library(mbed-rz-a2xx INTERFACE) + +target_include_directories(mbed-rz-a2xx INTERFACE . common @@ -14,7 +14,7 @@ target_include_directories(mbed-core r_can/inc ) -target_sources(mbed-core +target_sources(mbed-rz-a2xx INTERFACE analogin_api.c can_api.c @@ -38,3 +38,5 @@ target_sources(mbed-core r_can/src/r_can_rz.c ) + +target_link_libraries(mbed-rz-a2xx INTERFACE mbed-renesas) diff --git a/targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt b/targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt index 8b040ad326..e1803c9e70 100644 --- a/targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt +++ b/targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt @@ -11,10 +11,9 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-gr-mango INTERFACE) - -target_include_directories(mbed-core +target_include_directories(mbed-gr-mango INTERFACE . device @@ -24,7 +23,7 @@ target_include_directories(mbed-core device/inc/iodefine/iodefines ) -target_sources(mbed-core +target_sources(mbed-gr-mango INTERFACE PeripheralPins.c @@ -40,3 +39,7 @@ target_sources(mbed-core ${STARTUP_FILE} ${WEAK_HANDLER_FILE} ) + +mbed_set_linker_script(mbed-gr-mango ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-gr-mango INTERFACE mbed-rz-a2xx)