From 4eace2b49e608be1c582b07007c1f3e8220ee8ca Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 12 Oct 2015 02:26:35 +0200 Subject: [PATCH] CMake: simplify FindMiniupnpc.cmake miniupnpc.h provides MINIUPNPC_API_VERSION since 1.7 and we require 1.7 or later, so there is no reason to have version detection code for older versions. --- CMakeLists.txt | 12 +- CMakeTests/FindMiniupnpc.cmake | 217 ++--------------------------- Source/Core/Core/NetPlayServer.cpp | 2 +- 3 files changed, 19 insertions(+), 212 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 952cb2290b..1766bee2c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -690,19 +690,17 @@ if(USE_UPNP) if(NOT APPLE AND NOT ANDROID) include(FindMiniupnpc) endif() - if(MINIUPNP_FOUND AND (MINIUPNPC_VERSION_1_7_OR_HIGHER OR MINIUPNPC_VERSION_API14_OR_HIGHER)) + if(MINIUPNPC_FOUND AND MINIUPNPC_API_VERSION GREATER 8) message("Using shared miniupnpc") - include_directories(${MINIUPNP_INCLUDE_DIR}) - if (MINIUPNPC_VERSION_API14_OR_HIGHER) - add_definitions(-DUPNPDISCOVER_HAS_TTL) - endif() else() message("Using static miniupnpc from Externals") add_subdirectory(Externals/miniupnpc) - include_directories(Externals/miniupnpc/src) + set(MINIUPNPC_INCLUDE_DIRS Externals/miniupnpc/src) + set(MINIUPNPC_LIBRARIES miniupnpc) endif() add_definitions(-DUSE_UPNP) - list(APPEND LIBS miniupnpc) + include_directories(${MINIUPNPC_INCLUDE_DIRS}) + list(APPEND LIBS ${MINIUPNPC_LIBRARIES}) endif() if(NOT APPLE AND NOT ANDROID) diff --git a/CMakeTests/FindMiniupnpc.cmake b/CMakeTests/FindMiniupnpc.cmake index 5301d409c5..dd01e3ef72 100644 --- a/CMakeTests/FindMiniupnpc.cmake +++ b/CMakeTests/FindMiniupnpc.cmake @@ -1,208 +1,17 @@ -# Locate miniupnp library -# This module defines -# MINIUPNP_FOUND, if false, do not try to link to miniupnp -# MINIUPNP_LIBRARY, the miniupnp variant -# MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family) -# MINIUPNPC_VERSION_PRE1_6 --> set if we detect the version of miniupnpc is -# pre 1.6 -# MINIUPNPC_VERSION_PRE1_5 --> set if we detect the version of miniupnpc is -# pre 1.5 -# -# Note that the expected include convention is -# #include "miniupnpc.h" -# and not -# #include -# This is because, the miniupnpc location is not standardized and may exist -# in locations other than miniupnpc/ +# This file only works for MiniUPnPc 1.7 or later (it requires MINIUPNPC_API_VERSION). +# TODO Find out if any distribution still ships with /usr/include/miniupnpc.h (i.e. not in a separate directory). -#============================================================================= -# Copyright 2011 Mark Vejvoda -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distributed this file outside of CMake, substitute the full -# License text for the above reference.) +find_path(MINIUPNPC_INCLUDE_DIR miniupnpc.h PATH_SUFFIXES miniupnpc) +find_library(MINIUPNPC_LIBRARY miniupnpc) -if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) - # Already in cache, be silent - set(MINIUPNP_FIND_QUIETLY TRUE) -endif (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) +if(MINIUPNPC_INCLUDE_DIR) + file(STRINGS "${MINIUPNPC_INCLUDE_DIR}/miniupnpc.h" MINIUPNPC_API_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+") + string(REGEX REPLACE "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)" "\\1" MINIUPNPC_API_VERSION ${MINIUPNPC_API_VERSION_STR}) +endif() -find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h - PATH_SUFFIXES miniupnpc) -find_library(MINIUPNP_LIBRARY miniupnpc) - -if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) - set (MINIUPNP_FOUND TRUE) -endif () - -if (MINIUPNP_FOUND) - if (NOT MINIUPNP_FIND_QUIETLY) - message (STATUS "Found the miniupnpc libraries at ${MINIUPNP_LIBRARY}") - message (STATUS "Found the miniupnpc headers at ${MINIUPNP_INCLUDE_DIR}") - endif (NOT MINIUPNP_FIND_QUIETLY) - - 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 - #include - #include - #include - 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_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include - #include - #include - #include - int main() - { - static struct UPNPUrls urls; - static struct IGDdatas data; - - GetUPNPUrls (&urls, &data, \"myurl\",0); - - return 0; - }" - MINIUPNPC_VERSION_1_7_OR_HIGHER) - ENDIF() - -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_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include - #include - #include - #include - 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; - int upnp_error = 0; - devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_7) - ENDIF() - - 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_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include - #include - #include - #include - 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; - int upnp_error = 0; - devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_6) - - ENDIF() - - 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_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include - #include - #include - #include - static struct UPNPUrls urls; - static struct IGDdatas data; - int main() - { - char externalIP[16] = \"\"; - UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP); - - return 0; - }" - MINIUPNPC_VERSION_1_5_OR_HIGHER) - 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 AND NOT MINIUPNPC_VERSION_API14_OR_HIGHER) - set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY}) - check_cxx_source_runs(" - #include - #include - #include - #include - static struct UPNPUrls urls; - static struct IGDdatas data; - int main() - { - char externalIP[16] = \"\"; - UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP); - - return 0; - }" - MINIUPNPC_VERSION_PRE1_5) - -ENDIF() - -IF(MINIUPNPC_VERSION_PRE1_5) - message(STATUS "Found miniupnpc version is pre v1.5") -ENDIF() -IF(MINIUPNPC_VERSION_PRE1_6) - message(STATUS "Found miniupnpc version is pre v1.6") -ENDIF() -IF(MINIUPNPC_VERSION_PRE1_7) - message(STATUS "Found miniupnpc version is pre v1.7") -ENDIF() - -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") -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 () - message (STATUS "Could not find miniupnp") -endif () - -MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MINIUPNPC DEFAULT_MSG MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY MINIUPNPC_API_VERSION) +set(MINIUPNPC_LIBRARIES ${MINIUPNPC_LIBRARY}) +set(MINIUPNPC_INCLUDE_DIRS ${MINIUPNPC_INCLUDE_DIR}) +mark_as_advanced(MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY MINIUPNPC_API_VERSION_STR) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 8bde757c2e..0494825eb6 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -904,7 +904,7 @@ bool NetPlayServer::initUPnP() memset(&m_upnp_data, 0, sizeof(IGDdatas)); // Find all UPnP devices -#ifdef UPNPDISCOVER_HAS_TTL +#if MINIUPNPC_API_VERSION >= 14 UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, 2, &upnperror); #else UPNPDev *devlist = upnpDiscover(2000, nullptr, nullptr, 0, 0, &upnperror);