aboutsummaryrefslogtreecommitdiff
path: root/external/CMakeLists.txt
blob: d220786e56eb03ab4fe1a768a83b91abf7a17fb8 (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# 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 <miniupnpc/miniupnpc.h>
# This is because, the miniupnpc location is not standardized and may exist
# in locations other than miniupnpc/

#=============================================================================
# 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.)

if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
	# Already in cache, be silent
	set(MINIUPNP_FIND_QUIETLY TRUE)
endif (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)

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)
	include(CheckCXXSourceRuns)
	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 <miniwget.h>
	#include <miniupnpc.h>
	#include <upnpcommands.h>
	#include <stdio.h>
	int main()
	{
	static struct UPNPUrls urls;
	static struct IGDdatas data;

	GetUPNPUrls (&urls, &data, \"myurl\",0);

	return 0;
	}"
	MINIUPNPC_VERSION_1_7_OR_HIGHER)

IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
	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;
	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)
	   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;
	   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)
	   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>
	   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)
		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>
		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)
	message(STATUS "Found miniupnpc version is v1.7 or higher")
ENDIF()

else ()
	message (STATUS "Could not find miniupnp")
endif ()

MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY)

# And now on to the Monero part of things

if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER)
  message(STATUS "Using shared miniupnpc found at ${MINIUPNP_INCLUDE_DIR}")

  set(UPNP_STATIC false PARENT_SCOPE)
  set(UPNP_INCLUDE ${MINIUPNP_INCLUDE_DIR} PARENT_SCOPE)
  set(UPNP_LIBRARIES ${MINIUPNP_LIBRARY} PARENT_SCOPE)
else()
  message(STATUS "Using static miniupnpc from external")

  set(UPNPC_BUILD_STATIC ON CACHE BOOL "Build static library")
  set(UPNPC_BUILD_SHARED OFF CACHE BOOL "Build shared library")
  set(UPNPC_BUILD_TESTS OFF CACHE BOOL "Build test executables")
  add_subdirectory(miniupnpc)

  set_property(TARGET upnpc-static PROPERTY FOLDER "external")
  if(MSVC)
    set_property(TARGET upnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267")
  elseif(NOT MSVC)
    set_property(TARGET upnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-unused-result -Wno-unused-value")
  endif()

  set(UPNP_STATIC true PARENT_SCOPE)
  set(UPNP_LIBRARIES "upnpc-static")
endif()