summaryrefslogtreecommitdiff
blob: 80b0806e0c115489de7c3f5790e3638d9d27de11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
From 4e9fec4ce56fda2568a3a656e1f7c59cdbc5fb21 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <chewi@gentoo.org>
Date: Sun, 20 Feb 2022 11:24:24 +0000
Subject: [PATCH 1/3] Allow building against the system miniupnpc library

`USE_INTERNAL_MINIUPNP` defaults to true and ignores `USE_INTERNAL_LIBS` because
users are unlikely to have it installed.

Although miniupnpc uses pkg-config, it doesn't add any include paths to the
flags because it expects your include directives to include the miniupnpc
directory. We should therefore do the same with the internal build so that
either can be used.

Bug: https://github.com/odamex/odamex/issues/261
(cherry picked from commit 1832a4a1c06504de953cdec2413a47ee393101c7)
---
 CMakeLists.txt           | 1 +
 common/i_net.cpp         | 7 +++----
 libraries/CMakeLists.txt | 4 ++--
 server/CMakeLists.txt    | 8 +++++++-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fd17dd36b..c43c9f111 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,7 @@ cmake_dependent_option( USE_INTERNAL_CURL "Use internal libcurl" ${USE_INTERNAL_
 cmake_dependent_option( USE_INTERNAL_WXWIDGETS "Use internal wxWidgets" ${USE_INTERNAL_LIBS} BUILD_LAUNCHER 0 )
 cmake_dependent_option( ENABLE_PORTMIDI "Enable portmidi support" 1 BUILD_CLIENT 0 )
 cmake_dependent_option( USE_MINIUPNP "Build with UPnP support" 1 BUILD_SERVER 0 )
+cmake_dependent_option( USE_INTERNAL_MINIUPNP "Use internal MiniUPnP" 1 USE_MINIUPNP 0 )
 
 set(PROJECT_COPYRIGHT "2006-2022")
 set(PROJECT_RC_VERSION "10,0,0,0")
diff --git a/common/i_net.cpp b/common/i_net.cpp
index 27b218d0d..dba512346 100644
--- a/common/i_net.cpp
+++ b/common/i_net.cpp
@@ -93,10 +93,9 @@ typedef int SOCKET;
 #include "minilzo.h"
 
 #ifdef ODA_HAVE_MINIUPNP
-#define MINIUPNP_STATICLIB
-#include "miniwget.h"
-#include "miniupnpc.h"
-#include "upnpcommands.h"
+#include "miniupnpc/miniwget.h"
+#include "miniupnpc/miniupnpc.h"
+#include "miniupnpc/upnpcommands.h"
 #endif
 
 unsigned int	inet_socket;
diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt
index 1785ed0d8..ae7db4c86 100644
--- a/libraries/CMakeLists.txt
+++ b/libraries/CMakeLists.txt
@@ -350,7 +350,7 @@ endif()
 ### MiniUPnPc ###
 if(BUILD_SERVER AND NOT USE_MINIUPNP)
   message(STATUS "Skipping MiniUPnPc...")
-elseif(BUILD_SERVER AND USE_MINIUPNP)
+elseif(BUILD_SERVER AND USE_MINIUPNP AND USE_INTERNAL_MINIUPNP)
   message(STATUS "Compiling MiniUPnPc...")
 
   # Figure out the correct library path to attach to our imported target
@@ -386,7 +386,7 @@ elseif(BUILD_SERVER AND USE_MINIUPNP)
   # Synthesize an imported target that can be linked against.
   add_library(upnpc-static STATIC IMPORTED GLOBAL)
   set_target_properties(upnpc-static PROPERTIES
-    INTERFACE_INCLUDE_DIRECTORIES "${MINIUPNPC_INCLUDE_DIR}"
+    INTERFACE_COMPILE_DEFINITIONS MINIUPNP_STATICLIB
     IMPORTED_LOCATION ${MINIUPNPC_LIBRARY})
   if(WIN32)
     set_target_properties(upnpc-static PROPERTIES INTERFACE_LINK_LIBRARIES "ws2_32;iphlpapi")
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index c9fa17b64..32297080f 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -54,7 +54,13 @@ endif()
 target_link_libraries(odasrv ZLIB::ZLIB jsoncpp odamex-common odaproto)
 
 if(USE_MINIUPNP)
-  target_link_libraries(odasrv upnpc-static)
+  if(USE_INTERNAL_MINIUPNP)
+    target_link_libraries(odasrv upnpc-static)
+  else()
+    find_package(PkgConfig REQUIRED)
+    pkg_check_modules(MINIUPNPC miniupnpc REQUIRED IMPORTED_TARGET)
+    target_link_libraries(odasrv PkgConfig::MINIUPNPC)
+  endif()
 endif()
 
 if(WIN32)
-- 
2.34.1