mitteLib
Loading...
Searching...
No Matches
Mittelib

Nice C++17 goodies made in Mittelab

pipeline status

Repo: https://git.mittelab.org/proj/mittelib
Documentation: https://proj.mittelab.dev/mittelib/
PlatformIO lib: https://platformio.org/lib/show/12998/mitteLib
EspressIF component: https://components.espressif.com/components/mittelab/mittelib

This library aim at providing some handy, general purpose functionalities to embedded development. The C++ STL is rich but some functionalities (e.g. std::variant) require features (e.g. CTTI) that are generally disabled on embedded platforms; other helper classes instead are common patterns when interoperating with C libraries. This was originally developed for ESP-IDF, in C++17, but it can be used on desktop too (functionalities have been ported). Among the added features, binary streams, enum-based variants, observer-pattern helper classes, string helpers, a simple logging facility like IDF's.

Using the library in your project

ESP-IDF: CLI

idf.py add-dependency "mittelab/mittelib^1.0.8"

or in you idf_component.yml:

dependencies:
mittelab/mittelib: "^1.0.8"

ESP-IDF: directly from the git tree

In your idf_component.yml:

dependencies:
mittelib:
path: mittelib
git: https://git.mittelab.org/proj/mittelib.git
version: 1.0.8 # or master

ESP-IDF: as submodule

This is somewhat awkward because the library is in the mittelib subfolder, and the root CMakeLists.txt is for tests and usage on desktop, and IDF expects to find a direct call to idf_component_register in the CMakeLists.txt file inside the component folder. So we have to create a "mittelib" component that includes the right files. Luckily (or intentionally) Mittelib is just a collection of cpp files, so this is easy.

  1. Create a new component subfolder components/mittelib
  2. Clone this repo in components/mittelib/thirdparty (you can choose another name)
  3. Insert the following in components/mittelib/CMakeLists.txt:
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/mittelib/*.cpp")
idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/mittelib/include")

Linux CMake: fetch library via CMake

This uses FetchContent to download the library. In a directory thirdparty/mittelib (you can choose a different path), add a CMakeLists.txt file that contains

if (DEFINED ENV{IDF_PATH})
message(SEND_ERROR "This is not supposed to be used by ESP-IDF")
endif ()
include(FetchContent)
FetchContent_Declare(
mittelib
GIT_REPOSITORY https://git.mittelab.org/proj/mittelib.git
GIT_TAG 1.0.8 # or master
SOURCE_SUBDIR mittelib
)
FetchContent_MakeAvailable(mittelib)
FetchContent_GetProperties(mittelib)

In your project root CMakeLists.txt, add

cmake_minimum_required(VERSION 3.16)
project(kaproto)
add_subdirectory(thirdparty/mittelib)

Linux CMake: git submodule

Assume you have added this repo as a submodule at thirdparty/mittelib. In your project root CMakeList.txt, add

cmake_minimum_required(VERSION 3.16)
project(kaproto)
add_subdirectory(thirdparty/mittelib/mittelib)

This is correct, there is one extra "mittelib" subfolder.