diff --git a/CMakeLists.txt b/CMakeLists.txt index b321c2ff9..5c88ef6a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.7) +cmake_minimum_required(VERSION 3.13) project(libdatachannel VERSION 0.21.2 LANGUAGES CXX) @@ -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) @@ -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) @@ -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=) 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) @@ -268,7 +281,7 @@ if(RTC_UPDATE_VERSION_HEADER) ) endif() -add_library(datachannel SHARED +add_library(datachannel ${LIBDATACHANNEL_SOURCES} ${LIBDATACHANNEL_HEADERS} ${LIBDATACHANNEL_IMPL_SOURCES} @@ -301,18 +314,24 @@ target_compile_definitions(datachannel-static PUBLIC RTC_STATIC) target_include_directories(datachannel PUBLIC $ $) -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 + $) target_include_directories(datachannel-static PUBLIC $ $) -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 + $) if(WIN32) target_link_libraries(datachannel PUBLIC ws2_32) # winsock2 @@ -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) @@ -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()