From 194b88bf4fe5f8b27d7175f1051af88b32ac98b0 Mon Sep 17 00:00:00 2001 From: wowario Date: Sun, 15 Dec 2024 09:59:35 +0300 Subject: [PATCH] Revert "cmake: remove extera cmake/FindMiniupnpc.cmake and only rely on external/miniupnpc." This reverts commit 31f5bc908dc2f782267402b07101ea1fefa30efc. --- cmake/FindMiniupnpc.cmake | 59 +++++++++++++++++++++++++++++++++++++++ external/CMakeLists.txt | 2 ++ 2 files changed, 61 insertions(+) create mode 100644 cmake/FindMiniupnpc.cmake diff --git a/cmake/FindMiniupnpc.cmake b/cmake/FindMiniupnpc.cmake new file mode 100644 index 000000000..ad2004afc --- /dev/null +++ b/cmake/FindMiniupnpc.cmake @@ -0,0 +1,59 @@ +# --------------------------------- FindMiniupnpc Start --------------------------------- +# 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_1_7_OR_HIGHER, set if we detect the version of miniupnpc is 1.7 or higher +# +# 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/ + +if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY) + # Already in cache, be silent + set(MINIUPNP_FIND_QUIETLY TRUE) +endif () + +find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h + HINTS $ENV{MINIUPNP_INCLUDE_DIR} + PATH_SUFFIXES miniupnpc +) + +find_library(MINIUPNP_LIBRARY miniupnpc + HINTS $ENV{MINIUPNP_LIBRARY} +) + +find_library(MINIUPNP_STATIC_LIBRARY libminiupnpc.a + HINTS $ENV{MINIUPNP_STATIC_LIBRARY} +) + +set(MINIUPNP_INCLUDE_DIRS ${MINIUPNP_INCLUDE_DIR}) +set(MINIUPNP_LIBRARIES ${MINIUPNP_LIBRARY}) +set(MINIUPNP_STATIC_LIBRARIES ${MINIUPNP_STATIC_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + MiniUPnPc DEFAULT_MSG + MINIUPNP_INCLUDE_DIR + MINIUPNP_LIBRARY +) + +IF(MINIUPNPC_FOUND) + file(STRINGS "${MINIUPNP_INCLUDE_DIR}/miniupnpc.h" MINIUPNPC_API_VERSION_STR REGEX "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+[0-9]+") + if(MINIUPNPC_API_VERSION_STR MATCHES "^#define[\t ]+MINIUPNPC_API_VERSION[\t ]+([0-9]+)") + set(MINIUPNPC_API_VERSION "${CMAKE_MATCH_1}") + if (${MINIUPNPC_API_VERSION} GREATER "10" OR ${MINIUPNPC_API_VERSION} EQUAL "10") + message(STATUS "Found miniupnpc API version " ${MINIUPNPC_API_VERSION}) + set(MINIUPNP_FOUND true) + set(MINIUPNPC_VERSION_1_7_OR_HIGHER true) + endif() + endif() + +ENDIF() + +mark_as_advanced(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY MINIUPNP_STATIC_LIBRARY) +# --------------------------------- FindMiniupnpc End --------------------------------- diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 5f2ed58df..29aed0cc6 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -35,6 +35,8 @@ # ...except for FreeBSD, because FreeBSD is a special case that doesn't play well with # others. +find_package(Miniupnpc REQUIRED) + message(STATUS "Using in-tree miniupnpc") set(UPNPC_NO_INSTALL TRUE CACHE BOOL "Disable miniupnp installation" FORCE) add_subdirectory(miniupnp/miniupnpc)