← index #11269PR #5964
Related · high · value 0.708
QUERY · ISSUE

docs: Building embedding example using shared/static lib with cmake (with example)

openby shakfuopened 2023-04-15updated 2024-09-29
docs

I was recently interested to build static and shared library versions of the micropython/examples/embedding case using cmake and I managed to get it roughly done ( see this public repo in case anyone is interested).

Along the way I found that micropython has quite a number of cmake-related files in its repo (see below).

Since I did not use any of these in my above example, is there any documentation guidance on building MicroPython with cmake that I can use to improve my example? Thanks!

ports/esp32/CMakeLists.txt
ports/esp32/main/CMakeLists.txt
ports/rp2/CMakeLists.txt
ports/zephyr/CMakeLists.txt

AND

examples/usercmodule/cexample/micropython.cmake
examples/usercmodule/cppexample/micropython.cmake
examples/usercmodule/micropython.cmake
extmod/extmod.cmake
extmod/nimble/nimble.cmake
ports/esp32/boards/ESP32_S2_WROVER/mpconfigboard.cmake
ports/esp32/boards/GENERIC/mpconfigboard.cmake
ports/esp32/boards/GENERIC_C3/mpconfigboard.cmake
ports/esp32/boards/GENERIC_C3_USB/mpconfigboard.cmake
ports/esp32/boards/GENERIC_D2WD/mpconfigboard.cmake
ports/esp32/boards/GENERIC_OTA/mpconfigboard.cmake
ports/esp32/boards/GENERIC_S2/mpconfigboard.cmake
ports/esp32/boards/GENERIC_S3/mpconfigboard.cmake
ports/esp32/boards/GENERIC_S3_SPIRAM/mpconfigboard.cmake
ports/esp32/boards/GENERIC_S3_SPIRAM_OCT/mpconfigboard.cmake
ports/esp32/boards/GENERIC_SPIRAM/mpconfigboard.cmake
ports/esp32/boards/GENERIC_UNICORE/mpconfigboard.cmake
ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake
ports/esp32/boards/LOLIN_C3_MINI/mpconfigboard.cmake
ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake
ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake
ports/esp32/boards/M5STACK_ATOM/mpconfigboard.cmake
ports/esp32/boards/OLIMEX_ESP32_POE/mpconfigboard.cmake
ports/esp32/boards/SIL_WESP32/mpconfigboard.cmake
ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake
ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake
ports/esp32/boards/UM_FEATHERS3/mpconfigboard.cmake
ports/esp32/boards/UM_PROS3/mpconfigboard.cmake
ports/esp32/boards/UM_TINYPICO/mpconfigboard.cmake
ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake
ports/esp32/boards/UM_TINYS3/mpconfigboard.cmake
ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.cmake
ports/rp2/boards/ADAFRUIT_ITSYBITSY_RP2040/mpconfigboard.cmake
ports/rp2/boards/ADAFRUIT_QTPY_RP2040/mpconfigboard.cmake
ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.cmake
ports/rp2/boards/GARATRONIC_PYBSTICK26_RP2040/mpconfigboard.cmake
ports/rp2/boards/NULLBITS_BIT_C_PRO/mpconfigboard.cmake
ports/rp2/boards/PICO/mpconfigboard.cmake
ports/rp2/boards/PICO_W/mpconfigboard.cmake
ports/rp2/boards/PIMORONI_PICOLIPO_16MB/mpconfigboard.cmake
ports/rp2/boards/PIMORONI_PICOLIPO_4MB/mpconfigboard.cmake
ports/rp2/boards/PIMORONI_TINY2040/mpconfigboard.cmake
ports/rp2/boards/SPARKFUN_PROMICRO/mpconfigboard.cmake
ports/rp2/boards/SPARKFUN_THINGPLUS/mpconfigboard.cmake
ports/rp2/boards/W5100S_EVB_PICO/mpconfigboard.cmake
ports/rp2/boards/W5500_EVB_PICO/mpconfigboard.cmake
ports/rp2/boards/WEACTSTUDIO/mpconfigboard.cmake
py/mkrules.cmake
py/py.cmake
py/usermod.cmake
CANDIDATE · PULL REQUEST

ports/libmicropython: Implement a static library "port".

closedby jimmoopened 2020-04-24updated 2022-10-06
ports

This is to facilitate embedding MicroPython in third-party build systems or larger projects.

Two main changes:

  • Add a libmicropython port with a defined interface for configuration and customisation.
  • Update (replace) the examples/embedding demo to use this (and demo a few more features that are important to people who want to embed micropython)

The examples/embedding demo has been a bit of a stumbling block and comes up occasionally on the forums (it also currently doesn't compile). I don't feel that what's currently there is particularly useful to people as a "here's how to embed micropython" demo as there's far too much stuff going on and it's not clear which part is the demo and which part is libmicropython. And the dependence on the Unix port means that it's not at all useful to people wanting to embed anywhere else (i.e. other RTOS).
My goal here is that someone could embed MicroPython without really knowing much at all about how Make works (or the MicroPython build system).

I hope that this will also be useful for ports as well as embedding. I think we could almost use this as-is for a few of our ports (especially the simpler ones like samd and mimxrt). And it could also be used to vastly simplify the ESP32 port.

There's a few loose ends here (mostly marked as TODOs) but I'd like to leave them for future PRs, but these are all things that weren't addressed at all in the previous example.

Also adds building examples/embedding to travis.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied