You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/porting/target/cmake.md
+69-32Lines changed: 69 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -15,54 +15,83 @@ Note: All the CMake variables above are generated by mbed-tools and their values
15
15
16
16
## Mbed targets CMake input file structure
17
17
18
+
As we are still supporting Mbed CLI 1, we have maintained the directory naming scheme that use prefixes (`FEATURE_`, `COMPONENT_`, `TARGET_`).
19
+
20
+
Every Mbed CMake target should be prefixed with `mbed-`. Mbed boards listed in `targets.json` are translated in CMake to add the prefix and replace `_` with `-`. For example, the Mbed board `CYSBSYSKIT_01` is represented by the CMake target `mbed-cysbsyskit-01`.
21
+
18
22
### Vendor selection
19
23
20
-
Vendor selection is handled in [`targets/CMakeLists.txt`](https://github.com/ARMmbed/mbed-os/blob/master/targets/CMakeLists.txt) using a conditional statement to verify that one of the labels used by a given Mbed target matches a given partner directory. The matching directory is added to directories to build.
24
+
Vendor selection is handled in [`targets/CMakeLists.txt`](https://github.com/ARMmbed/mbed-os/blob/master/targets/CMakeLists.txt). A subdirectory is added to the build if one of the CMake targets it contains is referenced.
21
25
e.g
22
26
23
27
```
24
-
if("Cypress" IN_LIST MBED_TARGET_LABELS)
25
-
add_subdirectory(TARGET_Cypress)
26
-
endif()
28
+
add_subdirectory(TARGET_Cypress EXCLUDE_FROM_ALL)
27
29
```
28
-
Add an `elseif` conditional statement to add a vendor directory.
29
30
30
31
### MCU family targets
31
32
32
33
`targets/TARGET_<VENDOR_NAME>` usually contains different MCU or Mbed target families. The structure of the vendor directory is up to the vendor but it is preferable that it has logical separations.
33
34
For example, the content of `targets/TARGET_Cypress/TARGET_PSOC6` can be listed as follows:
# Add the include directories accessible from this directory that are not specific to an MCU family or Mbed target
53
-
target_include_directories(mbed-core
47
+
add_library(mbed-psoc6 INTERFACE)
48
+
49
+
# Add the include directories accessible from this directory that are specific to this MCU family or Mbed target
50
+
target_include_directories(mbed-psoc6
54
51
INTERFACE
55
52
...
56
53
)
57
54
58
-
# Add the source files accessible from this directory that are not specific to an MCU family or Mbed target
59
-
target_sources(mbed-core
55
+
# Add the source files accessible from this directory that are specific to this MCU family or Mbed target
56
+
target_sources(mbed-psoc6
60
57
INTERFACE
61
58
...
62
59
)
63
60
```
64
61
65
-
## Add target's CMakeLists.txt
62
+
The board CMake targets should link to `mbed-psoc6`:
63
+
64
+
```
65
+
add_library(mbed-cysbsyskit-01 INTERFACE)
66
+
67
+
target_include_directories(mbed-cysbsyskit-01
68
+
INTERFACE
69
+
...
70
+
)
71
+
72
+
target_sources(mbed-cysbsyskit-01
73
+
INTERFACE
74
+
...
75
+
)
76
+
# Other libraries that the Mbed board depends on
77
+
target_link_libraries(mbed-cysbsyskit-01
78
+
INTERFACE
79
+
mbed-cat1a
80
+
mbed-cysbsyskit-01-cm4
81
+
mbed-cysbsyskit-01-bsp-design-modus
82
+
mbed-psoc6
83
+
mbed-cy-psoc6-scl
84
+
)
85
+
86
+
target_compile_definitions(mbed-cysbsyskit-01
87
+
INTERFACE
88
+
"CY8C624AFNI_S2D43F"
89
+
)
90
+
91
+
mbed_post_build_psoc6_merge_hex("CYSBSYSKIT_01")
92
+
```
93
+
94
+
## Add Mbed board CMake input source file
66
95
67
96
Add `CMakeLists.txt` files to the top level directory of a given vendor directory. List all files found in the directory in this CMake input source file, adding additional CMake input source file if it is MCU or Mbed target specific and has a great number of files which will make the top level `CMakeLists.txt` too complex. Think when you decide to create functions in a computer software code to remove complexity.
68
97
@@ -74,17 +103,15 @@ A whole directory can be added to the build using `add_subdirectory()` if it is
@@ -97,17 +124,27 @@ Sources are listed using CMake's `target_sources()` function and added to the `m
97
124
98
125
### Linker script file
99
126
100
-
A global CMake property named `MBED_TARGET_LINKER_FILE` must be set for each linker file. This linker file must be listed with its absolute path, this is achieved by adding the sub-path obtained by the CMake variable `${CMAKE_CURRENT_SOURCE_DIR}`.
127
+
A function `mbed_set_linker_script` must be invoked for each linker file. The linker file must be listed with its absolute path, this is achieved by adding the sub-path obtained by the CMake variable `${CMAKE_CURRENT_SOURCE_DIR}`.
0 commit comments