CMakeLists.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #
  2. # Copyright (C) 2015-2015 Oleg Alexeenkov
  3. # Copyright (C) 2015-2020 Felix Weinrank
  4. #
  5. # All rights reserved.
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions
  9. # are met:
  10. # 1. Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. # 3. Neither the name of the project nor the names of its contributors
  16. # may be used to endorse or promote products derived from this software
  17. # without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. # SUCH DAMAGE.
  30. #
  31. #################################################
  32. # INCLUDE MODULES AND SETTINGS
  33. #################################################
  34. set(VERSION "0.9.5.0")
  35. # Shared library API and ABI versions
  36. # Notice: shared library version must be in X.Y.Z format only
  37. set(SOVERSION_FULL "2.0.0")
  38. set(SOVERSION_SHORT "2")
  39. include(GNUInstallDirs)
  40. set(prefix ${CMAKE_INSTALL_PREFIX})
  41. set(exec_prefix ${prefix})
  42. set(libdir ${exec_prefix}/${CMAKE_INSTALL_LIBDIR})
  43. set(includedir ${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
  44. set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR})
  45. set(CMAKE_MACOSX_RPATH 1)
  46. include(CheckCCompilerFlag)
  47. option(SCTP_USE_MBEDTLS_SHA1 "Build with mbedtls sha1 support." OFF)
  48. add_definitions(-D__Userspace__)
  49. add_definitions(-DSCTP_SIMPLE_ALLOCATOR)
  50. add_definitions(-DSCTP_PROCESS_LEVEL_LOCKS)
  51. if(SCTP_USE_MBEDTLS_SHA1)
  52. add_definitions(-DSCTP_USE_MBEDTLS_SHA1)
  53. find_package(MbedTLS REQUIRED)
  54. endif()
  55. #################################################
  56. # OS DEPENDENT
  57. #################################################
  58. check_c_compiler_flag(-Wno-address-of-packed-member has_wno_address_of_packed_member)
  59. if (has_wno_address_of_packed_member)
  60. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-address-of-packed-member")
  61. endif ()
  62. check_c_compiler_flag(-Wno-deprecated-declarations has_wno_deprecated_declarations)
  63. if (has_wno_deprecated_declarations)
  64. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
  65. endif ()
  66. if (CMAKE_SYSTEM_NAME MATCHES "Linux")
  67. add_definitions(-D_GNU_SOURCE)
  68. endif ()
  69. if (CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "iOS")
  70. add_definitions(-D__APPLE_USE_RFC_2292)
  71. endif ()
  72. #################################################
  73. # MISC
  74. #################################################
  75. if (sctp_build_shared_lib)
  76. set(BUILD_SHARED_LIBS 1)
  77. endif ()
  78. find_package(Threads)
  79. #################################################
  80. # LIBRARY FILES
  81. #################################################
  82. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  83. list(APPEND usrsctp_root_headers
  84. user_atomic.h
  85. user_environment.h
  86. user_inpcb.h
  87. user_ip_icmp.h
  88. user_ip6_var.h
  89. user_malloc.h
  90. user_mbuf.h
  91. user_queue.h
  92. user_recv_thread.h
  93. user_route.h
  94. user_socketvar.h
  95. user_uma.h
  96. usrsctp.h
  97. )
  98. list(APPEND usrsctp_netinet_headers
  99. netinet/sctp_asconf.h
  100. netinet/sctp_auth.h
  101. netinet/sctp_bsd_addr.h
  102. netinet/sctp_callout.h
  103. netinet/sctp_constants.h
  104. netinet/sctp_crc32.h
  105. netinet/sctp_header.h
  106. netinet/sctp_indata.h
  107. netinet/sctp_input.h
  108. netinet/sctp_lock_userspace.h
  109. netinet/sctp_os_userspace.h
  110. netinet/sctp_os.h
  111. netinet/sctp_output.h
  112. netinet/sctp_pcb.h
  113. netinet/sctp_peeloff.h
  114. netinet/sctp_process_lock.h
  115. netinet/sctp_sha1.h
  116. netinet/sctp_structs.h
  117. netinet/sctp_sysctl.h
  118. netinet/sctp_timer.h
  119. netinet/sctp_uio.h
  120. netinet/sctp_var.h
  121. netinet/sctputil.h
  122. netinet/sctp.h
  123. )
  124. list(APPEND usrsctp_netinet6_headers
  125. netinet6/sctp6_var.h
  126. )
  127. list(APPEND usrsctp_headers
  128. ${usrsctp_root_headers}
  129. ${usrsctp_netinet_headers}
  130. ${usrsctp_netinet6_headers}
  131. )
  132. list(APPEND usrsctp_sources
  133. netinet/sctp_asconf.c
  134. netinet/sctp_auth.c
  135. netinet/sctp_bsd_addr.c
  136. netinet/sctp_callout.c
  137. netinet/sctp_cc_functions.c
  138. netinet/sctp_crc32.c
  139. netinet/sctp_indata.c
  140. netinet/sctp_input.c
  141. netinet/sctp_output.c
  142. netinet/sctp_pcb.c
  143. netinet/sctp_peeloff.c
  144. netinet/sctp_sha1.c
  145. netinet/sctp_ss_functions.c
  146. netinet/sctp_sysctl.c
  147. netinet/sctp_timer.c
  148. netinet/sctp_userspace.c
  149. netinet/sctp_usrreq.c
  150. netinet/sctputil.c
  151. netinet6/sctp6_usrreq.c
  152. user_environment.c
  153. user_mbuf.c
  154. user_recv_thread.c
  155. user_socket.c
  156. )
  157. add_library(usrsctp ${usrsctp_sources} ${usrsctp_headers})
  158. target_include_directories(usrsctp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
  159. if(SCTP_USE_MBEDTLS_SHA1)
  160. target_include_directories(usrsctp PRIVATE ${MBEDTLS_INCLUDE_DIRS})
  161. endif()
  162. target_link_libraries(usrsctp ${CMAKE_THREAD_LIBS_INIT})
  163. if (WIN32)
  164. message(STATUS "link library: ws2_32")
  165. target_link_libraries(usrsctp ws2_32 iphlpapi)
  166. endif ()
  167. if(SCTP_USE_MBEDTLS_SHA1)
  168. target_link_libraries(usrsctp PRIVATE ${MBEDTLS_LIBRARIES})
  169. endif()
  170. set_target_properties(usrsctp PROPERTIES IMPORT_SUFFIX "_import.lib")
  171. set_target_properties(usrsctp PROPERTIES SOVERSION ${SOVERSION_SHORT} VERSION ${SOVERSION_FULL})
  172. #################################################
  173. # INSTALL LIBRARY AND HEADER
  174. #################################################
  175. install(TARGETS usrsctp DESTINATION ${CMAKE_INSTALL_LIBDIR})
  176. install(FILES usrsctp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  177. #################################################
  178. # GENERATE AND INSTALL PKG-CONFIG FILE
  179. #################################################
  180. configure_file("${PROJECT_SOURCE_DIR}/usrsctp.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/usrsctp.pc" @ONLY)
  181. install(FILES "${CMAKE_CURRENT_BINARY_DIR}/usrsctp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")