2
0
Эх сурвалжийг харах

Added USE_SYSTEM_USRSCTP cmake option

tytan652 2 жил өмнө
parent
commit
b6d2e92231

+ 18 - 12
CMakeLists.txt

@@ -9,6 +9,7 @@ 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(USE_SYSTEM_USRSCTP "Use system libusrsctp" OFF)
 option(USE_SYSTEM_PLOG "Use system Plog" OFF)
 option(USE_SYSTEM_JSON "Use system Nlohmann JSON" OFF)
 option(NO_WEBSOCKET "Disable WebSocket support" OFF)
@@ -214,19 +215,24 @@ 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}

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