From d0d432f204c5f4da90291b812e7e89809b26266a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 5 Jun 2012 21:45:54 +0000 Subject: [PATCH] - cmake now dynamically detects some versions of miniupnpc --- mk/cmake/Modules/FindMiniupnpc.cmake | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/mk/cmake/Modules/FindMiniupnpc.cmake b/mk/cmake/Modules/FindMiniupnpc.cmake index 75e00ab6..a2d0ec53 100644 --- a/mk/cmake/Modules/FindMiniupnpc.cmake +++ b/mk/cmake/Modules/FindMiniupnpc.cmake @@ -3,6 +3,10 @@ # 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" @@ -42,6 +46,105 @@ if (MINIUPNP_FOUND) 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; + int upnp_error = 0; + devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error); + + return 0; + }" + MINIUPNPC_VERSION_1_6_OR_HIGHER) + + IF (NOT MINIUPNPC_VERSION_1_6_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() + + 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) + + IF (NOT MINIUPNPC_VERSION_1_5_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(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6) + message(STATUS "Found miniupnpc version is v1.6 or higher") + ENDIF() + else () message (STATUS "Could not find miniupnp") endif ()