Skip to content

Commit 8f910ff

Browse files
committed
doc: add a CMake README file
1 parent fa1d5db commit 8f910ff

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Diff for: README_CMAKE.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
CMake can now be used to build Arduino sketches with this core.
2+
Examples of use can be found on [this repo](https://github.com/massonal/STM32CMake_workspace).
3+
4+
# Prerequisites
5+
6+
- CMake version >= 3.21
7+
- Python3 version >= 3.9
8+
- `make` / `ninja` (prefer `ninja`)
9+
- graphviz layout engines: `dot`, `sfdp` (optional)
10+
- Python modules: `graphviz`, `jinja2`; install them with `pip install ...`
11+
12+
Some additional dependencies (toolchain...) will be downloaded on the first build.
13+
14+
If your system does not provide a recent enough version of CMake, a suitable version may be installed with [`pip`](https://pypi.org/): `pip install cmake`.
15+
16+
# Usage
17+
18+
This section will describe the process of building a sketch "by hand", with a system shell. Other methods, such as with an IDE plug-in, may require adaptations.
19+
20+
Please see [STM32CMake_workspace](https://github.com/massonal/STM32CMake_workspace) for some quick examples; more may be added over time.
21+
22+
First of all, there has to be a CMakeLists.txt in the sketch folder.
23+
24+
- easy way: fire `cmake/scripts/cmake_easy_setup.py -b <board> -s <sketch folder>` (this requires arduino-cli and jinja)
25+
- advanced way: write your own by adapting from an example
26+
27+
--------
28+
29+
__Board name__: either through the script or directly in the CMakeLists.txt, the board name is the identifier found in boards.txt. (Yes, CMake is made aware of boards.txt/platform.txt.)
30+
In the following example, the value to retain would be "NUCLEO_F207ZG" (the part after "menu.pnum."):
31+
```
32+
# NUCLEO_F207ZG board
33+
Nucleo_144.menu.pnum.NUCLEO_F207ZG=Nucleo F207ZG
34+
Nucleo_144.menu.pnum.NUCLEO_F207ZG.node=NODE_F207ZG
35+
```
36+
37+
--------
38+
39+
Then CMake can be run to launch the configuration step. This is only needed on the very first time, at the beginning of the project.
40+
```sh
41+
cmake -S [sketch folder] -B [build folder] -G Ninja # "-G Ninja" -> generate ninja files (default = make)
42+
```
43+
The build folder is conventionally located at the root of the sketch folder and named `build`, e.g. :
44+
```
45+
.
46+
|-- Blink/
47+
| |-- Blink.ino
48+
| |-- CMakeLists.txt
49+
| `-- build/
50+
```
51+
52+
Finally, the sketch can be (re-)built with `cmake --build <build folder>`.
53+
This can also be done by invoking the build tool (usually `make` or `ninja`) directly from the build folder.
54+
**This last step is the only one needed in order to rebuild the project, even if some source files, or even the CMakeLists.txt, have changed.**
55+
56+
For more details on how to use CMake, please read the CMake [User Interaction Guide](https://cmake.org/cmake/help/v3.21/guide/user-interaction/index.html).
57+
58+
The official [CMake tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html) may also be useful for users looking to understand all the implementation details.
59+
60+
# Caveats
61+
62+
- The CMake build model makes it hard to auto-detect dependencies between the sketch and the Arduino libraries, and between Arduino libraries. Thus, you have to specify them manually; see the examples to see how.
63+
- Uploading the binaries to the board is not implemented; this step is up to you, using the appropriate tool. If your board supports the "mass storage" method, you can simply copy the .bin file to your board drive in the file explorer.

0 commit comments

Comments
 (0)