mbed-os/tools/cmake
Martin Kojtal db35bbdc43 CMake ble: remove component add function, use regular variable
use MBED_<library>_EXTRA_LIBRARIES variables we provide
2021-03-15 10:06:07 +00:00
..
cores CMake: Fix Cortex-A9 flags for GCC_ARM toolchain 2021-03-12 13:21:04 +00:00
profiles Fix variable name conflict with toolchain file 2020-12-03 10:58:41 -08:00
toolchains Configure memory map per target to allow multiple add_executable 2021-02-27 13:16:03 +01:00
CheckPythonPackage.cmake Whitespace formatting changes. 2021-02-03 14:12:29 -08:00
README.md CMake readme: split the table to user-facing and internal libs 2021-03-15 10:05:58 +00:00
app.cmake Rebase against master 2021-02-03 14:16:07 -08:00
mbed_greentea.cmake CMake: Fix Greentea tests 2021-02-23 13:08:43 +00:00
mbed_set_post_build.cmake CMake: Refactor post-build hook to remove APP_TARGET references 2021-02-19 11:52:57 +00:00
profile.cmake CMake: Rename Mbed OS path variable for consistency 2020-11-06 17:25:23 +00:00
requirements.txt Add intelhex version info (same as #14201) 2021-02-03 14:12:29 -08:00
set_linker_script.cmake CMake linker: fix change from the latest rebase 2021-03-15 10:05:53 +00:00
toolchain.cmake CMake: Generate response file before adding mbed-targets 2021-02-15 11:12:18 +00:00

README.md

CMake for Mbed OS

In order to replace the traditional Mbed tools, we are adding CMake support to allow the generation of build systems instructions to build Mbed OS as a library.

This is still at the experimental stage and still in development. It does not yet completely replace our current build tools. If you find a bug, please report it or raise a pull request as contributions are welcome!

Mbed OS is built as collection of all core libraries. Application project executables can be linked with the mbed-os library (which includes the core libraries of Mbed OS) and optional mbed-os- prefixed libraries depending on the additional features required by the projects and supported by the Mbed target.

The list of optional libraries for each component can be seen in the CMake input source file at the root of each component directory.

The following features are not yet supported and will be progressively added:

  • Application profile selection (bare metal)
  • Features that require altering compiler/linker command line options (except for printf library and C selections)

The full profile with the selected printf and C libraries.

Supported targets

Only a limited set of targets is supported at the moment.

The following targets are supported:

  • Ambiq Micro targets
  • Analog Devices targets
  • ARM FM targets
  • ARM SSG targets
  • Cypress targets
  • Freescale targets
  • GigaDevice targets
  • MAXIM targets
  • Nordic targets
  • NXP targets
  • Renesas targets
  • Samsung targets
  • Silicon Labs targets
  • STM targets
  • Toshiba targets

The post build operations are supported for the following Mbed boards: LPC1114, LPC1768, ARCH_PRO, LPC54114, LPC546XX, FF_LPC546XX, CY8CKIT064B0S2_4343W, CYTFM_064B0S2_4343W, CYSBSYSKIT_01, ARM_MUSCA_B1, ARM_MUSCA_S1.

Supported toolchains

Arm Compiler 6 and GNU Arm Embedded toolchains are supported.

Examples

Supported examples can be identified by the presence of a top level CMakeLists.txt input source file.

Known issues

How to build an application

Prerequisities:

From the application root or wherever mbed-os.lib is found, run the following command to:

  • create the Mbed OS configuration CMake module

  • create a build directory

  • generate the project configuration

  • build the project using the Ninja build system

    mbedtools compile -m <mbed-target> -t <toolchain>
    

CMAKE_BUILD_TYPE can overridden with Mbed specific values: Develop (default value), Release and Debug.

mbed-tools will pass -DCMAKE_BUILD_TYPE=<supported-build-type> for you when using the --build-type optional argument of the build subcommand as follows:

mbedtools compile -m <mbed-target> -t <toolchain> -b <supported-build-type>

If you're running CMake directly, you may need to pass it in yourself as follows:

cmake -S <source-dir> -B <build-dir> -DCMAKE_BUILD_TYPE=debug

How to build a greentea test

Install prerequisites suggested in the previous section and follow the below steps to build:

  • Set your current directory to the test suite directory

  • CMake MBED_TEST_LINK_LIBRARIES command-line argument config must be passed either mbed-os or mbed-baremetal when you are building a greentea test. In addition to that, you must pass any extra library along if that library source is not maintained as part of mbed os source tree.

    For example:
    kvstore greentea test is dependent on mbed-storage and mbed-storage-filesystemstore library however you don't need to pass it via MBED_TEST_LINK_LIBRARIES as it is already target linked in greentea test CMakeLists.txt, at the same time some libraries and test cases are private to the application and if you want to use it with kvstore test then pass it with MBED_TEST_LINK_LIBRARIES command-line argument.

  • Run the following command for the configuration CMake module to be generated

    mbedtools configure -t <TOOLCHAIN> -m <MBED_TARGET> --mbed-os-path /path/to/mbed-os
    
  • Build the test binary with the full profile

    cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-os && cmake --build .
    

    To build the test binary with the baremetal profile

    cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -DMBED_TEST_LINK_LIBRARIES=mbed-baremetal && cmake --build .
    

    To build the test binary with the full profile and a "XYZ" library

    cd cmake_build/<MBED_TARGET>/<PROFILE>/<TOOLCHAIN>/ && cmake ../../../.. -G Ninja -D"MBED_TEST_LINK_LIBRARIES=mbed-os XYZ" && cmake --build .
    

Notes:

  • These steps will change when mbedtools implements a sub-command to invoke Greentea tests
  • Some Greentea tests require specific application configuration files in order to build and run successfully. For example, the connectivity/mbedtls/tests/TESTS/mbedtls/sanity test requires the configuration file found at TESTs/configs/experimental.json.

Naming convention

  • mbed namespace: Mbed CMake targets must have mbed- prefix
  • all characters are lower case
  • words separated by hyphens

For example: mbed-ble-cordio

Mbed libraries

This section provides description for all CMake targets within Mbed OS repository.

mbed-os and mbed-baremetal libraries

An application links to either mbed-os or mbed-baremetal.

Target Function
mbed-os Interface library that attaches Mbed OS to a target (objects from mbed-core and mbed-rtos)
mbed-baremetal Interface library that attaches Mbed baremetal to a target (objects from mbed-core)

These are internal targets. They are subject to change. An application should not link to any of these.

Target Function
mbed-cmsis-cortex-m CMSIS library for Cortex-M
mbed-cmsis-cortex-a CMSIS library for Cortex-A
mbed-core Contains flags from Mbed baremetal. All Mbed OS libraries link to this.
mbed-core-objects Builds objects for Mbed baremetal
mbed-rtos Contains flags that turn Mbed baremetal into Mbed OS
mbed-rtos-objects Builds objects for RTOS
mbed-os-objects Build objects for Mbed OS (objects from mbed-core and mbed-rtos)
${MBED_TARGET_CONVERTED} Contains interface flags and sources that adapt Mbed OS for a target

Additional Mbed OS libraries

An application must explicitely link them using target_link_libraries().

Target Function
mbed-events Events library
mbed-ble Bluetooth library
mbed-storage Storage library
mbed-mbedtls TLS library
mbed-nfc NFC library
mbed-nanostack Nanostack library
mbed-netsocket Netsocket library
mbed-lorawan Lorawan library
mbed-wifi Wifi library