|
| 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 `scripts/cmake_easy_setup.py -b <board> -s <sketch folder>` (this requires jinja) |
| 25 | +- advanced way: write your own by adapting from an example |
| 26 | + |
| 27 | +__Board name__: either through the script or directly in the CMakeLists.txt, the board name is the identifier found in boards.txt: e.g., "GENERIC_F401RDTX", not "Generic F401RDTx". (Yes, CMake is made aware of boards.txt/platform.txt.) |
| 28 | + |
| 29 | +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. |
| 30 | +``` |
| 31 | +cmake -S <sketch folder> -B <build folder> |
| 32 | +``` |
| 33 | +The build folder is conventionally located at the root of the sketch folder and named `build`, e.g. : |
| 34 | +``` |
| 35 | +. |
| 36 | +|-- Blink/ |
| 37 | +| |-- Blink.ino |
| 38 | +| |-- CMakeLists.txt |
| 39 | +| `-- build/ |
| 40 | +``` |
| 41 | + |
| 42 | +Finally, the sketch can be (re-)built with `cmake --build <build folder>`. |
| 43 | +This can also be done by invoking the build tool (usually `make` or `ninja`) directly from the build folder. |
| 44 | +**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.** |
| 45 | + |
| 46 | +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). |
| 47 | + |
| 48 | +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. |
| 49 | + |
| 50 | +# Caveats |
| 51 | + |
| 52 | +- 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. |
| 53 | +- 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