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
DISCO_L475VG_IOT01A
K64F
K66F
NRF52840_DK
NUCLEO_F303K8
NUCLEO_F401RE
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.
Hi,
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
3.5.0
(mbed) $ mbedtools clone mbed-os-example-blinky blinky
[...]
(mbed) $ cd blinky/mbed-os
(mbed) blinky/mbed-os$ git describe
mbed-os-6.5.0
(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:
/home/ddouard/perso/mbed/examples/blinky/mbed-os/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303x8/TARGET_NUCLEO_F303K8/system_clock.c
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 cmake.org) on a Debian bullseye machine, with arm-none-eabi-gcc from debian, aka version 8.3.1.
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 (Use - Build tools | Mbed OS 6 Documentation) 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).
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
if("STM32F302x8" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32F302x8)
elseif("STM32F303x8" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_TARGET_STM32F303x8)
elseif("STM32F303xC" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32F303xC)
elseif("STM32F303xE" IN_LIST MBED_TARGET_LABELS)
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?
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 @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.