Skip to content

Commit 8016a53

Browse files
rajkan01hugueskamba
authored andcommitted
CMake: replace usage of the mbed_add_cmake_directory_if_labels() function (#13754)
Directories that start with special prefixes (TARGET_, FEATURE_, COMPONENT_) are added to the build based on Mbed target configuration from targets.json instead of calling utility function mbed_add_cmake_directory_if_labels().
1 parent fa98689 commit 8016a53

File tree

22 files changed

+98
-56
lines changed

22 files changed

+98
-56
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ include(${MBED_ROOT}/tools/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
2222
enable_language(C CXX ASM)
2323

2424
include(${MBED_ROOT}/tools/cmake/core.cmake)
25-
include(${MBED_ROOT}/tools/cmake/util.cmake)
2625
include(${MBED_ROOT}/tools/cmake/profile.cmake)
2726

2827
add_library(mbed-os OBJECT)

cmsis/CMSIS_5/CMSIS/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
4+
if("CORTEX_A" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_CORTEX_A)
6+
elseif("CORTEX_M" IN_LIST MBED_TARGET_LABELS)
7+
add_subdirectory(TARGET_CORTEX_M)
8+
endif()
59

610
add_subdirectory(RTOS2)

docs/design-documents/tools/cmake.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ Two steps approach:
1111

1212
Definitions and configurations would be defined in CMake files, an Mbed app configuration file (`/path/to/app/mbed_app.json`) and Mbed library configuration files (`/path/to/mbed-os/<LIBRARY_NAME>/mbed_lib.json`). `mbed-tools` would parse the Mbed library and app configuration files and generate an `mbed_config.cmake` file.
1313

14-
The following rules must be respected for backward compatibility.
14+
The following rules must be respected to include special prefix directories (TARGET_, COMPONENT_ and FEATURE_).
1515

16-
Target labels, components, and features defined in `/path/to/mbed-os/targets/targets.json` are used to help the build system determine which directories contain sources/include files to use in the build process. This is accomplished through a custom CMake function (`mbed_add_cmake_directory_if_labels`) to append a prefix (TARGET_, COMPONENT_ and FEATURE_) and add matching directories to the list of directories to process.
16+
Target labels, components, and features defined in `/path/to/mbed-os/targets/targets.json` are used to help the build system determine which directories contain sources/include files to use in the build process.
1717

18-
An example, to add `TARGET_STM` in the folder `targets` where we have folders like TARGET_NXP, TARGET_STM, etc:
18+
This is a problem as labels, components and features directories will most likely be renamed and will not necessarily use the special prefixes TARGET_, COMPONENT_ and FEATURE_ respectively. Whenever such directories are encountered, check the directory name without the special prefix in the CMake list `MBED_TARGET_LABELS` generated by `mbed-tools` then include the subdirectory to the build process if found.
1919

20-
```
21-
mbed_add_cmake_directory_if_labels("TARGET")
22-
```
20+
For example when the user builds for the `NUCLEO_F411RE` Mbed target, `mbed-tools` includes the `STM` label to the `MBED_TARGET_LABELS` list. `TARGET_STM` can only be added to the list of build directories as shown below:
2321

24-
If a user selects for example target `NUCLEO_F411RE`, the target defines the label `STM`. As result, the target folder STM is included.
22+
```
23+
# CMake input source file: mbed-os/targets/CMakeList.txt
2524
25+
if("STM" IN_LIST MBED_TARGET_LABELS)
26+
add_subdirectory(TARGET_STM)
27+
endif()
28+
```
2629
The same could be applied to other labels like features or components.
2730

2831
## Mbed OS Core (Mbed OS repository)
@@ -36,7 +39,6 @@ A number of CMake scripts are contained in the `mbed-os/tools/cmake` directory:
3639
* `core.cmake` - selects the core script from the `cmake/cores` directory, based on the value of the `MBED_CPU_CORE` variable
3740
* `profile.cmake` - selects the profile script from the `cmake/profiles` directory, based on the value of the `MBED_PROFILE` variable
3841
* `toolchain.cmake` - selects the toolchain script from the `cmake/toolchains` directory, based on the value of the `MBED_TOOLCHAIN` variable
39-
* `util.cmake` - custom CMake helper functions and macros
4042

4143
The next sections will describe static CMake files within Mbed OS Core repository.
4244

@@ -64,7 +66,7 @@ Custom functions/macros used within Mbed OS.
6466

6567
### 7. Component `CMakeLists.txt` Entry Point
6668

67-
This file statically defines the build specification of an Mbed OS component. It contains conditional statements that depend on the configuration parameters generated by `mbed-tools`. The component entry points make use of functions/macros defined in `util.cmake` to conditionally include or exclude directories.
69+
This file statically defines the build specification of an Mbed OS component. It contains conditional statements that depend on the configuration parameters generated by `mbed-tools`.
6870
The rule of thumb is to not expose header files that are internal. We would like to avoid having everything in the include paths as we do now.
6971

7072
## Building an Application

hal/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
4+
if("FLASH_CMSIS_ALGO" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_FLASH_CMSIS_ALGO)
6+
endif()
57

68
add_subdirectory(usb)
79

hal/usb/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
5-
64
target_include_directories(mbed-os
75
PUBLIC
86
include

targets/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
4+
if("Freescale" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_Freescale)
6+
elseif("NORDIC" IN_LIST MBED_TARGET_LABELS)
7+
add_subdirectory(TARGET_NORDIC)
8+
elseif("STM" IN_LIST MBED_TARGET_LABELS)
9+
add_subdirectory(TARGET_STM)
10+
endif()

targets/TARGET_Freescale/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
4+
if("MCUXpresso_MCUS" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_MCUXpresso_MCUS)
6+
endif()
57

68
target_include_directories(mbed-os
79
PUBLIC

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/CMakeLists.txt

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

4+
if("K66F" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_K66F)
6+
elseif("MCU_K64F" IN_LIST MBED_TARGET_LABELS)
7+
add_subdirectory(TARGET_MCU_K64F)
8+
endif()
9+
410
target_sources(mbed-os
511
PRIVATE
612
fsl_common.c
@@ -24,5 +30,3 @@ target_include_directories(mbed-os
2430
PUBLIC
2531
api
2632
)
27-
28-
mbed_add_cmake_directory_if_labels("TARGET")

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_K66F/CMakeLists.txt

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

4-
mbed_add_cmake_directory_if_labels("TARGET")
4+
if("FRDM" IN_LIST MBED_TARGET_LABELS)
5+
add_subdirectory(TARGET_FRDM)
6+
endif()
57

68
add_subdirectory(device)
79

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
add_subdirectory(device)
44

5-
mbed_add_cmake_directory_if_labels("TARGET")
5+
if("FRDM" IN_LIST MBED_TARGET_LABELS)
6+
add_subdirectory(TARGET_FRDM)
7+
elseif("HEXIWEAR" IN_LIST MBED_TARGET_LABELS)
8+
add_subdirectory(TARGET_HEXIWEAR)
9+
elseif("SDT64B" IN_LIST MBED_TARGET_LABELS)
10+
add_subdirectory(TARGET_SDT64B)
11+
endif()
612

713
target_sources(mbed-os
814
PRIVATE

0 commit comments

Comments
 (0)