From 128224269140ec0390f7902e21f360f2987d6dce Mon Sep 17 00:00:00 2001 From: Harrison Mutai Date: Fri, 12 Feb 2021 11:11:31 +0000 Subject: [PATCH] CMake: refactor Samsung targets Refactor all Samsung 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_Samsung/CMakeLists.txt | 8 +++----- .../TARGET_Samsung/TARGET_SIDK_S1SBP6A/CMakeLists.txt | 8 +++++--- .../TARGET_Samsung/TARGET_SIDK_S5JS100/CMakeLists.txt | 10 +++++++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/targets/TARGET_Samsung/CMakeLists.txt b/targets/TARGET_Samsung/CMakeLists.txt index 4a93bfe1dd..b7964d2c63 100644 --- a/targets/TARGET_Samsung/CMakeLists.txt +++ b/targets/TARGET_Samsung/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -if("SIDK_S1SBP6A" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_SIDK_S1SBP6A) -elseif("SIDK_S5JS100" IN_LIST MBED_TARGET_LABELS) - add_subdirectory(TARGET_SIDK_S5JS100) -endif() +add_subdirectory(TARGET_SIDK_S1SBP6A EXCLUDE_FROM_ALL) +add_subdirectory(TARGET_SIDK_S5JS100 EXCLUDE_FROM_ALL) + diff --git a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/CMakeLists.txt b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/CMakeLists.txt index d4cc5de3fb..feeac9544c 100644 --- a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/CMakeLists.txt +++ b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/CMakeLists.txt @@ -9,15 +9,15 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_s1sbp6a.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-s1sbp6a INTERFACE) -target_include_directories(mbed-core +target_include_directories(mbed-s1sbp6a INTERFACE . device ) -target_sources(mbed-core +target_sources(mbed-s1sbp6a INTERFACE PeripheralPins.c flash_api.c @@ -42,3 +42,5 @@ target_sources(mbed-core ${STARTUP_FILE} ) + +mbed_set_linker_script(mbed-s1sbp6a ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) diff --git a/targets/TARGET_Samsung/TARGET_SIDK_S5JS100/CMakeLists.txt b/targets/TARGET_Samsung/TARGET_SIDK_S5JS100/CMakeLists.txt index 929a500ac5..67b64c1dcb 100644 --- a/targets/TARGET_Samsung/TARGET_SIDK_S5JS100/CMakeLists.txt +++ b/targets/TARGET_Samsung/TARGET_SIDK_S5JS100/CMakeLists.txt @@ -9,9 +9,9 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(STARTUP_FILE device/TOOLCHAIN_GCC_ARM/startup_sidk_s5js100.S) endif() -set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) +add_library(mbed-s5js100 INTERFACE) -target_include_directories(mbed-core +target_include_directories(mbed-s5js100 INTERFACE . device @@ -20,7 +20,7 @@ target_include_directories(mbed-core security_subsystem/drivers ) -target_sources(mbed-core +target_sources(mbed-s5js100 INTERFACE gpio_api.c gpio_irq_api.c @@ -61,3 +61,7 @@ target_sources(mbed-core ${STARTUP_FILE} ) + +mbed_set_linker_script(mbed-s5js100 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) + +target_link_libraries(mbed-s5js100)