Skip to content

Commit 9033d9b

Browse files
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.
1 parent aa561ee commit 9033d9b

File tree

6 files changed

+40
-29
lines changed

6 files changed

+40
-29
lines changed

targets/TARGET_RENESAS/CMakeLists.txt

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 ("RZ_A1XX" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_RZ_A1XX)
6-
elseif("RZ_A2XX" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_RZ_A2XX)
8-
endif()
4+
add_subdirectory(TARGET_RZ_A1XX EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_RZ_A2XX EXCLUDE_FROM_ALL)
96

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

targets/TARGET_RENESAS/TARGET_RZ_A1XX/CMakeLists.txt

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

4-
if ("GR_LYCHEE" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_GR_LYCHEE)
6-
elseif("RZ_A1H" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_RZ_A1H)
8-
endif()
4+
add_subdirectory(TARGET_GR_LYCHEE EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_RZ_A1H EXCLUDE_FROM_ALL)
96

10-
target_include_directories(mbed-core
7+
add_library(mbed-rz-a1xx INTERFACE)
8+
9+
target_include_directories(mbed-rz-a1xx
1110
INTERFACE
1211
.
1312
common
1413
)
1514

16-
target_sources(mbed-core
15+
target_sources(mbed-rz-a1xx
1716
INTERFACE
1817
analogin_api.c
1918
can_api.c
@@ -35,3 +34,5 @@ target_sources(mbed-core
3534

3635
common/rza_io_regrw.c
3736
)
37+
38+
target_link_libraries(mbed-rz-a1xx INTERFACE mbed-renesas)

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_GR_LYCHEE/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
1111
set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S)
1212
endif()
1313

14-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(mbed-gr-lychee INTERFACE)
1515

1616

17-
target_include_directories(mbed-core
17+
target_include_directories(mbed-gr-lychee
1818
INTERFACE
1919
.
2020
device
@@ -23,7 +23,7 @@ target_include_directories(mbed-core
2323
device/inc/iodefines
2424
)
2525

26-
target_sources(mbed-core
26+
target_sources(mbed-gr-lychee
2727
INTERFACE
2828
trng_api_esp32.cpp
2929
PeripheralPins.c
@@ -40,3 +40,6 @@ target_sources(mbed-core
4040
${WEAK_HANDLER_FILE}
4141
)
4242

43+
mbed_set_linker_script(mbed-gr-lychee ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
44+
45+
target_link_libraries(mbed-gr-lychee INTERFACE mbed-rz-a1xx)

targets/TARGET_RENESAS/TARGET_RZ_A1XX/TARGET_RZ_A1H/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
1111
set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S)
1212
endif()
1313

14-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(mbed-rz-a1h INTERFACE)
1515

16-
17-
target_include_directories(mbed-core
16+
target_include_directories(mbed-rz-a1h
1817
INTERFACE
1918
.
2019
device
@@ -23,7 +22,7 @@ target_include_directories(mbed-core
2322
device/inc/iodefines
2423
)
2524

26-
target_sources(mbed-core
25+
target_sources(mbed-rz-a1h
2726
INTERFACE
2827
PeripheralPins.c
2928

@@ -38,3 +37,7 @@ target_sources(mbed-core
3837
${STARTUP_FILE}
3938
${WEAK_HANDLER_FILE}
4039
)
40+
41+
mbed_set_linker_script(mbed-rz-a1h ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
42+
43+
target_link_libraries(mbed-rz-a1h INTERFACE mbed-rz-a1xx)

targets/TARGET_RENESAS/TARGET_RZ_A2XX/CMakeLists.txt

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

4-
if ("GR_MANGO" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_GR_MANGO)
6-
endif()
4+
add_subdirectory(TARGET_GR_MANGO EXCLUDE_FROM_ALL)
75

8-
target_include_directories(mbed-core
6+
add_library(mbed-rz-a2xx INTERFACE)
7+
8+
target_include_directories(mbed-rz-a2xx
99
INTERFACE
1010
.
1111
common
@@ -14,7 +14,7 @@ target_include_directories(mbed-core
1414
r_can/inc
1515
)
1616

17-
target_sources(mbed-core
17+
target_sources(mbed-rz-a2xx
1818
INTERFACE
1919
analogin_api.c
2020
can_api.c
@@ -38,3 +38,5 @@ target_sources(mbed-core
3838

3939
r_can/src/r_can_rz.c
4040
)
41+
42+
target_link_libraries(mbed-rz-a2xx INTERFACE mbed-renesas)

targets/TARGET_RENESAS/TARGET_RZ_A2XX/TARGET_GR_MANGO/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
1111
set(WEAK_HANDLER_FILE device/TOOLCHAIN_GCC_ARM/weak_handler.S)
1212
endif()
1313

14-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(mbed-gr-mango INTERFACE)
1515

16-
17-
target_include_directories(mbed-core
16+
target_include_directories(mbed-gr-mango
1817
INTERFACE
1918
.
2019
device
@@ -24,7 +23,7 @@ target_include_directories(mbed-core
2423
device/inc/iodefine/iodefines
2524
)
2625

27-
target_sources(mbed-core
26+
target_sources(mbed-gr-mango
2827
INTERFACE
2928
PeripheralPins.c
3029

@@ -40,3 +39,7 @@ target_sources(mbed-core
4039
${STARTUP_FILE}
4140
${WEAK_HANDLER_FILE}
4241
)
42+
43+
mbed_set_linker_script(mbed-gr-mango ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
44+
45+
target_link_libraries(mbed-gr-mango INTERFACE mbed-rz-a2xx)

0 commit comments

Comments
 (0)