Skip to content

Commit

Permalink
Make datachannel target comply with BUILD_SHARED_LIBS option
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Oct 22, 2024
1 parent 6cc706f commit ed3656d
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.13)
project(libdatachannel
VERSION 0.21.2
LANGUAGES CXX)
Expand All @@ -7,6 +7,7 @@ set(PROJECT_DESCRIPTION "C/C++ WebRTC network library featuring Data Channels, M
include(GNUInstallDirs)

# Options
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
option(USE_MBEDTLS "Use Mbed TLS instead of OpenSSL" OFF)
option(USE_NICE "Use libnice instead of libjuice" OFF)
Expand Down Expand Up @@ -49,7 +50,6 @@ endif()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_SHARED_LIBS OFF) # to force usrsctp to be built static

if(WIN32)
add_definitions(-DWIN32_LEAN_AND_MEAN)
Expand Down Expand Up @@ -254,11 +254,24 @@ else()
option(sctp_inet6 OFF)
option(sctp_werror OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF) # to force usrsctp to be built static
add_subdirectory(deps/usrsctp EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS})
if (MSYS OR MINGW)
target_compile_definitions(usrsctp PUBLIC -DSCTP_STDINT_INCLUDE=<stdint.h>)
endif()
add_library(Usrsctp::Usrsctp ALIAS usrsctp)
if(NOT BUILD_SHARED_LIBS)
# usrsctp lacks an export set
set_target_properties(usrsctp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
install(TARGETS usrsctp EXPORT UsrsctpTargets)
install(EXPORT UsrsctpTargets
FILE UsrsctpTargets.cmake
NAMESPACE Usrsctp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/usrsctp
EXCLUDE_FROM_ALL)
endif()
endif()

if(RTC_UPDATE_VERSION_HEADER)
Expand All @@ -268,7 +281,7 @@ if(RTC_UPDATE_VERSION_HEADER)
)
endif()

add_library(datachannel SHARED
add_library(datachannel
${LIBDATACHANNEL_SOURCES}
${LIBDATACHANNEL_HEADERS}
${LIBDATACHANNEL_IMPL_SOURCES}
Expand Down Expand Up @@ -301,18 +314,24 @@ target_compile_definitions(datachannel-static PUBLIC RTC_STATIC)
target_include_directories(datachannel PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE: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 PRIVATE Threads::Threads)
target_link_libraries(datachannel PRIVATE Usrsctp::Usrsctp plog::plog)
target_include_directories(datachannel PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel PRIVATE
Threads::Threads
Usrsctp::Usrsctp
$<BUILD_INTERFACE:plog::plog>)

target_include_directories(datachannel-static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE: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 PRIVATE Threads::Threads)
target_link_libraries(datachannel-static PRIVATE Usrsctp::Usrsctp plog::plog)
target_include_directories(datachannel-static PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc
${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(datachannel-static PRIVATE
Threads::Threads
Usrsctp::Usrsctp
$<BUILD_INTERFACE:plog::plog>)

if(WIN32)
target_link_libraries(datachannel PUBLIC ws2_32) # winsock2
Expand Down Expand Up @@ -349,6 +368,7 @@ else()
else()
if(NOT TARGET srtp2)
add_subdirectory(deps/libsrtp EXCLUDE_FROM_ALL)
install(TARGETS srtp2)
endif()
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_SRTP=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_SRTP=0)
Expand Down Expand Up @@ -426,9 +446,10 @@ else()
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuice)
else()
add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
install(TARGETS juice)
target_compile_definitions(datachannel PRIVATE RTC_SYSTEM_JUICE=0)
target_compile_definitions(datachannel-static PRIVATE RTC_SYSTEM_JUICE=0)
target_link_libraries(datachannel PRIVATE LibJuice::LibJuiceStatic)
target_link_libraries(datachannel PRIVATE LibJuice::LibJuice)
target_link_libraries(datachannel-static PRIVATE LibJuice::LibJuiceStatic)
endif()
endif()
Expand Down

0 comments on commit ed3656d

Please sign in to comment.