Browse Source

Updated Makefile and CMakeLists for libjuice

Paul-Louis Ageneau 5 years ago
parent
commit
2dece6afff
2 changed files with 66 additions and 30 deletions
  1. 36 20
      CMakeLists.txt
  2. 30 10
      Makefile

+ 36 - 20
CMakeLists.txt

@@ -1,9 +1,12 @@
 cmake_minimum_required (VERSION 3.7)
 project (libdatachannel
 	DESCRIPTION "WebRTC Data Channels Library"
-	VERSION 0.2.1
+	VERSION 0.3.2
 	LANGUAGES CXX)
 
+option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
+option(USE_JUICE "Use libjuice instead of libnice" OFF)
+
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
 
@@ -33,6 +36,7 @@ set(TESTS_ANSWERER_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/test/p2p/answerer.cpp
 )
 
+
 # Hack because usrsctp uses CMAKE_SOURCE_DIR instead of CMAKE_CURRENT_SOURCE_DIR
 set(CMAKE_REQUIRED_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}/deps/usrsctp/usrsctplib")
 
@@ -58,9 +62,8 @@ else()
   endif()
 endif()
 
-option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
-
-find_package(LibNice REQUIRED)
+add_library(Usrsctp::Usrsctp ALIAS usrsctp)
+add_library(Usrsctp::UsrsctpStatic ALIAS usrsctp-static)
 
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
@@ -74,10 +77,9 @@ target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/includ
 target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
 target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
 target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
-target_link_libraries(datachannel 
+target_link_libraries(datachannel
 						Threads::Threads
-						usrsctp-static 
-						LibNice::LibNice						
+						usrsctp-static
 						)
 
 add_library(datachannel-static STATIC EXCLUDE_FROM_ALL ${LIBDATACHANNEL_SOURCES})
@@ -91,8 +93,7 @@ target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR
 target_include_directories(datachannel-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
 target_link_libraries(datachannel-static
 						Threads::Threads
-						usrsctp-static 
-						LibNice::LibNice						
+						usrsctp-static
 						)
 
 if (USE_GNUTLS)
@@ -117,29 +118,44 @@ else()
 	target_link_libraries(datachannel-static OpenSSL::SSL)
 endif()
 
+if (USE_JUICE)
+	add_subdirectory(deps/libjuice EXCLUDE_FROM_ALL)
+	target_compile_definitions(datachannel PRIVATE USE_JUICE=1)
+	target_link_libraries(datachannel LibJuice::LibJuiceStatic)
+	target_compile_definitions(datachannel-static PRIVATE USE_JUICE=1)
+	target_link_libraries(datachannel-static LibJuice::LibJuiceStatic)
+else()
+	find_package(LibNice REQUIRED)
+	target_compile_definitions(datachannel PRIVATE USE_JUICE=0)
+	target_link_libraries(datachannel LibNice::LibNice)
+	target_compile_definitions(datachannel-static PRIVATE USE_JUICE=0)
+	target_link_libraries(datachannel-static LibNice::LibNice)
+endif()
+
 add_library(LibDataChannel::LibDataChannel ALIAS datachannel)
 add_library(LibDataChannel::LibDataChannelStatic ALIAS datachannel-static)
 
 # Main Test
-add_executable(tests ${TESTS_SOURCES})
-set_target_properties(tests PROPERTIES
+add_executable(libdatachannel-tests ${TESTS_SOURCES})
+set_target_properties(libdatachannel-tests PROPERTIES
 	VERSION ${PROJECT_VERSION}
 	CXX_STANDARD 17)
-
-target_link_libraries(tests datachannel)
+set_target_properties(libdatachannel-tests PROPERTIES OUTPUT_NAME tests)
+target_link_libraries(libdatachannel-tests datachannel)
 
 # P2P Test: offerer
-add_executable(offerer ${TESTS_OFFERER_SOURCES})
-set_target_properties(offerer PROPERTIES
+add_executable(libdatachannel-offerer ${TESTS_OFFERER_SOURCES})
+set_target_properties(libdatachannel-offerer PROPERTIES
 	VERSION ${PROJECT_VERSION}
 	CXX_STANDARD 17)
-
-target_link_libraries(offerer datachannel)
+set_target_properties(libdatachannel-offerer PROPERTIES OUTPUT_NAME offerer)
+target_link_libraries(libdatachannel-offerer datachannel)
 
 # P2P Test: answerer
-add_executable(answerer ${TESTS_ANSWERER_SOURCES})
-set_target_properties(answerer PROPERTIES
+add_executable(libdatachannel-answerer ${TESTS_ANSWERER_SOURCES})
+set_target_properties(libdatachannel-answerer PROPERTIES
 	VERSION ${PROJECT_VERSION}
 	CXX_STANDARD 17)
+set_target_properties(libdatachannel-answerer PROPERTIES OUTPUT_NAME datachannel)
+target_link_libraries(libdatachannel-answerer datachannel)
 
-target_link_libraries(answerer datachannel)

+ 30 - 10
Makefile

@@ -7,21 +7,37 @@ RM=rm -f
 CPPFLAGS=-O2 -pthread -fPIC -Wall -Wno-address-of-packed-member
 CXXFLAGS=-std=c++17
 LDFLAGS=-pthread
-LIBS=glib-2.0 gobject-2.0 nice
+LIBS=
+LOCALLIBS=libusrsctp.a
 USRSCTP_DIR=deps/usrsctp
+JUICE_DIR=deps/libjuice
 PLOG_DIR=deps/plog
 
+INCLUDES=-Iinclude/rtc -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib
+LDLIBS=
+
 USE_GNUTLS ?= 0
 ifneq ($(USE_GNUTLS), 0)
-        CPPFLAGS+= -DUSE_GNUTLS=1
-        LIBS+= gnutls
+        CPPFLAGS+=-DUSE_GNUTLS=1
+        LIBS+=gnutls
 else
-        CPPFLAGS+= -DUSE_GNUTLS=0
-        LIBS+= openssl
+        CPPFLAGS+=-DUSE_GNUTLS=0
+        LIBS+=openssl
 endif
 
-LDLIBS= $(shell pkg-config --libs $(LIBS))
-INCLUDES=-Iinclude/rtc -I$(PLOG_DIR)/include -I$(USRSCTP_DIR)/usrsctplib $(shell pkg-config --cflags $(LIBS))
+USE_JUICE ?= 0
+ifneq ($(USE_JUICE), 0)
+        CPPFLAGS+=-DUSE_JUICE=1
+        INCLUDES+=-I$(JUICE_DIR)/include
+        LOCALLIBS+=libjuice.a
+        LIBS+=nettle
+else
+        CPPFLAGS+=-DUSE_JUICE=0
+        LIBS+=glib-2.0 gobject-2.0 nice
+endif
+
+INCLUDES+=$(shell pkg-config --cflags $(LIBS))
+LDLIBS+=$(LOCALLIBS) $(shell pkg-config --libs $(LIBS))
 
 SRCS=$(shell printf "%s " src/*.cpp)
 OBJS=$(subst .cpp,.o,$(SRCS))
@@ -39,11 +55,11 @@ test/%.o: test/%.cpp
 $(NAME).a: $(OBJS)
 	$(AR) crf $@ $(OBJS)
 
-$(NAME).so: libusrsctp.a $(OBJS)
-	$(CXX) $(LDFLAGS) -shared -o $@ $(OBJS) $(LDLIBS) libusrsctp.a
+$(NAME).so: $(LOCALLIBS) $(OBJS)
+	$(CXX) $(LDFLAGS) -shared -o $@ $(OBJS) $(LDLIBS)
 
 tests: $(NAME).a test/main.o
-	$(CXX) $(LDFLAGS) -o $@ test/main.o $(LDLIBS) $(NAME).a libusrsctp.a
+	$(CXX) $(LDFLAGS) -o $@ test/main.o $(NAME).a $(LDLIBS)
 
 clean:
 	-$(RM) include/rtc/*.d *.d
@@ -67,3 +83,7 @@ libusrsctp.a:
 		make
 	cp $(USRSCTP_DIR)/usrsctplib/.libs/libusrsctp.a .
 
+libjuice.a:
+	cd $(JUICE_DIR) && make
+	cp $(JUICE_DIR)/libjuice.a .
+