Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using system lib for all submodules #818

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# libdatachannel - Building instructions

## Clone repository and submodules
## Clone repository

```bash
$ git clone https://github.com/paullouisageneau/libdatachannel.git
```

## Init submodules

This step is optional if `PREFER_SYSTEM_LIB` CMake option will be enabled.

```bash
$ cd libdatachannel
$ git submodule update --init --recursive --depth 1
```
Expand All @@ -12,7 +19,10 @@ $ git submodule update --init --recursive --depth 1

The CMake library targets `libdatachannel` and `libdatachannel-static` respectively correspond to the shared and static libraries. The default target will build tests and examples.

The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice. The options `USE_SYSTEM_SRTP` and `USE_SYSTEM_JUICE` allow to link against the system library rather than building the submodule, for libsrtp and libjuice respectively.
The option `USE_GNUTLS` allows to switch between OpenSSL (default) and GnuTLS, and the option `USE_NICE` allows to switch between libjuice as submodule (default) and libnice.

The option `PREFER_SYSTEM_LIB` allow to link against the system library rather than building all the submodule.
Options `USE_SYSTEM_SRTP`, `USE_SYSTEM_JUICE`, `USE_SYSTEM_USRSCTP`, `USE_SYSTEM_PLOG` and `USE_SYSTEM_JSON` allow to do the same but per submodule, for libsrtp, libjuice, libusrsctp, Plog and Nlohmann JSON respectively.

If you only need Data Channels, the option `NO_MEDIA` allows to make the library lighter by removing media support. Similarly, `NO_WEBSOCKET` removes WebSocket support.

Expand Down
51 changes: 34 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, M
# Options
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
option(USE_NICE "Use libnice instead of libjuice" OFF)
option(USE_SYSTEM_SRTP "Use system libSRTP" OFF)
option(USE_SYSTEM_JUICE "Use system libjuice" OFF)
option(PREFER_SYSTEM_LIB "Prefer system libraries over deps folder" OFF)
option(USE_SYSTEM_SRTP "Use system libSRTP" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_JUICE "Use system libjuice" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_USRSCTP "Use system libusrsctp" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_PLOG "Use system Plog" ${PREFER_SYSTEM_LIB})
option(USE_SYSTEM_JSON "Use system Nlohmann JSON" ${PREFER_SYSTEM_LIB})
option(NO_WEBSOCKET "Disable WebSocket support" OFF)
option(NO_MEDIA "Disable media transport support" OFF)
option(NO_EXAMPLES "Disable examples" OFF)
Expand Down Expand Up @@ -202,25 +206,34 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
add_subdirectory(deps/plog EXCLUDE_FROM_ALL)
if(USE_SYSTEM_PLOG)
find_package(plog REQUIRED)
else()
set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
add_subdirectory(deps/plog EXCLUDE_FROM_ALL)
endif()

if(SCTP_DEBUG)
add_definitions(-DSCTP_DEBUG)
endif()
option(sctp_build_shared_lib OFF)
option(sctp_build_programs OFF)
option(sctp_inet OFF)
option(sctp_inet6 OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL)
if (MSYS OR MINGW)
target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(usrsctp PRIVATE -Wno-error=format-truncation)

if(USE_SYSTEM_USRSCTP)
find_package(Usrsctp REQUIRED)
else()
option(sctp_build_shared_lib OFF)
option(sctp_build_programs OFF)
option(sctp_inet OFF)
option(sctp_inet6 OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL)
if (MSYS OR MINGW)
target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(usrsctp PRIVATE -Wno-error=format-truncation)
endif()
add_library(Usrsctp::Usrsctp ALIAS usrsctp)
endif()
add_library(Usrsctp::Usrsctp ALIAS usrsctp)

add_library(datachannel SHARED
${LIBDATACHANNEL_SOURCES}
Expand Down Expand Up @@ -473,7 +486,11 @@ endif()
# Examples
if(NOT NO_EXAMPLES)
set(JSON_BuildTests OFF CACHE INTERNAL "")
add_subdirectory(deps/json EXCLUDE_FROM_ALL)
if(USE_SYSTEM_JSON)
find_package(nlohmann_json REQUIRED)
else()
add_subdirectory(deps/json EXCLUDE_FROM_ALL)
endif()

if(NOT NO_WEBSOCKET)
add_subdirectory(examples/client)
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ libdatachannel is available on [AUR](https://aur.archlinux.org/packages/libdatac

## Dependencies

Only [GnuTLS](https://www.gnutls.org/) or [OpenSSL](https://www.openssl.org/) is necessary. Optionally, [libnice](https://nice.freedesktop.org/) can be selected as an alternative ICE backend instead of libjuice.

Submodules:
- usrsctp: https://github.com/sctplab/usrsctp
- plog: https://github.com/SergiusTheBest/plog
- libjuice: https://github.com/paullouisageneau/libjuice (if not compiled with libnice backend)
- libsrtp: https://github.com/cisco/libsrtp (if compiled with media support)
- [GnuTLS](https://www.gnutls.org/) or [OpenSSL](https://www.openssl.org/)
- [usrsctp](https://github.com/sctplab/usrsctp) (as submodule by default)
- [Plog](https://github.com/SergiusTheBest/plog) (as submodule by default)
- [libjuice](https://github.com/paullouisageneau/libjuice) (as submodule by default) or [libnice](https://nice.freedesktop.org/) as an ICE backend.
- [libsrtp](https://github.com/cisco/libsrtp) (as submodule by default) required if compiled with media support.
- [Nlohmann JSON](https://github.com/nlohmann/json) (as submodule by default) required to build examples.

## Building

Expand Down
51 changes: 51 additions & 0 deletions cmake/Modules/FindUsrsctp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#[=======================================================================[.rst
FindUsrsctp
----------

FindModule for Usrsctp library

Imported Targets
^^^^^^^^^^^^^^^^

This module defines the :prop_tgt:`IMPORTED` target ``Usrsctp::Usrsctp``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``Usrsctp_FOUND``
True, if the library was found.

#]=======================================================================]

include(FindPackageHandleStandardArgs)

find_path(
Usrsctp_INCLUDE_DIR
NAMES usrsctp.h
PATHS /usr/include /usr/local/include)

find_library(
Usrsctp_LIBRARY
NAMES usrsctp libusrsctp
PATHS /usr/lib /usr/local/lib)

find_package_handle_standard_args(
Usrsctp
REQUIRED_VARS Usrsctp_LIBRARY Usrsctp_INCLUDE_DIR)
mark_as_advanced(Usrsctp_INCLUDE_DIR Usrsctp_LIBRARY)

if(Usrsctp_FOUND)
if(NOT TARGET Usrsctp::Usrsctp)
if(IS_ABSOLUTE "${Usrsctp_LIBRARY}")
add_library(Usrsctp::Usrsctp UNKNOWN IMPORTED)
set_property(TARGET Usrsctp::Usrsctp PROPERTY IMPORTED_LOCATION "${Usrsctp_LIBRARY}")
else()
add_library(Usrsctp::Usrsctp INTERFACE IMPORTED)
set_property(TARGET Usrsctp::Usrsctp PROPERTY IMPORTED_LIBNAME "${Usrsctp_LIBRARY}")
endif()

set_target_properties(Usrsctp::Usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Usrsctp_INCLUDE_DIR}")
endif()
endif()
47 changes: 47 additions & 0 deletions cmake/Modules/Findplog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#[=======================================================================[.rst
Findplog
----------

FindModule for Plog library

Imported Targets
^^^^^^^^^^^^^^^^

This module defines the :prop_tgt:`IMPORTED` target ``plog::plog``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``plog_FOUND``
True, if the library was found.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``plog_INCLUDE_DIR``
Directory containing ``plog/Log.h``.

#]=======================================================================]

include(FindPackageHandleStandardArgs)

find_path(
plog_INCLUDE_DIR
NAMES plog/Log.h
PATHS /usr/include /usr/local/include)

find_package_handle_standard_args(
plog
REQUIRED_VARS plog_INCLUDE_DIR)
mark_as_advanced(plog_INCLUDE_DIR)

if(plog_FOUND)
if(NOT TARGET plog::plog)
add_library(plog::plog INTERFACE IMPORTED)
set_target_properties(plog::plog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${plog_INCLUDE_DIR}")
endif()
endif()
2 changes: 1 addition & 1 deletion examples/client-benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set_target_properties(datachannel-client-benchmark PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.client.benchmark)

find_package(Threads REQUIRED)
target_link_libraries(datachannel-client-benchmark LibDataChannel::LibDataChannel Threads::Threads nlohmann_json)
target_link_libraries(datachannel-client-benchmark LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET datachannel-client-benchmark POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion examples/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ set_target_properties(datachannel-client PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.client)

find_package(Threads REQUIRED)
target_link_libraries(datachannel-client LibDataChannel::LibDataChannel Threads::Threads nlohmann_json)
target_link_libraries(datachannel-client LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET datachannel-client POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion examples/media-receiver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set_target_properties(datachannel-media-receiver PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.media-receiver)

find_package(Threads REQUIRED)
target_link_libraries(datachannel-media-receiver LibDataChannel::LibDataChannel Threads::Threads nlohmann_json)
target_link_libraries(datachannel-media-receiver LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET datachannel-media-receiver POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion examples/media-sender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set_target_properties(datachannel-media-sender PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.media-sender)

find_package(Threads REQUIRED)
target_link_libraries(datachannel-media-sender LibDataChannel::LibDataChannel Threads::Threads nlohmann_json)
target_link_libraries(datachannel-media-sender LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET datachannel-media-sender POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion examples/media-sfu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set_target_properties(datachannel-media-sfu PROPERTIES
set_target_properties(datachannel-media-sfu PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.sfumedia)

target_link_libraries(datachannel-media-sfu LibDataChannel::LibDataChannel nlohmann_json)
target_link_libraries(datachannel-media-sfu LibDataChannel::LibDataChannel nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET datachannel-media-sfu POST_BUILD
Expand Down
2 changes: 1 addition & 1 deletion examples/streamer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set_target_properties(streamer PROPERTIES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.streamer)

find_package(Threads REQUIRED)
target_link_libraries(streamer LibDataChannel::LibDataChannel Threads::Threads nlohmann_json)
target_link_libraries(streamer LibDataChannel::LibDataChannel Threads::Threads nlohmann_json::nlohmann_json)

if(MSVC)
add_custom_command(TARGET streamer POST_BUILD
Expand Down