Fixed compilation on MSVC

This commit is contained in:
Paul-Louis Ageneau
2020-06-21 20:37:27 +02:00
parent bcd1972270
commit f3024d0552
5 changed files with 107 additions and 17 deletions

102
Jamfile
View File

@ -3,6 +3,12 @@ import feature : feature ;
project libdatachannel ; project libdatachannel ;
path-constant CWD : . ; path-constant CWD : . ;
feature gnutls : off on : composite propagated ;
feature.compose <gnutls>off
: <define>USE_GNUTLS=0 ;
feature.compose <gnutls>on
: <define>USE_GNUTLS=1 ;
lib libdatachannel lib libdatachannel
: # sources : # sources
[ glob ./src/*.cpp ] [ glob ./src/*.cpp ]
@ -12,9 +18,15 @@ lib libdatachannel
<define>USE_JUICE=1 <define>USE_JUICE=1
<define>RTC_ENABLE_MEDIA=0 <define>RTC_ENABLE_MEDIA=0
<define>RTC_ENABLE_WEBSOCKET=0 <define>RTC_ENABLE_WEBSOCKET=0
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
<toolset>msvc:<define>NOMINMAX
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
<toolset>msvc:<define>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
<library>/libdatachannel//usrsctp <library>/libdatachannel//usrsctp
<library>/libdatachannel//juice <library>/libdatachannel//juice
<library>/libdatachannel//plog <library>/libdatachannel//plog
<gnutls>off:<library>ssl
<gnutls>off:<library>crypto
: # default build : # default build
<link>static <link>static
: # usage requirements : # usage requirements
@ -22,15 +34,8 @@ lib libdatachannel
<library>/libdatachannel//plog <library>/libdatachannel//plog
<toolset>gcc:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable" <toolset>gcc:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
<toolset>clang:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable" <toolset>clang:<cxxflags>"-pthread -Wno-pedantic -Wno-unused-parameter -Wno-unused-variable"
<toolset>msvc:<cxxflags>"/DWIN32_LEAN_AND_MEAN /DNOMINMAX /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING"
; ;
feature gnutls : off on : composite propagated ;
feature.compose <gnutls>off
: <define>USE_GNUTLS=0 ;
feature.compose <gnutls>on
: <define>USE_GNUTLS=1 ;
alias plog alias plog
: # no sources : # no sources
: # no build requirements : # no build requirements
@ -85,7 +90,7 @@ actions make_libusrsctp
} }
actions make_libusrsctp_msvc actions make_libusrsctp_msvc
{ {
(cd $(CWD)/deps/usrsctp && cmake -B build -G "NMake Makefiles" && cd build && nmake usrsctplib-static) (cd $(CWD)/deps/usrsctp && cmake -B build -G "Visual Studio 16 2019" && cd build && msbuild usrsctplib.sln)
cp $(CWD)/deps/usrsctp/build/usrsctplib/libusrsctp.lib $(<) cp $(CWD)/deps/usrsctp/build/usrsctplib/libusrsctp.lib $(<)
} }
@ -121,7 +126,86 @@ rule make_libjuice_msvc ( targets * : sources * : properties * )
} }
actions make_libjuice_msvc actions make_libjuice_msvc
{ {
(cd $(CWD)/deps/libjuice && cmake -B build -G "NMake Makefiles" $(CMAKEOPTS) && cd build && nmake juice-static) (cd $(CWD)/deps/libjuice && cmake -B build -G "Visual Studio 16 2019" $(CMAKEOPTS) && cd build && msbuild libjuice.sln)
cp $(CWD)/deps/libjuice/build/libjuice-static.lib $(<) cp $(CWD)/deps/libjuice/build/libjuice-static.lib $(<)
} }
# the search path to pick up the openssl libraries from. This is the <search>
# property of those libraries
rule openssl-lib-path ( properties * )
{
local OPENSSL_LIB = [ feature.get-values <openssl-lib> : $(properties) ] ;
if <target-os>darwin in $(properties) && $(OPENSSL_LIB) = ""
{
# on macOS, default to pick up openssl from the homebrew installation
# brew install openssl
OPENSSL_LIB = /usr/local/opt/openssl/lib ;
}
else if <target-os>windows in $(properties) && $(OPENSSL_LIB) = ""
{
# on windows, assume openssl is installed to c:\OpenSSL-Win32
if <address-model>64 in $(properties)
{ OPENSSL_LIB = c:\\OpenSSL-Win64\\lib ; }
else
{ OPENSSL_LIB = c:\\OpenSSL-Win32\\lib ; }
}
local result ;
result += <search>$(OPENSSL_LIB) ;
return $(result) ;
}
# the include path to pick up openssl headers from. This is the
# usage-requirement for the openssl-related libraries
rule openssl-include-path ( properties * )
{
local OPENSSL_INCLUDE = [ feature.get-values <openssl-include> : $(properties) ] ;
if <target-os>darwin in $(properties) && $(OPENSSL_INCLUDE) = ""
{
# on macOS, default to pick up openssl from the homebrew installation
# brew install openssl
OPENSSL_INCLUDE = /usr/local/opt/openssl/include ;
}
else if <target-os>windows in $(properties) && $(OPENSSL_INCLUDE) = ""
{
# on windows, assume openssl is installed to c:\OpenSSL-Win32
if <address-model>64 in $(properties)
{ OPENSSL_INCLUDE = c:\\OpenSSL-Win64\\include ; }
else
{ OPENSSL_INCLUDE = c:\\OpenSSL-Win32\\include ; }
}
local result ;
result += <include>$(OPENSSL_INCLUDE) ;
return $(result) ;
}
# libraries for openssl on windows
lib advapi32 : : <name>advapi32 ;
lib user32 : : <name>user32 ;
lib shell32 : : <name>shell32 ;
lib gdi32 : : <name>gdi32 ;
lib bcrypt : : <name>bcrypt ;
lib z : : <link>shared <name>z ;
alias ssl-deps : advapi32 user32 shell32 gdi32 ;
# pre OpenSSL 1.1 windows
lib crypto : ssl-deps : <target-os>windows <openssl-version>pre1.1 <name>libeay32
<conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
lib ssl : ssl-deps : <target-os>windows <openssl-version>pre1.1 <name>ssleay32
<use>crypto <conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
# OpenSSL 1.1+ windows
lib crypto : ssl-deps : <toolset>msvc <openssl-version>1.1 <name>libcrypto
<conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
lib ssl : ssl-deps : <toolset>msvc <openssl-version>1.1 <name>libssl <use>crypto
<conditional>@openssl-lib-path : : <conditional>@openssl-include-path ;
# generic OpenSSL
lib crypto : : <name>crypto <use>z <conditional>@openssl-lib-path : :
<conditional>@openssl-include-path ;
lib ssl : : <name>ssl <use>crypto <conditional>@openssl-lib-path : :
<conditional>@openssl-include-path ;

View File

@ -428,7 +428,7 @@ void DtlsTransport::runRecvLoop() {
if (state() == State::Connecting) { if (state() == State::Connecting) {
// Continue the handshake // Continue the handshake
int ret = SSL_do_handshake(mSsl); ret = SSL_do_handshake(mSsl);
if (!openssl::check(mSsl, ret, "Handshake failed")) if (!openssl::check(mSsl, ret, "Handshake failed"))
break; break;
@ -442,7 +442,7 @@ void DtlsTransport::runRecvLoop() {
postHandshake(); postHandshake();
} }
} else { } else {
int ret = SSL_read(mSsl, buffer, bufferSize); ret = SSL_read(mSsl, buffer, bufferSize);
if (!openssl::check(mSsl, ret)) if (!openssl::check(mSsl, ret))
break; break;
@ -455,7 +455,7 @@ void DtlsTransport::runRecvLoop() {
std::optional<milliseconds> duration; std::optional<milliseconds> duration;
if (state() == State::Connecting) { if (state() == State::Connecting) {
// Warning: This function breaks the usual return value convention // Warning: This function breaks the usual return value convention
int ret = DTLSv1_handle_timeout(mSsl); ret = DTLSv1_handle_timeout(mSsl);
if (ret < 0) { if (ret < 0) {
throw std::runtime_error("Handshake timeout"); // write BIO can't fail throw std::runtime_error("Handshake timeout"); // write BIO can't fail
} else if (ret > 0) { } else if (ret > 0) {

View File

@ -483,7 +483,7 @@ void PeerConnection::forwardMessage(message_ptr message) {
return; return;
} }
auto channel = findDataChannel(message->stream); auto channel = findDataChannel(uint16_t(message->stream));
auto iceTransport = std::atomic_load(&mIceTransport); auto iceTransport = std::atomic_load(&mIceTransport);
auto sctpTransport = std::atomic_load(&mSctpTransport); auto sctpTransport = std::atomic_load(&mSctpTransport);
@ -658,7 +658,8 @@ void PeerConnection::resetCallbacks() {
mGatheringStateChangeCallback = nullptr; mGatheringStateChangeCallback = nullptr;
} }
bool PeerConnection::getSelectedCandidatePair(CandidateInfo *local, CandidateInfo *remote) { bool PeerConnection::getSelectedCandidatePair([[maybe_unused]] CandidateInfo *local,
[[maybe_unused]] CandidateInfo *remote) {
#if USE_JUICE #if USE_JUICE
PLOG_WARNING << "getSelectedCandidatePair() is not implemented for libjuice"; PLOG_WARNING << "getSelectedCandidatePair() is not implemented for libjuice";
return false; return false;

View File

@ -448,8 +448,8 @@ bool SctpTransport::safeFlush() {
} }
} }
int SctpTransport::handleRecv(struct socket *sock, union sctp_sockstore addr, const byte *data, int SctpTransport::handleRecv(struct socket * /*sock*/, union sctp_sockstore /*addr*/,
size_t len, struct sctp_rcvinfo info, int flags) { const byte *data, size_t len, struct sctp_rcvinfo info, int flags) {
try { try {
PLOG_VERBOSE << "Handle recv, len=" << len; PLOG_VERBOSE << "Handle recv, len=" << len;
if (!len) if (!len)
@ -500,7 +500,7 @@ int SctpTransport::handleSend(size_t free) {
return safeFlush() ? 0 : -1; return safeFlush() ? 0 : -1;
} }
int SctpTransport::handleWrite(byte *data, size_t len, uint8_t tos, uint8_t set_df) { int SctpTransport::handleWrite(byte *data, size_t len, uint8_t /*tos*/, uint8_t /*set_df*/) {
try { try {
PLOG_VERBOSE << "Handle write, len=" << len; PLOG_VERBOSE << "Handle write, len=" << len;

View File

@ -48,6 +48,11 @@ gnutls_datum_t make_datum(char *data, size_t size);
#else // USE_GNUTLS==0 #else // USE_GNUTLS==0
#ifdef _WIN32
// Include winsock2.h header first since OpenSSL may include winsock.h
#include <winsock2.h>
#endif
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/bio.h> #include <openssl/bio.h>