Arm Mbed OS support forum

CMake is now part of Mbed OS

Since we introduced the new Mbed Tools in August, we made progress with CMake to decrease building time of Mbed OS. CMake is part of Mbed OS master branch for all of you to try and provide feedback.

CMake and the new Mbed Tools are under active development. We will be adding additional targets and features to our CMake support in the following weeks.

We recommend using the latest Mbed Tools and CMake as they contain important bugfixes.

Mbed OS libraries

Application project executables can be linked with one of two main libraries mbed-os or mbed-baremetal and optional mbed- prefixed libraries depending on the additional features required by an application.

Targets supported

  • K64F
  • K66F
  • NRF52840_DK
  • NUCLEO_F303K8
  • WIO_3G

Toolchains supported

GCC Arm and ARMClang are supported.

Examples supported

Supported examples can be identified by the presence of a top level CMakeLists.txt input source file on the example’s development branch.

Additional details

For more details, please read the CMake support README and Mbed Tools how-to README.

We will add detailed public documentation soon.


That’s great news, thanks @Kojto for sharing that!

Quick question: what about bootloader and Pelion compatibility?

This is one of our upcoming tasks to look at the bootloader.


Good to hear! Thanks :slight_smile:

I am trying to play with the new build system, but I can’t make it work.

I have installed mbed-tools From a python (3.8) virtual environment and cloned the blinky examples:

(mbed) $ mbedtools --version
(mbed) $ mbedtools clone mbed-os-example-blinky blinky
(mbed) $ cd blinky/mbed-os
(mbed) blinky/mbed-os$ git describe
(mbed) blinky/mbed-os$ cd ..
(mbed) blinky$ mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
-- Configuring done
CMake Error at CMakeLists.txt:14 (add_executable):
  Cannot find source file:


  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
ERROR: CMake invocation failed!

More information may be available by using the command line option '-v'.

I’ve tested with several other nucleo targets an I get similar results (not always the same file that cannot be found however).

The cloned version of the blinky example is at revision 2a95fcd8 (aka tagged version for mbed 6.5.0) and I’m using cmake 3.19.1 (downloaded from on a Debian bullseye machine, with arm-none-eabi-gcc from debian, aka version 8.3.1.

Did I miss something?

Ok the list of supported targets is a bit confusing. According to the top level message, the NUCLEO_F303K8 is expected to be supported, but the doc ( only lists 3 supported boards ( K64F , DISCO_L475VG_IOT01A and NRF52840_DK ).

And indeed the compilation work perfectly with the K64F target (and as expected is waaaay faster than the cli v1 build system).

STM targets are now available in master, but not in 6.5.0.

Cool. Seems there is a bug in targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt:

 mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
CMake Error at mbed-os/targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt:7 (add_subdirectory):
  add_subdirectory given source "TARGET_TARGET_STM32F303x8" which is not an
  existing directory.

(using mbed-os g6d89500dfe)

and sure enough:

head -n 10 mbed-os/targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt 
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0


seems a bit “odd” :slight_smile:

Ahh much better (with a fixed TARGET_STM32F3/CMakeLists.txt):

mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ddouard/perso/mbed/examples/blinky/cmake_build
Building Mbed project...
[228/228] Linking CXX executable mbed-os-example-blinky
-- built: /home/ddouard/perso/mbed/examples/blinky/cmake_build/mbed-os-example-blinky.bin
-- built: /home/ddouard/perso/mbed/examples/blinky/cmake_build/mbed-os-example-blinky.hex
| Module           |         .text |     .data |        .bss |
| [fill]           |       48(+48) |     0(+0) |     15(+15) |
| [lib]/c_nano.a   |   3724(+3724) | 100(+100) |     12(+12) |
| [lib]/gcc.a      |     772(+772) |     0(+0) |       0(+0) |
| [lib]/misc       |     248(+248) |     4(+4) |     28(+28) |
| main.cpp.obj     |       48(+48) |     0(+0) |       0(+0) |
| mbed-os/cmsis    |   6580(+6580) | 168(+168) | 5953(+5953) |
| mbed-os/drivers  |       70(+70) |     0(+0) |       0(+0) |
| mbed-os/hal      |   1348(+1348) |     4(+4) |     66(+66) |
| mbed-os/platform |   4274(+4274) | 260(+260) |   348(+348) |
| mbed-os/rtos     |       28(+28) |     0(+0) |       0(+0) |
| mbed-os/targets  |   6832(+6832) |     8(+8) |   522(+522) |
| Subtotals        | 23972(+23972) | 544(+544) | 6944(+6944) |
Total Static RAM memory (data + bss): 7488(+7488) bytes
Total Flash memory (text + data): 24516(+24516) bytes

If the issue is present in master on mbed-os, you can raise an issue on github or make a PR with a fix, the team will greatly appreciate it :slight_smile:

ok ok, here it is :slight_smile:


Thanks @douardda. We will integrate the fix asap. If you find anything else, create an issue or pull request (much appreciated).

Just curious since the mbed tools are in master, I am wondering if there is a way to utilize the CMake build system pre mbed-os-6 ? My application is currently built using mbed-os-5.15.5 with mbed-cli and I would like to stay at this version of mbed os.

Also I was told that the binaries built using the new CMake Build mechanism results in smaller binaries than MBED-CLI, Is this statement accurate?


Hi @ajayk,

we won’t port CMake to 5.15 but you can use it if you port it. You might update some CMakes as the structure of files is different.

Smaller binaries could be achieved also if you use .mbedignore and just remove what you do not use. We use the same compiler flags, so it’s just matter of what is added and what linker is capable of stripping.

By the way, if you’re OK with a 3rd party option, mbed-cmake should be compatible with Mbed 5.15; all you need to do is set it up and then replace the Mbed source code directory with the 5.15 source.

Thanks Jamie for sharing mbed-cmake, I completely forgot to mention it.

Thanks @Kojto and @MultipleMonomials for taking the time to respond. I will give your suggestions a shot and see if I can get CMake or mbed-cmake to work for pre mbed-os 6.