Browse Source

Merge pull request #818 from tytan652/no_more_mandatory_submodules

Allow using system lib for all submodules
Paul-Louis Ageneau 2 years ago
parent
commit
c3b9d78dd2

+ 12 - 2
BUILDING.md

@@ -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
 ```
@@ -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.
 

+ 34 - 17
CMakeLists.txt

@@ -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)
@@ -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}
@@ -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)

+ 6 - 7
README.md

@@ -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
 

+ 51 - 0
cmake/Modules/FindUsrsctp.cmake

@@ -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 - 0
cmake/Modules/Findplog.cmake

@@ -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()

+ 1 - 1
examples/client-benchmark/CMakeLists.txt

@@ -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

+ 1 - 1
examples/client/CMakeLists.txt

@@ -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

+ 1 - 1
examples/media-receiver/CMakeLists.txt

@@ -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

+ 1 - 1
examples/media-sender/CMakeLists.txt

@@ -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

+ 1 - 1
examples/media-sfu/CMakeLists.txt

@@ -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

+ 1 - 1
examples/streamer/CMakeLists.txt

@@ -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