Merge pull request #3109 from OrdinaryMagician/miniupnpc14

Update to support miniupnpc 1.9 API version 14
This commit is contained in:
Ryan Houdek 2015-09-30 11:08:58 -04:00
commit 0764971feb
3 changed files with 42 additions and 6 deletions

View File

@ -690,9 +690,12 @@ if(USE_UPNP)
if(NOT APPLE AND NOT ANDROID) if(NOT APPLE AND NOT ANDROID)
include(FindMiniupnpc) include(FindMiniupnpc)
endif() endif()
if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER) if(MINIUPNP_FOUND AND (MINIUPNPC_VERSION_1_7_OR_HIGHER OR MINIUPNPC_VERSION_API14_OR_HIGHER))
message("Using shared miniupnpc") message("Using shared miniupnpc")
include_directories(${MINIUPNP_INCLUDE_DIR}) include_directories(${MINIUPNP_INCLUDE_DIR})
if (MINIUPNPC_VERSION_API14_OR_HIGHER)
add_definitions(-DUPNPDISCOVER_HAS_TTL)
endif()
else() else()
message("Using static miniupnpc from Externals") message("Using static miniupnpc from Externals")
add_subdirectory(Externals/miniupnpc) add_subdirectory(Externals/miniupnpc)

View File

@ -49,6 +49,30 @@ if (MINIUPNP_FOUND)
message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}") message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}")
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs("
#include <miniwget.h>
#include <miniupnpc.h>
#include <upnpcommands.h>
#include <stdio.h>
int main()
{
struct UPNPDev *devlist = NULL;
int upnp_delay = 5000;
const char *upnp_multicastif = NULL;
const char *upnp_minissdpdsock = NULL;
int upnp_sameport = 0;
int upnp_ipv6 = 0;
unsigned char upnp_ttl = 2;
int upnp_error = 0;
devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, upnp_ttl, &upnp_error);
return 0;
}"
MINIUPNPC_VERSION_API14_OR_HIGHER)
IF (NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs(" check_cxx_source_runs("
@ -66,8 +90,9 @@ if (MINIUPNP_FOUND)
return 0; return 0;
}" }"
MINIUPNPC_VERSION_1_7_OR_HIGHER) MINIUPNPC_VERSION_1_7_OR_HIGHER)
ENDIF()
IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs(" check_cxx_source_runs("
@ -91,7 +116,7 @@ IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
MINIUPNPC_VERSION_PRE1_7) MINIUPNPC_VERSION_PRE1_7)
ENDIF() ENDIF()
IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs(" check_cxx_source_runs("
@ -116,7 +141,7 @@ IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
ENDIF() ENDIF()
IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs(" check_cxx_source_runs("
@ -136,7 +161,7 @@ IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
MINIUPNPC_VERSION_1_5_OR_HIGHER) MINIUPNPC_VERSION_1_5_OR_HIGHER)
ENDIF() ENDIF()
IF (NOT MINIUPNPC_VERSION_1_5_OR_HIGHER AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER) IF (NOT MINIUPNPC_VERSION_1_5_OR_HIGHER AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
check_cxx_source_runs(" check_cxx_source_runs("
@ -167,10 +192,14 @@ IF(MINIUPNPC_VERSION_PRE1_7)
message(STATUS "Found miniupnpc version is pre v1.7") message(STATUS "Found miniupnpc version is pre v1.7")
ENDIF() ENDIF()
IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7) IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER)
message(STATUS "Found miniupnpc version is v1.7 or higher") message(STATUS "Found miniupnpc version is v1.7 or higher")
ENDIF() ENDIF()
IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
message(STATUS "Found miniupnpc version is v1.9 API version 14 or higher")
ENDIF()
else () else ()
message (STATUS "Could not find miniupnp") message (STATUS "Could not find miniupnp")
endif () endif ()

View File

@ -904,7 +904,11 @@ bool NetPlayServer::initUPnP()
memset(&m_upnp_data, 0, sizeof(IGDdatas)); memset(&m_upnp_data, 0, sizeof(IGDdatas));
// Find all UPnP devices // Find all UPnP devices
#ifdef UPNPDISCOVER_HAS_TTL
UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &upnperror);
#else
UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, &upnperror); UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, &upnperror);
#endif
if (!devlist) if (!devlist)
{ {
WARN_LOG(NETPLAY, "An error occured trying to discover UPnP devices."); WARN_LOG(NETPLAY, "An error occured trying to discover UPnP devices.");