CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. cmake_minimum_required (VERSION 2.6)
  2. project (miniupnpc C)
  3. set (MINIUPNPC_VERSION 1.9)
  4. set (MINIUPNPC_API_VERSION 15)
  5. if (NOT CMAKE_BUILD_TYPE)
  6. if (WIN32)
  7. set (DEFAULT_BUILD_TYPE MinSizeRel)
  8. else (WIN32)
  9. set (DEFAULT_BUILD_TYPE RelWithDebInfo)
  10. endif(WIN32)
  11. set (CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING
  12. "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
  13. FORCE)
  14. endif()
  15. option (UPNPC_BUILD_STATIC "Build static library" TRUE)
  16. option (UPNPC_BUILD_SHARED "Build shared library" TRUE)
  17. if (NOT WIN32)
  18. option (UPNPC_BUILD_TESTS "Build test executables" TRUE)
  19. endif (NOT WIN32)
  20. option (NO_GETADDRINFO "Define NO_GETADDRINFO" FALSE)
  21. mark_as_advanced (NO_GETADDRINFO)
  22. if (NO_GETADDRINFO)
  23. add_definitions (-DNO_GETADDRINFO)
  24. endif (NO_GETADDRINFO)
  25. if (NOT WIN32)
  26. add_definitions (-DMINIUPNPC_SET_SOCKET_TIMEOUT)
  27. add_definitions (-D_BSD_SOURCE -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200112L)
  28. else (NOT WIN32)
  29. add_definitions (-D_WIN32_WINNT=0x0501) # XP or higher for getnameinfo and friends
  30. endif (NOT WIN32)
  31. if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  32. add_definitions (-D_DARWIN_C_SOURCE)
  33. endif ()
  34. # Set compiler specific build flags
  35. if (CMAKE_COMPILER_IS_GNUC)
  36. # Set our own default flags at first run.
  37. if (NOT CONFIGURED)
  38. if (NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
  39. set (_PIC -fPIC)
  40. endif (CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
  41. set (CMAKE_C_FLAGS "${_PIC} -Wall $ENV{CFLAGS}" # CMAKE_C_FLAGS gets appended to the other C flags
  42. CACHE STRING "Flags used by the C compiler during normal builds." FORCE)
  43. set (CMAKE_C_FLAGS_DEBUG "-g -DDDEBUG"
  44. CACHE STRING "Flags used by the C compiler during debug builds." FORCE)
  45. set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG"
  46. CACHE STRING "Flags used by the C compiler during release builds." FORCE)
  47. set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG"
  48. CACHE STRING "Flags used by the C compiler during release builds." FORCE)
  49. set (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG"
  50. CACHE STRING "Flags used by the C compiler during release builds." FORCE)
  51. endif (NOT CONFIGURED)
  52. endif ()
  53. configure_file (${CMAKE_SOURCE_DIR}/miniupnpcstrings.h.cmake ${CMAKE_BINARY_DIR}/miniupnpcstrings.h)
  54. include_directories (${CMAKE_BINARY_DIR})
  55. set (MINIUPNPC_SOURCES
  56. igd_desc_parse.c
  57. miniupnpc.c
  58. minixml.c
  59. minisoap.c
  60. minissdpc.c
  61. miniwget.c
  62. upnpc.c
  63. upnpcommands.c
  64. upnpdev.c
  65. upnpreplyparse.c
  66. upnperrors.c
  67. connecthostport.c
  68. portlistingparse.c
  69. receivedata.c
  70. )
  71. if (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
  72. set (MINIUPNPC_SOURCES ${MINIUPNPC_SOURCES} minissdpc.c)
  73. endif (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
  74. if (WIN32)
  75. set_source_files_properties (${MINIUPNPC_SOURCES} PROPERTIES
  76. COMPILE_DEFINITIONS "MINIUPNP_STATICLIB;MINIUPNP_EXPORTS"
  77. )
  78. endif (WIN32)
  79. if (WIN32)
  80. find_library (WINSOCK2_LIBRARY NAMES ws2_32 WS2_32 Ws2_32)
  81. find_library (IPHLPAPI_LIBRARY NAMES iphlpapi)
  82. set (LDLIBS ${WINSOCK2_LIBRARY} ${IPHLPAPI_LIBRARY} ${LDLIBS})
  83. #elseif (CMAKE_SYSTEM_NAME STREQUAL "Solaris")
  84. # find_library (SOCKET_LIBRARY NAMES socket)
  85. # find_library (NSL_LIBRARY NAMES nsl)
  86. # find_library (RESOLV_LIBRARY NAMES resolv)
  87. # set (LDLIBS ${SOCKET_LIBRARY} ${NSL_LIBRARY} ${RESOLV_LIBRARY} ${LDLIBS})
  88. endif (WIN32)
  89. if (NOT UPNPC_BUILD_STATIC AND NOT UPNPC_BUILD_SHARED)
  90. message (FATAL "Both shared and static libraries are disabled!")
  91. endif (NOT UPNPC_BUILD_STATIC AND NOT UPNPC_BUILD_SHARED)
  92. if (UPNPC_BUILD_STATIC)
  93. add_library (upnpc-static STATIC ${MINIUPNPC_SOURCES})
  94. set_target_properties (upnpc-static PROPERTIES OUTPUT_NAME "miniupnpc")
  95. target_link_libraries (upnpc-static ${LDLIBS})
  96. set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} upnpc-static)
  97. set (UPNPC_LIBRARY_TARGET upnpc-static)
  98. endif (UPNPC_BUILD_STATIC)
  99. if (UPNPC_BUILD_SHARED)
  100. add_library (upnpc-shared SHARED ${MINIUPNPC_SOURCES})
  101. set_target_properties (upnpc-shared PROPERTIES OUTPUT_NAME "miniupnpc")
  102. set_target_properties (upnpc-shared PROPERTIES VERSION ${MINIUPNPC_VERSION})
  103. set_target_properties (upnpc-shared PROPERTIES SOVERSION ${MINIUPNPC_API_VERSION})
  104. target_link_libraries (upnpc-shared ${LDLIBS})
  105. set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} upnpc-shared)
  106. set (UPNPC_LIBRARY_TARGET upnpc-shared)
  107. endif (UPNPC_BUILD_SHARED)
  108. if (UPNPC_BUILD_TESTS)
  109. add_executable (testminixml testminixml.c minixml.c igd_desc_parse.c)
  110. target_link_libraries (testminixml ${LDLIBS})
  111. add_executable (minixmlvalid minixmlvalid.c minixml.c)
  112. target_link_libraries (minixmlvalid ${LDLIBS})
  113. add_executable (testupnpreplyparse testupnpreplyparse.c
  114. minixml.c upnpreplyparse.c)
  115. target_link_libraries (testupnpreplyparse ${LDLIBS})
  116. add_executable (testigddescparse testigddescparse.c
  117. igd_desc_parse.c minixml.c miniupnpc.c miniwget.c minissdpc.c
  118. upnpcommands.c upnpreplyparse.c minisoap.c connecthostport.c
  119. portlistingparse.c receivedata.c
  120. )
  121. target_link_libraries (testigddescparse ${LDLIBS})
  122. add_executable (testminiwget testminiwget.c
  123. miniwget.c miniupnpc.c minisoap.c upnpcommands.c minissdpc.c
  124. upnpreplyparse.c minixml.c igd_desc_parse.c connecthostport.c
  125. portlistingparse.c receivedata.c
  126. )
  127. target_link_libraries (testminiwget ${LDLIBS})
  128. # set (UPNPC_INSTALL_TARGETS ${UPNPC_INSTALL_TARGETS} testminixml minixmlvalid testupnpreplyparse testigddescparse testminiwget)
  129. endif (UPNPC_BUILD_TESTS)
  130. install (TARGETS ${UPNPC_INSTALL_TARGETS}
  131. RUNTIME DESTINATION bin
  132. LIBRARY DESTINATION lib${LIB_SUFFIX}
  133. ARCHIVE DESTINATION lib${LIB_SUFFIX}
  134. )
  135. install (FILES
  136. miniupnpc.h
  137. miniwget.h
  138. upnpcommands.h
  139. igd_desc_parse.h
  140. upnpreplyparse.h
  141. upnperrors.h
  142. upnpdev.h
  143. miniupnpctypes.h
  144. portlistingparse.h
  145. miniupnpc_declspec.h
  146. DESTINATION include/miniupnpc
  147. )
  148. set (CONFIGURED YES CACHE INTERNAL "")
  149. # vim: ts=2:sw=2