Attempt to detect best UPnP library available

Because we don't support libupnp-1.8.x yet avoid using that library
If libupnp-1.6.x is available use that, if not try to use miniupnc if
  if unavailble print a warning and disable RetroShare UPnP support
This commit is contained in:
Gioacchino Mazzurco 2019-04-24 18:08:35 +02:00
parent 2498f945f4
commit fb4f206427
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
3 changed files with 56 additions and 9 deletions

View File

@ -653,7 +653,11 @@ SOURCES += util/folderiterator.cc \
equals(RS_UPNP_LIB, miniupnpc) { equals(RS_UPNP_LIB, miniupnpc) {
HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h HEADERS += upnp/upnputil.h upnp/upnphandler_miniupnp.h
SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc SOURCES += upnp/upnputil.c upnp/upnphandler_miniupnp.cc
} else { }
equals(RS_UPNP_LIB, "upnp ixml") { ## libupnp-1.8.x
# Not supported yet
}
equals(RS_UPNP_LIB, "upnp ixml threadutil") { ## libupnp-1.6.x
HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h HEADERS += upnp/UPnPBase.h upnp/upnphandler_linux.h
SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc SOURCES += upnp/UPnPBase.cpp upnp/upnphandler_linux.cc
DEFINES *= RS_USE_LIBUPNP DEFINES *= RS_USE_LIBUPNP

View File

@ -1586,9 +1586,11 @@ int RsServer::StartupRetroShare()
mNetMgr->addNetListener(mProxyStack); mNetMgr->addNetListener(mProxyStack);
#endif #endif
#if defined(RS_USE_LIBMINIUPNPC) || defined(RS_USE_LIBUPNP)
// Original UPnP Interface. // Original UPnP Interface.
pqiNetAssistFirewall *mUpnpMgr = new upnphandler(); pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
mNetMgr->addNetAssistFirewall(1, mUpnpMgr); mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
#endif // defined(RS_USE_LIBMINIUPNPC) || defined(RS_USE_LIBUPNP)
} }
/**************************************************************************/ /**************************************************************************/

View File

@ -203,10 +203,17 @@ no_rs_broadcast_discovery:CONFIG -= rs_broadcast_discovery
# use (pthread, "") usually depends on platform. # use (pthread, "") usually depends on platform.
isEmpty(RS_THREAD_LIB):RS_THREAD_LIB = pthread isEmpty(RS_THREAD_LIB):RS_THREAD_LIB = pthread
# Specify UPnP library to use appending the following assignation to qmake # Specify UPnP library to use, appending the following assignation to qmake
# command line 'RS_UPNP_LIB=miniupnpc' the name of the UPNP library to use # command line
# (miniupnpc, "upnp ixml threadutil") usually depends on platform. # 'RS_UPNP_LIB=none' do not compile UPnP support
isEmpty(RS_UPNP_LIB):RS_UPNP_LIB = upnp ixml threadutil # 'RS_UPNP_LIB=miniupnpc' to use miniupnpc
# 'RS_UPNP_LIB="upnp ixml threadutil"' to use libupnp-1.6.x
# 'RS_UPNP_LIB="upnp ixml"' to use libupnp-1.8.x
# Which library is better suited usually depends on the platform.
# See http://miniupnp.free.fr/ and http://pupnp.sourceforge.net/ for more
# information about the libraries. Autodetection is attempted by default.
#RS_UPNP_LIB=
########################################################################################################################################################### ###########################################################################################################################################################
# #
@ -302,7 +309,7 @@ defineReplace(linkStaticLibs) {
return($$retSlib) return($$retSlib)
} }
## This function return pretarget deps for the static the libraries contained in ## This function return pretarget deps for the static libraries contained in
## the variable given as paramether. ## the variable given as paramether.
defineReplace(pretargetStaticLibs) { defineReplace(pretargetStaticLibs) {
libsVarName = $$1 libsVarName = $$1
@ -705,6 +712,40 @@ macx-* {
QT += macextras QT += macextras
} }
# If not yet defined attempt UPnP library autodetection should works at least
# for miniupnc libupnp-1.6.x and libupnp-1.8.x
isEmpty(RS_UPNP_LIB) {
__TEMP_UPNP_LIBS = upnp ixml threadutil
for(mLib, __TEMP_UPNP_LIBS) {
attemptPath=$$findFileInPath(lib$${mLib}.a, QMAKE_LIBDIR)
isEmpty(attemptPath):attemptPath=$$findFileInPath(lib$${mLib}.so, QMAKE_LIBDIR)
!isEmpty(attemptPath):RS_UPNP_LIB += $${mLib}
}
## Workaround as libupnp-1.8.x is not supported yet
equals(RS_UPNP_LIB, "upnp ixml"):RS_UPNP_LIB=
## END Workaround as libupnp-1.8.x is not supported yet
isEmpty(RS_UPNP_LIB) {
__TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.a, QMAKE_LIBDIR)
!isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc
__TEMP_UPNP_LIBS=$$findFileInPath(libminiupnpc.so, QMAKE_LIBDIR)
!isEmpty(__TEMP_UPNP_LIBS):RS_UPNP_LIB=miniupnpc
}
isEmpty(RS_UPNP_LIB) {
warning("RS_UPNP_LIB detection failed, UPnP support disabled!")
} else {
message("Autodetected RS_UPNP_LIB=$$RS_UPNP_LIB")
}
}
equals(RS_UPNP_LIB, none):RS_UPNP_LIB=
equals(RS_UPNP_LIB, miniupnpc):DEFINES*=RS_USE_LIBMINIUPNPC
equals(RS_UPNP_LIB, "upnp ixml"):DEFINES*=RS_USE_LIBUPNP_1_8_X
## libupnp-1.6.x
equals(RS_UPNP_LIB, "upnp ixml threadutil"):DEFINES*=RS_USE_LIBUPNP
## Retrocompatibility assignations, get rid of this ASAP ## Retrocompatibility assignations, get rid of this ASAP
isEmpty(BIN_DIR) : BIN_DIR = $${RS_BIN_DIR} isEmpty(BIN_DIR) : BIN_DIR = $${RS_BIN_DIR}