|
| 1 | +CMake projects may be integrated in various IDEs. |
| 2 | + |
| 3 | +Some IDEs sport a CMake plug-in, notably VScode. |
| 4 | +This is the easy case -- please refer to the documentation of the relevant plug-in. |
| 5 | + |
| 6 | +Unfortunately, ST's Cube IDE does not have such a plug-in. A procedure to handle CMake projects nonetheless, |
| 7 | +using its built-in support for Makefiles, is detailed below. |
| 8 | + |
| 9 | +# Requirements |
| 10 | + |
| 11 | +The same requirements as detailed in the [[Setup]] page for shell users apply. |
| 12 | + |
| 13 | +# Walkthrough |
| 14 | + |
| 15 | +The first step is to create or import a __"Makefile Project with Existing Code"__: |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +----------------- |
| 20 | + |
| 21 | +Then browse for the project's location, and leave all other settings to default as illustrated below: |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +----------------- |
| 26 | + |
| 27 | +The next step is to fill in the build settings. |
| 28 | +Right click on the project, hit "Properties" (or `Alt`+`Enter`), then go to the "C/C++ build" section. |
| 29 | +Fill in the "Builder Settings" and "Behavior" tabs as follows |
| 30 | +(be sure to replace the build location with the relevant value for your project). |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +You may also change the build command to "ninja"; this is known to be much more efficient, in terms of build time, than Make. |
| 36 | + |
| 37 | +----------------- |
| 38 | + |
| 39 | +Once this is done, there remains to tell CubeIDE how to run CMake. |
| 40 | +Right click on the project, hit "Build targets" -> "Create" (or `Shift`+`F9`, "Add"). |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +Fill the window that pops up as follows: |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +Build command : |
| 49 | +```sh |
| 50 | +# if you stuck with Make in the previous step |
| 51 | +cmake -S [source folder] -B [build folder] -G Unix\ Makefiles |
| 52 | + |
| 53 | +# or, if you picked Ninja earlier, |
| 54 | +cmake -S [source folder] -B [build folder] -G Ninja |
| 55 | +``` |
| 56 | + |
| 57 | +For the source and build folder, you can use one of Cube's automatic variables, such as `${workspace_loc:/1_Blink}/build`, as in the project settings. |
| 58 | +Make sure the build folder (`-B`) matches the value you passed in the project build configuration step! |
| 59 | + |
| 60 | +----------------- |
| 61 | + |
| 62 | +Now, all the configuration steps are done. |
| 63 | + |
| 64 | +To run CMake, build the target you created in the previous step (or hit `F9`): |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +To or rebuild the project, hit `Ctrl`+`B`, or right-click on the project -> "Build project". |
| 69 | + |
| 70 | + |
0 commit comments