fiber
Loading...
Searching...
No Matches
Download & Integration

How to fetch and integrate Fiber into your CMake project.

You can integrate the Fiber library in multiple ways depending on your workflow. The main target to link against is:

  • fiber (link PRIVATE)
  • Optionally, fiber_sys_stubs (link PUBLIC) for system call stubs

(Preferred) CMake and CPM.cmake

  • CMake is a build tool generator in witch you can specify how C++ project files should be compiled.
  • CPM.cmake is a package manager - just a CMake script that you download and include - that will download, integrate, build and cache source libraries for you. I also allows to build everything always from source with the same compile options/flags, which makes this perfect for embedded.

Just add the following ot your CMakeLists.txt:

# include the CPM package manager script
include(CPM.cmake)
# Optional: Enable system call stubs for freestanding/bare-metal
set(FIBER_USE_SYS_STUBS ON CACHE BOOL "" FORCE)
# add/downloads the library
CPMAddPackage("gh:TobiasWallner/Fiber#main")
# link fiber to your project
target_link_libraries(my_target PRIVATE fiber)
# optionally: if `FIBER_USE_SYS_STUBS ON`. !!! Has to link PUBLIC !!!
target_link_libraries(my_target PUBLIC fiber_sys_stubs)

CMake with its command FetchContent

FetchContent, similar to CPM, already comes with CMake. So you do not have to download additional files. However, FetchContent does not support source cacheing and download the full libraries into your project every time.

Add to your CMakeLists.txt:

# optionally: add system wrappers that reduce binary size on embedded options that never exit `main()`
set(FIBER_USE_SYS_STUBS ON CACHE BOOL "" FORCE)
# adds/downloads the library
include(FetchContent)
FetchContent_Declare(
Fiber
GIT_REPOSITORY https://github.com/TobiasWallner/Fiber.git
GIT_TAG main
)
# make the library avaliable
FetchContent_MakeAvailable(Fiber)
# link to the emebed library
target_link_libraries(my_target PRIVATE fiber)
# optionally: if `FIBER_USE_SYS_STUBS ON`. !!! Has to link PUBLIC !!!
target_link_libraries(my_target PUBLIC fiber_sys_stubs)

CMake with its command add_subdirectory

Download Fiber into a subdirectory of your project:

git clone https://github.com/TobiasWallner/Fiber.git external/Fiber --depth=1

Add to your CMakeLists.txt:

# optionally: add system wrappers that reduce binary size on embedded options that never exit `main()`
set(FIBER_USE_SYS_STUBS ON CACHE BOOL "" FORCE)
# add the library
add_subdirectory(external/Fiber)
# link to the emebed library
target_link_libraries(my_target PRIVATE fiber)
# optionally: if `FIBER_USE_SYS_STUBS ON`. !!! Has to link PUBLIC !!!
target_link_libraries(my_target PUBLIC fiber_sys_stubs) # if ON

🛠 Don't Want to Use CMake?

No worries. If you're using STM32CubeIDE, Atmel Studio, or Keil:

  • download the library from https://github.com/TobiasWallner/Fiber
  • Add all .cpp files from fiber/* to your project.
  • Include /fiber/ to your include path.
  • Start using #include <fiber/xxx.hpp> and you're good to go.

Please refere to your IDE vendor on how to include libraries.

❗ But seriously, you should try CMake. It automates libraries for C++.


If you want to know more about the compile definitions and switches you can set to customise your project, see: Compile Definition.

Next: Hello Coroutine