Skip to content

Commit 7d17214

Browse files
committed
cmake design: update to the latest updates
Add requirements Fix cmake folder updates Fix label function Plus other small edits
1 parent f51723c commit 7d17214

File tree

1 file changed

+38
-43
lines changed

1 file changed

+38
-43
lines changed
Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,85 @@
11
# CMake Mbed OS
22

3+
Requirements:
4+
- CMake 3.13 and higher
5+
- mbed-tools (python 3.x)
6+
37
Two steps approach:
48

59
- Mbed OS core CMake
610
- Application CMake
711

8-
All what can be defined should be in CMake files and configuration (app/mbed .json files). Our build system would parse the configuration, create rules and generate top level CMake file that would include others (application CMake files plus also Mbed OS core CMake).
12+
All what can be defined should be in CMake files and configuration (app/mbed .json files). Our build system would parse the configuration and generate config CMake file.
913

1014
To stay backward compatible, we create common rules as follows.
1115

12-
We replace current `TOOLCHAIN_`, `FEATURE_`, `TARGET_` by providing `add_subdirectory` macros. There would be `if_target()`, `if_feature()`, `_if_toolchain()` macros for better readability.
13-
14-
Example, to add stm_directory only for STM targets (current rule TARGET_STM):
15-
16-
```
17-
add_subdirectory_if_target(STM stm_directory)
18-
19-
```
16+
We use target labels to include subfolders. The function goes through target labels and if there is a folder in the current CMake source directory, it includes it.
2017

21-
Application example:
18+
An example, to add `TARGET_STM` in the a folder `targets`:
2219

2320
```
24-
./TARGET_STM/qspi/driver_stm_qspi.cpp
25-
./TARGET_STM/peripheral_specific_to_stm/stm_specific_driver.cpp
26-
```
27-
28-
As result, the top level application CMake:
29-
30-
```
31-
add_subdirectory_if_target(STM TARGET_STM/qspi)
32-
add_subdirectory_if_target(STM TARGET_STM/peripheral_specific_to_stm)
33-
21+
mbed_add_cmake_directory_if_labels("TARGET")
3422
```
3523

36-
There would be static CMakes in the `./TARGET_STM/qspi/` and `./TARGET_STM/peripheral_specific_to_stm` that would define what files should be included or specific settins for these modules.
24+
The same could be applied to other labels like features or components.
3725

3826
To migrate to the new build system, we can provide auto scanning of the module and generate CMake based on what we find or use the way as described above. In both cases, we could stay backward compatible.
3927

4028
## Mbed OS Core (Mbed OS repository)
4129

4230
There are couple of CMakes in the tree.
4331

44-
1. Mbed OS boiler plate defined in Mbed OS root (provides way for build system to overwrite/add configuration)
45-
2. Mbed OS Toolchain settings (toolchain.cmake) that would get generated based on the toolchain selected
46-
3. Each module has own CMake (describing the module - what files are there, target/feature/component selection based on target, etc)
32+
1. The boiler plate for Mbed OS defined in Mbed OS root (provides way for the build system to overwrite/add configuration)
33+
1. Toolchain settings (toolchain.cmake) - configures the toolchain from cmake/toolchains directory based on the selected toolchain (`MBED_TOOLCHAIN`)
34+
1. Profile configuration (profile.cmake) - configures the profile from cmake/profiles directory based on the selected profile (`MBED_PROFILE`)
35+
1. Core configuration (core.cmake) - configures the core from cmake/cores directory based on the selected target (`MBED_CPU_CORE`)
36+
1. Utilities (util.cmake) - functions or macros we use
37+
1. Application cmake (app.cmake) - an application includes it to
38+
1. Each component has own CMake file (describing the component - what files are to include, target/feature/component selection based on target, etc)
4739

4840
The next sections will describe static CMake files within Mbed OS Core repository.
4941

5042
### 1. Boilerplate CMake
5143

52-
The main CMake file in Mbes OS repository provides just boilerplate for Mbed OS to be built. It described the Mbed OS tree, provides all the options we have in Mbed OS. This will be autogenerated by the tools.
44+
The main CMake file in Mbes OS repository provides just boilerplate for Mbed OS to be built. It described the Mbed OS tree, provides all the options we have in Mbed OS.
45+
46+
This is not intended to be included by an application.
5347

5448
### 2. Toolchain CMake
5549

56-
There are 3 toolchains, we provide the template that tools could fill in. The information is already in the build tools, we just need to extract that info and make it CMake compatible.
50+
All the toolchain settings are defined in cmake/toolchains cmake files.
5751

58-
This toolchain CMake is included by the Mbed OS CMake.
52+
### 3. Profile CMake
5953

60-
### 3. Module CMake
54+
The application profiles are defined in cmake/profiles.
6155

62-
This file statically defines the structure of the module within Mbed OS. It's conditionally config based. We use regular CMake expressions plus extend it with own macros to conditionally include/exclude directories. The thumb of the rule, do not expose headers that are internal. We would like to avoid having everything in the include paths as we do now.
56+
### 4. Core CMake
6357

58+
The core definitions are defined in cmake/cores.
6459

65-
`add_subdirectory` always adds the directory to the main CMake.
60+
### 5. Utilities
6661

67-
```
68-
add_subdirectory(drivers)
69-
```
62+
Functions or macros that we use within Mbed OS and might be useful for other as well.
63+
64+
### 6. Application CMake
7065

71-
Conditionally directories addition based on the config:
66+
This is the cmake that must be included by an application, using:
7267

7368
```
74-
add_subdirectory_if_config(CONFIG_REQUIRES_RTOS rtos)
69+
include(${MBED_ROOT}/cmake/app.cmake)
7570
```
7671

77-
Conditionally directories addition based on the target/toolchain/feature.
72+
### 7. Component CMake
7873

74+
This file statically defines the structure of the component within Mbed OS. It is conditionally config based. We use regular CMake expressions plus extend it with own macros to conditionally include/exclude directories. The thumb of the rule, do not expose headers that are internal. We would like to avoid having everything in the include paths as we do now.
75+
76+
77+
`add_subdirectory` always adds the directory to the main CMake.
7978

8079
```
81-
add_subdirectory_if_target(STM targets\TARGET_STM)
82-
add_subdirectory_if_toolchain(GCC_ARM cmsis\TARGET_GCC_ARM)
83-
add_subdirectory_if_feature(BLE ble\FEATURE_BLE)
80+
add_subdirectory(drivers)
8481
```
8582

86-
8783
## Application CMake
8884

8985
We should provide application CMake functionality with our own configuration. There are couple of approaches we could take. Statically defined CMake but then this disconnectes config and CMake - as CMake contains configuration for a project (like includes, sources, etc). Our build tool would need to parse CMake to get all paths used in the project or Mbed OS to find out where to look for configuration file. Therefore the build system has a knowledge as it is currently. We use `requires` to include/exclude modules.
@@ -96,6 +92,5 @@ A user create own CMake file to configure an application, also with `mbed_app.js
9692
2. Parse the application configuration
9793
3. Get the target configuration
9894
4. Get the Mbed OS configuration (select what modules we need and get their config, paths, etc)
99-
5. Create the toolchain.cmake file
100-
6. Inject all previous steps to the Mbed OS Core CMake
101-
7. Build an application
95+
5. Create .mbedbuild/mbed_config.cmake
96+
6. Build an application

0 commit comments

Comments
 (0)