mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-22 15:15:28 +00:00
Added CMake support
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
build/
|
||||||
*.d
|
*.d
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
|
64
CMakeLists.txt
Normal file
64
CMakeLists.txt
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
cmake_minimum_required (VERSION 3.7)
|
||||||
|
project (libdatachannel
|
||||||
|
DESCRIPTION "WebRTC Data Channels Library"
|
||||||
|
VERSION 0.2.1
|
||||||
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
||||||
|
|
||||||
|
set(LIBDATACHANNEL_SOURCES
|
||||||
|
candidate.cpp
|
||||||
|
certificate.cpp
|
||||||
|
channel.cpp
|
||||||
|
configuration.cpp
|
||||||
|
datachannel.cpp
|
||||||
|
description.cpp
|
||||||
|
dtlstransport.cpp
|
||||||
|
icetransport.cpp
|
||||||
|
peerconnection.cpp
|
||||||
|
rtc.cpp
|
||||||
|
sctptransport.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
list(TRANSFORM LIBDATACHANNEL_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
||||||
|
|
||||||
|
add_definitions(-DINET -DINET6)
|
||||||
|
add_subdirectory(usrsctp EXCLUDE_FROM_ALL)
|
||||||
|
target_compile_options(usrsctp-static PRIVATE -Wno-address-of-packed-member)
|
||||||
|
|
||||||
|
find_package(GnuTLS REQUIRED)
|
||||||
|
find_package(LibNice REQUIRED)
|
||||||
|
|
||||||
|
if(NOT TARGET GnuTLS::GnuTLS)
|
||||||
|
add_library(GnuTLS::GnuTLS UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(GnuTLS::GnuTLS PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${GNUTLS_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_COMPILE_DEFINITIONS "${GNUTLS_DEFINITIONS}"
|
||||||
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||||
|
IMPORTED_LOCATION "${GNUTLS_LIBRARIES}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(datachannel SHARED ${LIBDATACHANNEL_SOURCES})
|
||||||
|
set_target_properties(datachannel PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
CXX_STANDARD 17)
|
||||||
|
|
||||||
|
target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
|
||||||
|
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
|
target_link_libraries(datachannel usrsctp-static GnuTLS::GnuTLS LibNice::LibNice)
|
||||||
|
|
||||||
|
add_library(datachannel-static STATIC ${LIBDATACHANNEL_SOURCES})
|
||||||
|
set_target_properties(datachannel-static PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
CXX_STANDARD 17)
|
||||||
|
|
||||||
|
target_include_directories(datachannel-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
|
||||||
|
target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
|
target_link_libraries(datachannel-static usrsctp-static GnuTLS::GnuTLS LibNice::LibNice)
|
||||||
|
|
||||||
|
add_library(LibDataChannel::LibDataChannel ALIAS datachannel)
|
||||||
|
add_library(LibDataChannel::LibDataChannelStatic ALIAS datachannel-static)
|
||||||
|
|
123
cmake/Modules/FindGLIB.cmake
Normal file
123
cmake/Modules/FindGLIB.cmake
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
# - Try to find Glib and its components (gio, gobject etc)
|
||||||
|
# Once done, this will define
|
||||||
|
#
|
||||||
|
# GLIB_FOUND - system has Glib
|
||||||
|
# GLIB_INCLUDE_DIRS - the Glib include directories
|
||||||
|
# GLIB_LIBRARIES - link these to use Glib
|
||||||
|
#
|
||||||
|
# Optionally, the COMPONENTS keyword can be passed to find_package()
|
||||||
|
# and Glib components can be looked for. Currently, the following
|
||||||
|
# components can be used, and they define the following variables if
|
||||||
|
# found:
|
||||||
|
#
|
||||||
|
# gio: GLIB_GIO_LIBRARIES
|
||||||
|
# gobject: GLIB_GOBJECT_LIBRARIES
|
||||||
|
# gmodule: GLIB_GMODULE_LIBRARIES
|
||||||
|
# gthread: GLIB_GTHREAD_LIBRARIES
|
||||||
|
#
|
||||||
|
# Note that the respective _INCLUDE_DIR variables are not set, since
|
||||||
|
# all headers are in the same directory as GLIB_INCLUDE_DIRS.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in the
|
||||||
|
# documentation and/or other materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
|
||||||
|
# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
|
||||||
|
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||||
|
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||||
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
find_package(PkgConfig)
|
||||||
|
pkg_check_modules(PC_GLIB QUIET glib-2.0)
|
||||||
|
|
||||||
|
find_library(GLIB_LIBRARIES
|
||||||
|
NAMES glib-2.0
|
||||||
|
HINTS ${PC_GLIB_LIBDIR}
|
||||||
|
${PC_GLIB_LIBRARY_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Files in glib's main include path may include glibconfig.h, which,
|
||||||
|
# for some odd reason, is normally in $LIBDIR/glib-2.0/include.
|
||||||
|
get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH)
|
||||||
|
find_path(GLIBCONFIG_INCLUDE_DIR
|
||||||
|
NAMES glibconfig.h
|
||||||
|
HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR}
|
||||||
|
${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS}
|
||||||
|
PATH_SUFFIXES glib-2.0/include
|
||||||
|
)
|
||||||
|
|
||||||
|
find_path(GLIB_INCLUDE_DIR
|
||||||
|
NAMES glib.h
|
||||||
|
HINTS ${PC_GLIB_INCLUDEDIR}
|
||||||
|
${PC_GLIB_INCLUDE_DIRS}
|
||||||
|
PATH_SUFFIXES glib-2.0
|
||||||
|
)
|
||||||
|
|
||||||
|
set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR})
|
||||||
|
|
||||||
|
# Version detection
|
||||||
|
if (EXISTS "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h")
|
||||||
|
file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS)
|
||||||
|
string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
|
||||||
|
set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
|
||||||
|
set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}")
|
||||||
|
string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}")
|
||||||
|
set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}")
|
||||||
|
set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# Additional Glib components. We only look for libraries, as not all of them
|
||||||
|
# have corresponding headers and all headers are installed alongside the main
|
||||||
|
# glib ones.
|
||||||
|
foreach (_component ${GLIB_FIND_COMPONENTS})
|
||||||
|
if (${_component} STREQUAL "gio")
|
||||||
|
find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR})
|
||||||
|
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES)
|
||||||
|
elseif (${_component} STREQUAL "gobject")
|
||||||
|
find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR})
|
||||||
|
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES)
|
||||||
|
elseif (${_component} STREQUAL "gmodule")
|
||||||
|
find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR})
|
||||||
|
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES)
|
||||||
|
elseif (${_component} STREQUAL "gthread")
|
||||||
|
find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR})
|
||||||
|
set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES)
|
||||||
|
elseif (${_component} STREQUAL "gio-unix")
|
||||||
|
# gio-unix is compiled as part of the gio library, but the include paths
|
||||||
|
# are separate from the shared glib ones. Since this is currently only used
|
||||||
|
# by WebKitGTK we don't go to extraordinary measures beyond pkg-config.
|
||||||
|
pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0)
|
||||||
|
endif ()
|
||||||
|
endforeach ()
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS}
|
||||||
|
VERSION_VAR GLIB_VERSION)
|
||||||
|
|
||||||
|
mark_as_advanced(
|
||||||
|
GLIBCONFIG_INCLUDE_DIR
|
||||||
|
GLIB_GIO_LIBRARIES
|
||||||
|
GLIB_GIO_UNIX_LIBRARIES
|
||||||
|
GLIB_GMODULE_LIBRARIES
|
||||||
|
GLIB_GOBJECT_LIBRARIES
|
||||||
|
GLIB_GTHREAD_LIBRARIES
|
||||||
|
GLIB_INCLUDE_DIR
|
||||||
|
GLIB_INCLUDE_DIRS
|
||||||
|
GLIB_LIBRARIES
|
||||||
|
)
|
||||||
|
|
35
cmake/Modules/FindLibNice.cmake
Normal file
35
cmake/Modules/FindLibNice.cmake
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
if (NOT TARGET LibNice::LibNice)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
pkg_check_modules(PC_LIBNICE nice)
|
||||||
|
set(LIBNICE_DEFINITIONS ${PC_LIBNICE_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
find_path(LIBNICE_INCLUDE_DIR nice/agent.h
|
||||||
|
HINTS ${PC_LIBNICE_INCLUDEDIR} ${PC_LIBNICE_INCLUDE_DIRS}
|
||||||
|
PATH_SUFFICES libnice)
|
||||||
|
find_library(LIBNICE_LIBRARY NAMES nice libnice
|
||||||
|
HINTS ${PC_LIBNICE_LIBDIR} ${PC_LIBNICE_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(Libnice DEFAULT_MSG
|
||||||
|
LIBNICE_LIBRARY LIBNICE_INCLUDE_DIR)
|
||||||
|
mark_as_advanced(LIBNICE_INCLUDE_DIR LIBNICE_LIBRARY)
|
||||||
|
|
||||||
|
set(LIBNICE_LIBRARIES ${LIBNICE_LIBRARY})
|
||||||
|
set(LIBNICE_INCLUDE_DIRS ${LIBNICE_INCLUDE_DIR})
|
||||||
|
|
||||||
|
find_package(GLIB REQUIRED COMPONENTS gio gobject gmodule gthread)
|
||||||
|
|
||||||
|
list(APPEND LIBNICE_INCLUDE_DIRS ${GLIB_INCLUDE_DIRS})
|
||||||
|
list(APPEND LIBNICE_LIBRARIES ${GLIB_GOBJECT_LIBRARIES} ${GLIB_LIBRARIES})
|
||||||
|
|
||||||
|
if (LIBNICE_FOUND)
|
||||||
|
add_library(LibNice::LibNice UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(LibNice::LibNice PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${LIBNICE_LIBRARY}"
|
||||||
|
INTERFACE_COMPILE_DEFINITIONS "_REENTRANT"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${LIBNICE_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${LIBNICE_LIBRARIES}"
|
||||||
|
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
Reference in New Issue
Block a user