Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

216 wiersze
7.5KB

  1. # MIT License
  2. #
  3. # Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a copy
  6. # of this software and associated documentation files (the "Software"), to deal
  7. # in the Software without restriction, including without limitation the rights
  8. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. # copies of the Software, and to permit persons to whom the Software is
  10. # furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be included in all
  13. # copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. # SOFTWARE.
  22. #
  23. ##############################################################################
  24. # jsoncpp
  25. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/jsoncpp/src/lib_json JSONCPP_SRC_LIST)
  26. add_library(jsoncpp STATIC ${JSONCPP_SRC_LIST})
  27. target_compile_options(jsoncpp
  28. PRIVATE ${COMPILE_OPTIONS_DEFAULT})
  29. target_include_directories(jsoncpp
  30. PRIVATE
  31. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/jsoncpp/include"
  32. PUBLIC
  33. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/jsoncpp/include")
  34. update_cached_list(MK_LINK_LIBRARIES jsoncpp)
  35. ##############################################################################
  36. # media-server
  37. set(MediaServer_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/media-server")
  38. # TODO: 补一个函数处理各种库
  39. # 添加 mov、flv 库用于 MP4 录制
  40. if(ENABLE_MP4)
  41. message(STATUS "ENABLE_MP4 defined")
  42. # MOV
  43. set(MediaServer_MOV_ROOT ${MediaServer_ROOT}/libmov)
  44. aux_source_directory(${MediaServer_MOV_ROOT}/include MOV_SRC_LIST)
  45. aux_source_directory(${MediaServer_MOV_ROOT}/source MOV_SRC_LIST)
  46. add_library(mov STATIC ${MOV_SRC_LIST})
  47. add_library(MediaServer::mov ALIAS mov)
  48. target_compile_definitions(mov
  49. PUBLIC -DENABLE_MP4)
  50. target_compile_options(mov
  51. PRIVATE ${COMPILE_OPTIONS_DEFAULT})
  52. target_include_directories(mov
  53. PRIVATE
  54. "$<BUILD_INTERFACE:${MediaServer_MOV_ROOT}/include>"
  55. PUBLIC
  56. "$<BUILD_INTERFACE:${MediaServer_MOV_ROOT}/include>")
  57. # FLV
  58. set(MediaServer_FLV_ROOT ${MediaServer_ROOT}/libflv)
  59. aux_source_directory(${MediaServer_FLV_ROOT}/include FLV_SRC_LIST)
  60. aux_source_directory(${MediaServer_FLV_ROOT}/source FLV_SRC_LIST)
  61. add_library(flv STATIC ${FLV_SRC_LIST})
  62. add_library(MediaServer::flv ALIAS flv)
  63. target_compile_options(flv
  64. PRIVATE ${COMPILE_OPTIONS_DEFAULT})
  65. target_include_directories(flv
  66. PRIVATE
  67. "$<BUILD_INTERFACE:${MediaServer_FLV_ROOT}/include>"
  68. PUBLIC
  69. "$<BUILD_INTERFACE:${MediaServer_FLV_ROOT}/include>")
  70. update_cached_list(MK_LINK_LIBRARIES
  71. MediaServer::flv MediaServer::mov)
  72. update_cached_list(MK_COMPILE_DEFINITIONS
  73. ENABLE_MP4)
  74. endif()
  75. # 添加 mpeg 用于支持 ts 生成
  76. if(ENABLE_RTPPROXY OR ENABLE_HLS)
  77. # mpeg
  78. set(MediaServer_MPEG_ROOT ${MediaServer_ROOT}/libmpeg)
  79. aux_source_directory(${MediaServer_MPEG_ROOT}/include MPEG_SRC_LIST)
  80. aux_source_directory(${MediaServer_MPEG_ROOT}/source MPEG_SRC_LIST)
  81. add_library(mpeg STATIC ${MPEG_SRC_LIST})
  82. add_library(MediaServer::mpeg ALIAS mpeg)
  83. # media-server库相关编译宏
  84. # MPEG_H26X_VERIFY - 视频流类型识别
  85. # MPEG_ZERO_PAYLOAD_LENGTH - 兼容hik流
  86. # MPEG_DAHUA_AAC_FROM_G711 - 兼容dahua流
  87. target_compile_options(mpeg
  88. PRIVATE ${COMPILE_OPTIONS_DEFAULT} -DMPEG_H26X_VERIFY -DMPEG_ZERO_PAYLOAD_LENGTH -DMPEG_DAHUA_AAC_FROM_G711)
  89. target_include_directories(mpeg
  90. PRIVATE
  91. "$<BUILD_INTERFACE:${MediaServer_MPEG_ROOT}/include>"
  92. PUBLIC
  93. "$<BUILD_INTERFACE:${MediaServer_MPEG_ROOT}/include>")
  94. update_cached_list(MK_LINK_LIBRARIES MediaServer::mpeg)
  95. if(ENABLE_RTPPROXY)
  96. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_RTPPROXY)
  97. endif()
  98. if(ENABLE_HLS)
  99. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_HLS)
  100. endif()
  101. endif()
  102. ##############################################################################
  103. # toolkit
  104. # TODO: 改造 toolkit 以便直接引用
  105. include(CheckStructHasMember)
  106. include(CheckSymbolExists)
  107. # 检查 sendmmsg 相关依赖并设置对应的宏, 配置 _GNU_SOURCE 以启用 GNU 扩展特性
  108. list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
  109. check_struct_has_member("struct mmsghdr" msg_hdr sys/socket.h HAVE_MMSG_HDR)
  110. check_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG_API)
  111. check_symbol_exists(recvmmsg sys/socket.h HAVE_RECVMMSG_API)
  112. set(COMPILE_DEFINITIONS)
  113. # ToolKit 依赖 ENABLE_OPENSSL 以及 ENABLE_MYSQL
  114. list(FIND MK_COMPILE_DEFINITIONS ENABLE_OPENSSL ENABLE_OPENSSL_INDEX)
  115. if(NOT ENABLE_OPENSSL_INDEX EQUAL -1)
  116. list(APPEND COMPILE_DEFINITIONS ENABLE_OPENSSL)
  117. endif()
  118. list(FIND MK_COMPILE_DEFINITIONS ENABLE_MYSQL ENABLE_MYSQL_INDEX)
  119. if(NOT ENABLE_MYSQL_INDEX EQUAL -1)
  120. list(APPEND COMPILE_DEFINITIONS ENABLE_MYSQL)
  121. endif()
  122. if(HAVE_MMSG_HDR)
  123. list(APPEND COMPILE_DEFINITIONS HAVE_MMSG_HDR)
  124. endif()
  125. if(HAVE_SENDMMSG_API)
  126. list(APPEND COMPILE_DEFINITIONS HAVE_SENDMMSG_API)
  127. endif()
  128. if(HAVE_RECVMMSG_API)
  129. list(APPEND COMPILE_DEFINITIONS HAVE_RECVMMSG_API)
  130. endif()
  131. set(ToolKit_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/ZLToolKit)
  132. # 收集源代码
  133. file(GLOB ToolKit_SRC_LIST
  134. ${ToolKit_ROOT}/src/*/*.cpp
  135. ${ToolKit_ROOT}/src/*/*.h
  136. ${ToolKit_ROOT}/src/*/*.c)
  137. if(IOS)
  138. list(APPEND ToolKit_SRC_LIST
  139. ${ToolKit_ROOT}/Network/Socket_ios.mm)
  140. endif()
  141. ###################################################################
  142. #使用wepoll windows iocp 模拟 epoll
  143. if(ENABLE_WEPOLL)
  144. if(WIN32)
  145. message(STATUS "Enable wepoll")
  146. #增加wepoll源文件及api参数兼容文件
  147. list(APPEND ToolKit_SRC_LIST
  148. ${CMAKE_CURRENT_SOURCE_DIR}/wepoll/wepoll.c
  149. ${CMAKE_CURRENT_SOURCE_DIR}/wepoll/sys/epoll.cpp)
  150. #增加wepoll头文件目录
  151. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wepoll)
  152. #开启epoll
  153. add_definitions(-DHAS_EPOLL)
  154. endif()
  155. endif()
  156. ###################################################################
  157. # 去除 win32 的适配代码
  158. if(NOT WIN32)
  159. list(REMOVE_ITEM ToolKit_SRC_LIST ${ToolKit_ROOT}/win32/getopt.c)
  160. else()
  161. # 防止 Windows.h 包含 Winsock.h
  162. list(APPEND COMPILE_DEFINITIONS
  163. WIN32_LEAN_AND_MEAN MP4V2_NO_STDINT_DEFS
  164. # 禁用警告
  165. _CRT_SECURE_NO_WARNINGS _WINSOCK_DEPRECATED_NO_WARNINGS)
  166. endif()
  167. # 添加库
  168. add_library(zltoolkit STATIC ${ToolKit_SRC_LIST})
  169. add_library(ZLMediaKit::ToolKit ALIAS zltoolkit)
  170. target_compile_definitions(zltoolkit
  171. PUBLIC ${COMPILE_DEFINITIONS})
  172. target_compile_options(zltoolkit
  173. PRIVATE ${COMPILE_OPTIONS_DEFAULT})
  174. target_include_directories(zltoolkit
  175. PRIVATE
  176. "$<BUILD_INTERFACE:${ToolKit_ROOT}/src>"
  177. PUBLIC
  178. "$<BUILD_INTERFACE:${ToolKit_ROOT}>/src")
  179. update_cached_list(MK_LINK_LIBRARIES ZLMediaKit::ToolKit)
  180. if(USE_SOLUTION_FOLDERS AND (NOT GROUP_BY_EXPLORER))
  181. # 在 IDE 中对文件进行分组, 源文件和头文件分开
  182. set_file_group(${ToolKit_ROOT}/src ${ToolKit_SRC_LIST})
  183. endif()
  184. # 未在使用
  185. if(ENABLE_CXX_API)
  186. # 保留目录结构
  187. install(DIRECTORY ${ToolKit_ROOT}/
  188. DESTINATION ${INSTALL_PATH_INCLUDE}/ZLToolKit
  189. REGEX "(.*[.](md|cpp)|win32)$" EXCLUDE)
  190. install(TARGETS zltoolkit
  191. DESTINATION ${INSTALL_PATH_LIB})
  192. endif()