CMake script for retrieving, building and linking Google's WebRTC into a single static library.
Find a file
2024-08-19 22:35:00 +03:00
cmake Disable use of sysroot to avoid conflicts on non-Debian based systems. 2024-08-19 22:30:50 +03:00
libwebrtc Make installation directory be relocatable (replace hard-coded paths in CMake configs with dynamic ones). 2024-08-19 22:30:50 +03:00
patches Add an ability to replace some source files before building. 2022-10-03 15:43:17 +03:00
.gitignore Separated sources fetching and building. 2021-04-07 21:37:04 +03:00
AUTHORS Add AUTHORS file 2017-01-28 16:41:14 +01:00
CHANGELOG.md (#10): State BUILD_TESTS variable inside the README and CHANGELOG 2017-03-30 19:44:36 +02:00
CMakeLists.txt Add an ability to replace some source files before building. 2022-10-03 15:43:17 +03:00
LICENSE Include the full Apache License 2.0 2017-02-15 18:34:04 +01:00
README.md Separated sources fetching and building. 2021-04-07 21:37:04 +03:00
sync.bat Fix synchronization for old versions of WebRTC. 2024-08-19 22:35:00 +03:00
sync.sh Fix synchronization for old versions of WebRTC. 2024-08-19 22:35:00 +03:00

libwebrtc License

This repository contains a collection of CMake scripts to help you embed Google's native WebRTC implementation inside your project as simple as this:

cmake_minimum_required(VERSION 3.9)
project(sample)

find_package(LibWebRTC REQUIRED)
include(${LIBWEBRTC_USE_FILE})

set(SOURCE_FILES main.cpp)
add_executable(sample ${SOURCE_FILES})
target_link_libraries(sample ${LIBWEBRTC_LIBRARIES})

Prerequisites

  • CMake 3.9 or later
  • Python 2.7 (optional for Windows since it will use the interpreter located inside the depot_tools installation)

Debian & Ubuntu

  • Required development packages:
# apt-get install build-essential libglib2.0-dev libgtk2.0-dev libxtst-dev \
                  libxss-dev libpci-dev libdbus-1-dev libgconf2-dev \
                  libgnome-keyring-dev libnss3-dev libasound2-dev libpulse-dev \
                  libudev-dev
  • GCC & G++ 4.8 or later, for C++11 support

macOS

  • OS X 10.11 or later
  • Xcode 7.3.1 or later

Windows

  • Windows 7 x64 or later

  • Visual Studio 2015/2017

    Make sure that you install the following components:

    • Visual C++, which will select three sub-categories including MFC
    • Universal Windows Apps Development Tools
      • Tools (1.4.1) and Windows 10 SDK (10.0.14393)
  • Windows 10 SDK with Debugging Tools for Windows or Windows Driver Kit 10 installed in the same Windows 10 SDK installation directory.

Getting sources

Clone the repository and run script to fetch WebRTC sources. You can pass WebRTC version (branch) to script to fetch specific version.

git clone https://github.com/UltraCoderRU/libwebrtc.git
cd libwebrtc

# Linux
./sync.sh [WEBRTC_VERSION]

# Windows
sync.bat [WEBRTC_VERSION]

Compiling

Create an output directory, browse inside it, then run CMake to configure project.

mkdir build
cd build

# Linux:
cmake -DCMAKE_BUILD_TYPE=<Debug/Release> -DCMAKE_INSTALL_PREFIX=<install_path> ..

# Windows
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=<install_path> ..

After configuration build library using standard CMake commands.

# Linux:
cmake --build .
sudo cmake --build . --target install

# Windows:
cmake --build . --config <Debug/Release> --target INSTALL

The library will be located inside the lib subdirectory of the <install_path>. The include subdirectory will contain the header files. CMake scripts will be placed inside the lib/cmake/LibWebRTC subdirectory.

Using WebRTC in your project

To import LibWebRTC into your CMake project use find_package:

find_package(LibWebRTC REQUIRED)
include(${LIBWEBRTC_USE_FILE})

target_link_libraries(my-app ${LIBWEBRTC_LIBRARIES})

You should add library installation path to CMAKE_INSTALL_PREFIX variable while configuring your project:

cmake -DCMAKE_PREFIX_PATH=<install_path> ...

Configuration

The library will be compiled and usable on the same host's platform and architecture. Here are some CMake flags which could be useful if you need to perform cross-compiling.

  • GN_EXTRA_ARGS

    Add extra arguments to the gn gen --args parameter.

  • NINJA_ARGS

    Arguments to pass while executing the ninja command.

Status

The following table displays the current state of this project, including supported platforms and architectures.

x86 amd64 arm arm64
Linux - - -
Windows - - -
MacOS - - - -
Android - - - -
iOS - - - -

Acknowledgements

Many thanks to Dr. Alex Gouaillard for being an excellent mentor for this project.

Everything started from his «Automating libwebrtc build with CMake» blog article, which was a great source of inspiration for me to create the easiest way to link the WebRTC library in any native project.