Building STM core/sketches with cmake

Post Reply
ag123
Posts: 1883
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Building STM core/sketches with cmake

Post by ag123 »

The relevant links / pages:
viewtopic.php?t=1648
https://github.com/stm32duino/Arduino_C ... E_CMAKE.md
https://github.com/stm32duino/Arduino_C ... esentation
https://github.com/stm32duino/CMake_workspace

there are some prerequisites to install, most important CMake, python (and some python modules), ninja
https://github.com/stm32duino/Arduino_C ... wiki/Setup

after prerequisites are installed, is to run the quick start script from the *parent* (above sketch) folder of the sketch to generate a CMakeList.txt file in the sketch folder
https://github.com/stm32duino/Arduino_C ... art-script
e.g. where [ARDUINO_CORE_STM32_FOLDER] is where you git clone the Arduino_Core_STM32 repo

Code: Select all

python3 [ARDUINO_CORE_STM32_FOLDER]/cmake/scripts/cmake_easy_setup.py --board BLACKPILL_F401CC --sketch sketch_folder
edit the generated CMakeList.txt file in the sketch folder to see that all your sketch sources are listed under the build_sketch() section.

then the build steps are, make a directory e.g. build (this is for CMake to generate it's work scripts / files and build, the bin file is found there after the build)
https://github.com/stm32duino/Arduino_C ... sing-cmake

Code: Select all

cmake -S [source folder] -B [build folder] -G Ninja
then to actually compile it is

Code: Select all

cmake --build [build folder]
There is quite a bit of convenience to use Cmake with eclipse, Eclipse CDT has features that support Cmake. And without any custom add-on in eclipse, i.e. CDT is adequate. And that Cmake is (far) more fluid vs Arduino IDE which pre-defines files in certain locations (it is a good and bad thing).

CMake is a built tool and it doesn't require an IDE. The use of an IDE is optional with this.
fpiSTM
Posts: 1920
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 107
Location: Le Mans
Contact:

Re: Building STM core/sketches with cmake

Post by fpiSTM »

Note than a CMake projec tcan be loaded with STM32CubeIDE.
Post Reply

Return to “Forum rules, FAQs and HowTo's”