This document describes how to build libpeer, including the FAT library that combines all dependencies into a single static library.
- CMake 3.16 or higher
- C compiler (GCC or Clang)
- Git
- Bash shell
sudo apt -y install git cmake build-essentialbrew install cmakeClone the repository with all submodules:
git clone --recursive git@github.com:dsugisawa-mixi/libpeer.git
cd libpeerIf you already cloned without --recursive, initialize submodules:
git submodule update --init --recursivecmake -S . -B build| Option | Default | Description |
|---|---|---|
ENABLE_TESTS |
OFF | Enable building tests |
BUILD_SHARED_LIBS |
OFF | Build shared libraries |
ADDRESS_SANITIZER |
OFF | Build with AddressSanitizer |
MEMORY_SANITIZER |
OFF | Build with MemorySanitizer |
THREAD_SANITIZER |
OFF | Build with ThreadSanitizer |
UNDEFINED_BEHAVIOR_SANITIZER |
OFF | Build with UndefinedBehaviorSanitizer |
cmake --build buildThis will:
- Build all third-party dependencies (mbedtls, libsrtp, usrsctp, cJSON)
- Build the main
libpeerlibrary - Build the example applications
The FAT library combines all static libraries into a single archive file, making it easier to link your application.
cmake --build build --target fat_libraryThe FAT library will be created at:
build/dist/lib/libpeer_fat.a
The FAT library (libpeer_fat.a) includes:
libpeer.a- Main WebRTC librarylibusrsctp.a- SCTP implementation for DataChannellibsrtp2.a- Secure RTPlibmbedtls.a- TLS librarylibmbedx509.a- X.509 certificate handlinglibmbedcrypto.a- Cryptographic functionslibcjson.a- JSON parsing
Link against the FAT library in your project:
gcc -o myapp myapp.c -Ibuild/dist/include -Lbuild/dist/lib -lpeer_fat -lpthreadOr in CMake:
add_executable(myapp myapp.c)
target_include_directories(myapp PRIVATE ${LIBPEER_BUILD_DIR}/dist/include)
target_link_libraries(myapp ${LIBPEER_BUILD_DIR}/dist/lib/libpeer_fat.a pthread)To cross-compile for another platform, specify a CMake toolchain file:
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake
cmake --build build
cmake --build build --target fat_libraryAfter building, the output directory structure is:
build/
├── dist/
│ ├── include/ # Header files
│ │ ├── cjson/
│ │ ├── mbedtls/
│ │ ├── srtp2/
│ │ └── usrsctp/
│ └── lib/
│ ├── libcjson.a
│ ├── libmbedcrypto.a
│ ├── libmbedtls.a
│ ├── libmbedx509.a
│ ├── libpeer_fat.a # Combined FAT library
│ ├── libsrtp2.a
│ └── libusrsctp.a
├── src/
│ └── libpeer.a # Main library
└── examples/
└── generic/
└── sample # Example application