FindMiniupnpc.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Locate miniupnp library
  2. # This module defines
  3. # MINIUPNP_FOUND, if false, do not try to link to miniupnp
  4. # MINIUPNP_LIBRARY, the miniupnp variant
  5. # MINIUPNP_INCLUDE_DIR, where to find miniupnpc.h and family)
  6. # MINIUPNPC_VERSION_PRE1_6 --> set if we detect the version of miniupnpc is
  7. # pre 1.6
  8. # MINIUPNPC_VERSION_PRE1_5 --> set if we detect the version of miniupnpc is
  9. # pre 1.5
  10. #
  11. # Note that the expected include convention is
  12. # #include "miniupnpc.h"
  13. # and not
  14. # #include <miniupnpc/miniupnpc.h>
  15. # This is because, the miniupnpc location is not standardized and may exist
  16. # in locations other than miniupnpc/
  17. #=============================================================================
  18. # Copyright 2011 Mark Vejvoda
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distributed this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
  30. # Already in cache, be silent
  31. set(MINIUPNP_FIND_QUIETLY TRUE)
  32. endif (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
  33. find_path(MINIUPNP_INCLUDE_DIR miniupnpc.h
  34. PATH_SUFFIXES miniupnpc)
  35. find_library(MINIUPNP_LIBRARY miniupnpc)
  36. if (MINIUPNP_INCLUDE_DIR AND MINIUPNP_LIBRARY)
  37. set (MINIUPNP_FOUND TRUE)
  38. endif ()
  39. if (MINIUPNP_FOUND)
  40. if (NOT MINIUPNP_FIND_QUIETLY)
  41. message (STATUS "Found the miniupnpc libraries at ${MINIUPNP_LIBRARY}")
  42. message (STATUS "Found the miniupnpc headers at ${MINIUPNP_INCLUDE_DIR}")
  43. endif (NOT MINIUPNP_FIND_QUIETLY)
  44. message(STATUS "Detecting version of miniupnpc in path: ${MINIUPNP_INCLUDE_DIR}")
  45. set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
  46. set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
  47. check_cxx_source_runs("
  48. #include <miniwget.h>
  49. #include <miniupnpc.h>
  50. #include <upnpcommands.h>
  51. #include <stdio.h>
  52. int main()
  53. {
  54. static struct UPNPUrls urls;
  55. static struct IGDdatas data;
  56. GetUPNPUrls (&urls, &data, \"myurl\",0);
  57. return 0;
  58. }"
  59. MINIUPNPC_VERSION_1_7_OR_HIGHER)
  60. IF (NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
  61. set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
  62. set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
  63. check_cxx_source_runs("
  64. #include <miniwget.h>
  65. #include <miniupnpc.h>
  66. #include <upnpcommands.h>
  67. #include <stdio.h>
  68. int main()
  69. {
  70. struct UPNPDev *devlist = NULL;
  71. int upnp_delay = 5000;
  72. const char *upnp_multicastif = NULL;
  73. const char *upnp_minissdpdsock = NULL;
  74. int upnp_sameport = 0;
  75. int upnp_ipv6 = 0;
  76. int upnp_error = 0;
  77. devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport, upnp_ipv6, &upnp_error);
  78. return 0;
  79. }"
  80. MINIUPNPC_VERSION_PRE1_7)
  81. ENDIF()
  82. IF (NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
  83. set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
  84. set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
  85. check_cxx_source_runs("
  86. #include <miniwget.h>
  87. #include <miniupnpc.h>
  88. #include <upnpcommands.h>
  89. #include <stdio.h>
  90. int main()
  91. {
  92. struct UPNPDev *devlist = NULL;
  93. int upnp_delay = 5000;
  94. const char *upnp_multicastif = NULL;
  95. const char *upnp_minissdpdsock = NULL;
  96. int upnp_sameport = 0;
  97. int upnp_ipv6 = 0;
  98. int upnp_error = 0;
  99. devlist = upnpDiscover(upnp_delay, upnp_multicastif, upnp_minissdpdsock, upnp_sameport);
  100. return 0;
  101. }"
  102. MINIUPNPC_VERSION_PRE1_6)
  103. ENDIF()
  104. IF (NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7 AND NOT MINIUPNPC_VERSION_1_7_OR_HIGHER)
  105. set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
  106. set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
  107. check_cxx_source_runs("
  108. #include <miniwget.h>
  109. #include <miniupnpc.h>
  110. #include <upnpcommands.h>
  111. #include <stdio.h>
  112. static struct UPNPUrls urls;
  113. static struct IGDdatas data;
  114. int main()
  115. {
  116. char externalIP[16] = \"\";
  117. UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIP);
  118. return 0;
  119. }"
  120. MINIUPNPC_VERSION_1_5_OR_HIGHER)
  121. ENDIF()
  122. 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)
  123. set(CMAKE_REQUIRED_INCLUDES ${MINIUPNP_INCLUDE_DIR})
  124. set(CMAKE_REQUIRED_LIBRARIES ${MINIUPNP_LIBRARY})
  125. check_cxx_source_runs("
  126. #include <miniwget.h>
  127. #include <miniupnpc.h>
  128. #include <upnpcommands.h>
  129. #include <stdio.h>
  130. static struct UPNPUrls urls;
  131. static struct IGDdatas data;
  132. int main()
  133. {
  134. char externalIP[16] = \"\";
  135. UPNP_GetExternalIPAddress(urls.controlURL, data.servicetype, externalIP);
  136. return 0;
  137. }"
  138. MINIUPNPC_VERSION_PRE1_5)
  139. ENDIF()
  140. IF(MINIUPNPC_VERSION_PRE1_5)
  141. message(STATUS "Found miniupnpc version is pre v1.5")
  142. ENDIF()
  143. IF(MINIUPNPC_VERSION_PRE1_6)
  144. message(STATUS "Found miniupnpc version is pre v1.6")
  145. ENDIF()
  146. IF(MINIUPNPC_VERSION_PRE1_7)
  147. message(STATUS "Found miniupnpc version is pre v1.7")
  148. ENDIF()
  149. IF(NOT MINIUPNPC_VERSION_PRE1_5 AND NOT MINIUPNPC_VERSION_PRE1_6 AND NOT MINIUPNPC_VERSION_PRE1_7)
  150. message(STATUS "Found miniupnpc version is v1.7 or higher")
  151. ENDIF()
  152. else ()
  153. message (STATUS "Could not find miniupnp")
  154. endif ()
  155. MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY)