CMakeLists.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. cmake_minimum_required(VERSION 3.1.3)
  24. # 加载自定义模块
  25. # Load custom modules
  26. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  27. project(ZLMediaKit LANGUAGES C CXX)
  28. # 使能 C++11
  29. # Enable C++11
  30. set(CMAKE_CXX_STANDARD 11)
  31. option(ENABLE_API "Enable C API SDK" ON)
  32. option(ENABLE_API_STATIC_LIB "Enable mk_api static lib" OFF)
  33. option(ENABLE_ASAN "Enable Address Sanitize" OFF)
  34. option(ENABLE_CXX_API "Enable C++ API SDK" OFF)
  35. option(ENABLE_FAAC "Enable FAAC" OFF)
  36. option(ENABLE_FFMPEG "Enable FFmpeg" OFF)
  37. option(ENABLE_HLS "Enable HLS" ON)
  38. option(ENABLE_JEMALLOC_STATIC "Enable static linking to the jemalloc library" OFF)
  39. option(ENABLE_JEMALLOC_DUMP "Enable jemalloc to dump malloc statistics" OFF)
  40. option(ENABLE_MEM_DEBUG "Enable Memory Debug" OFF)
  41. option(ENABLE_MP4 "Enable MP4" ON)
  42. option(ENABLE_MSVC_MT "Enable MSVC Mt/Mtd lib" ON)
  43. option(ENABLE_MYSQL "Enable MySQL" OFF)
  44. option(ENABLE_OPENSSL "Enable OpenSSL" ON)
  45. option(ENABLE_PLAYER "Enable Player" ON)
  46. option(ENABLE_RTPPROXY "Enable RTPPROXY" ON)
  47. option(ENABLE_SERVER "Enable Server" ON)
  48. option(ENABLE_SERVER_LIB "Enable server as android static library" OFF)
  49. option(ENABLE_SRT "Enable SRT" ON)
  50. option(ENABLE_TESTS "Enable Tests" ON)
  51. option(ENABLE_SCTP "Enable SCTP" ON)
  52. option(ENABLE_WEBRTC "Enable WebRTC" ON)
  53. option(ENABLE_X264 "Enable x264" OFF)
  54. option(ENABLE_WEPOLL "Enable wepoll" ON)
  55. option(ENABLE_VIDEOSTACK "Enable video stack" OFF)
  56. option(DISABLE_REPORT "Disable report to report.zlmediakit.com" OFF)
  57. option(USE_SOLUTION_FOLDERS "Enable solution dir supported" ON)
  58. ##############################################################################
  59. # 设置socket默认缓冲区大小为256k.如果设置为0则不设置socket的默认缓冲区大小,使用系统内核默认值(设置为0仅对linux有效)
  60. # Set the default buffer size of the socket to 256k. If set to 0, the default buffer size of the socket will not be set,
  61. # and the system kernel default value will be used (setting to 0 is only valid for linux)
  62. set(SOCKET_DEFAULT_BUF_SIZE 262144 CACHE STRING "Default buffer size for socket" FORCE)
  63. if("${CMAKE_BUILD_TYPE}" STREQUAL "")
  64. set(CMAKE_BUILD_TYPE "Debug")
  65. endif()
  66. message(STATUS "编译类型: ${CMAKE_BUILD_TYPE}")
  67. # 方便排查编译问题, 需要 FORCE CACHE, 否则需要命令行设置才生效
  68. # To facilitate the troubleshooting of compilation problems, you need to FORCE CACHE, otherwise you need to set it on the command line to take effect
  69. set(CMAKE_VERBOSE_MAKEFILE ON CACHE INTERNAL "" FORCE)
  70. # TODO: include 当前目录会导致 server 编译出错, 待排除
  71. set(CMAKE_INCLUDE_CURRENT_DIR OFF)
  72. # 安装路径
  73. # Install path
  74. if(NOT CMAKE_INSTALL_PREFIX)
  75. if(UNIX)
  76. set(INSTALL_PATH_LIB lib${LIB_SUFFIX})
  77. set(INSTALL_PATH_INCLUDE include)
  78. set(INSTALL_PATH_RUNTIME bin)
  79. elseif(WIN32)
  80. # Windows 下安装到了用户主目录下?
  81. # Install to the user's home directory under Windows?
  82. set(INSTALL_PATH_LIB $ENV{HOME}/${CMAKE_PROJECT_NAME}/lib)
  83. set(INSTALL_PATH_INCLUDE $ENV{HOME}/${CMAKE_PROJECT_NAME}/include)
  84. else()
  85. message(WARNING "该平台(${CMAKE_SYSTEM_NAME})下暂未设置安装路径")
  86. endif()
  87. else()
  88. set(INSTALL_PATH_LIB ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
  89. set(INSTALL_PATH_INCLUDE ${CMAKE_INSTALL_PREFIX}/include)
  90. set(INSTALL_PATH_RUNTIME ${CMAKE_INSTALL_PREFIX}/bin)
  91. endif()
  92. string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)
  93. # 设置输出目录, 包括 bin, lib 以及其他文件
  94. # Windows 也不再区分 32/64
  95. # Set the output directory, including bin, lib and other files
  96. # Windows no longer distinguishes 32/64
  97. set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release/${SYSTEM_NAME_LOWER}/${CMAKE_BUILD_TYPE})
  98. set(LIBRARY_OUTPUT_PATH ${OUTPUT_DIR})
  99. set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})
  100. # 添加 git 版本信息
  101. # Add git version information
  102. set(COMMIT_HASH "Git_Unkown_commit")
  103. set(COMMIT_TIME "Git_Unkown_time")
  104. set(BRANCH_NAME "Git_Unkown_branch")
  105. set(BUILD_TIME "")
  106. string(TIMESTAMP BUILD_TIME "%Y-%m-%dT%H:%M:%S")
  107. find_package(Git QUIET)
  108. if(GIT_FOUND)
  109. execute_process(
  110. COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD
  111. OUTPUT_VARIABLE COMMIT_HASH
  112. OUTPUT_STRIP_TRAILING_WHITESPACE
  113. ERROR_QUIET
  114. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  115. execute_process(
  116. COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEAD
  117. OUTPUT_VARIABLE BRANCH_NAME
  118. OUTPUT_STRIP_TRAILING_WHITESPACE
  119. ERROR_QUIET
  120. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  121. execute_process(
  122. COMMAND ${GIT_EXECUTABLE} log --format=format:%aI -1
  123. OUTPUT_VARIABLE COMMIT_TIME
  124. OUTPUT_STRIP_TRAILING_WHITESPACE
  125. ERROR_QUIET
  126. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  127. endif()
  128. configure_file(
  129. ${CMAKE_CURRENT_SOURCE_DIR}/ZLMVersion.h.ini
  130. ${CMAKE_CURRENT_BINARY_DIR}/ZLMVersion.h
  131. @ONLY)
  132. message(STATUS "Git version is ${BRANCH_NAME} ${COMMIT_HASH}/${COMMIT_TIME} ${BUILD_TIME}")
  133. ##############################################################################
  134. # 方便修改全局变量
  135. # Convenient to modify global variables
  136. function(update_cached name value)
  137. set("${name}" "${value}" CACHE INTERNAL "*** Internal ***" FORCE)
  138. endfunction()
  139. function(update_cached_list name)
  140. set(_tmp_list "${${name}}")
  141. list(APPEND _tmp_list "${ARGN}")
  142. list(REMOVE_DUPLICATES _tmp_list)
  143. update_cached(${name} "${_tmp_list}")
  144. endfunction()
  145. # TODO:
  146. function(set_file_group prefix)
  147. message(STATUS "set_file_group " ${prefix} " " ${ARGC})
  148. foreach(FILE IN LISTS ARGN 1)
  149. # Get the directory of the source file
  150. get_filename_component(PARENT_DIR "${FILE}" DIRECTORY)
  151. # Remove common directory prefix to make the group
  152. string(REPLACE "${prefix}" "" GROUP "${PARENT_DIR}")
  153. # Make sure we are using windows slashes
  154. string(REPLACE "/" "\\" GROUP "${GROUP}")
  155. source_group("${GROUP}" FILES "${FILE}")
  156. endforeach()
  157. endfunction()
  158. find_program(CCACHE_FOUND ccache)
  159. if(CCACHE_FOUND)
  160. set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  161. set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  162. endif()
  163. if(UNIX)
  164. # UNIX/Linux/Darwin
  165. set(COMPILE_OPTIONS_DEFAULT
  166. "-fPIC"
  167. "-Wall;-Wextra"
  168. "-Wno-unused-function;-Wno-unused-parameter;-Wno-unused-variable;-Wno-deprecated-declarations"
  169. "-Wno-error=extra;-Wno-error=missing-field-initializers;-Wno-error=type-limits;-Wno-comment")
  170. if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
  171. set(COMPILE_OPTIONS_DEFAULT ${COMPILE_OPTIONS_DEFAULT} "-g3")
  172. else()
  173. set(COMPILE_OPTIONS_DEFAULT ${COMPILE_OPTIONS_DEFAULT} "-g0")
  174. endif()
  175. elseif(WIN32)
  176. if (MSVC)
  177. set(COMPILE_OPTIONS_DEFAULT
  178. # TODO: /wd4819 应该是不会生效
  179. "/wd4566;/wd4819;/utf-8"
  180. # warning C4530: C++ exception handler used, but unwind semantics are not enabled.
  181. "/EHsc")
  182. # disable Windows logo
  183. list(APPEND COMPILE_OPTIONS_DEFAULT "/nologo")
  184. list(APPEND CMAKE_STATIC_LINKER_FLAGS "/nologo")
  185. endif()
  186. endif()
  187. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
  188. if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
  189. include_directories(SYSTEM "/opt/homebrew/include")
  190. endif()
  191. endif()
  192. # mediakit 以及各个 runtime 依赖
  193. # mediakit and various runtime dependencies
  194. update_cached(MK_LINK_LIBRARIES "")
  195. update_cached(MK_COMPILE_DEFINITIONS ENABLE_VERSION)
  196. if (DISABLE_REPORT)
  197. update_cached_list(MK_COMPILE_DEFINITIONS DISABLE_REPORT)
  198. endif ()
  199. if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  200. include(CheckCXXSourceCompiles)
  201. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/checks/atomic_check.cpp atomic_check_cpp)
  202. check_cxx_source_compiles("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITHOUT_LIB)
  203. if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
  204. # cmake --help-policy CMP0075
  205. list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
  206. check_cxx_source_compiles("${atomic_check_cpp}" HAVE_CXX_ATOMICS_WITH_LIB)
  207. if(NOT HAVE_CXX_ATOMICS_WITH_LIB)
  208. message(WARNING "Compiler doesn't support std::atomic<long long>")
  209. else()
  210. update_cached_list(MK_LINK_LIBRARIES atomic)
  211. endif()
  212. endif()
  213. endif()
  214. # 多个模块依赖 ffmpeg 相关库, 统一查找
  215. # Multiple modules depend on ffmpeg related libraries, unified search
  216. if(ENABLE_FFMPEG)
  217. find_package(PkgConfig QUIET)
  218. # 查找 ffmpeg/libutil 是否安装
  219. # find ffmpeg/libutil installed
  220. if(PKG_CONFIG_FOUND)
  221. pkg_check_modules(AVUTIL QUIET IMPORTED_TARGET libavutil)
  222. if(AVUTIL_FOUND)
  223. update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVUTIL)
  224. message(STATUS "found library: ${AVUTIL_LIBRARIES}")
  225. endif()
  226. endif()
  227. # 查找 ffmpeg/libavcodec 是否安装
  228. # find ffmpeg/libavcodec installed
  229. if(PKG_CONFIG_FOUND)
  230. pkg_check_modules(AVCODEC QUIET IMPORTED_TARGET libavcodec)
  231. if(AVCODEC_FOUND)
  232. update_cached_list(MK_LINK_LIBRARIES PkgConfig::AVCODEC)
  233. message(STATUS "found library: ${AVCODEC_LIBRARIES}")
  234. endif()
  235. endif()
  236. # 查找 ffmpeg/libswscale 是否安装
  237. # find ffmpeg/libswscale installed
  238. if(PKG_CONFIG_FOUND)
  239. pkg_check_modules(SWSCALE QUIET IMPORTED_TARGET libswscale)
  240. if(SWSCALE_FOUND)
  241. update_cached_list(MK_LINK_LIBRARIES PkgConfig::SWSCALE)
  242. message(STATUS "found library: ${SWSCALE_LIBRARIES}")
  243. endif()
  244. endif()
  245. # 查找 ffmpeg/libswresample 是否安装
  246. # find ffmpeg/libswresample installed
  247. if(PKG_CONFIG_FOUND)
  248. pkg_check_modules(SWRESAMPLE QUIET IMPORTED_TARGET libswresample)
  249. if(SWRESAMPLE_FOUND)
  250. update_cached_list(MK_LINK_LIBRARIES PkgConfig::SWRESAMPLE)
  251. message(STATUS "found library: ${SWRESAMPLE_LIBRARIES}")
  252. endif()
  253. endif()
  254. # 查找 ffmpeg/libutil 是否安装
  255. # find ffmpeg/libutil installed
  256. if(NOT AVUTIL_FOUND)
  257. find_package(AVUTIL QUIET)
  258. if(AVUTIL_FOUND)
  259. include_directories(SYSTEM ${AVUTIL_INCLUDE_DIR})
  260. update_cached_list(MK_LINK_LIBRARIES ${AVUTIL_LIBRARIES})
  261. message(STATUS "found library: ${AVUTIL_LIBRARIES}")
  262. endif ()
  263. endif ()
  264. # 查找 ffmpeg/libavcodec 是否安装
  265. # find ffmpeg/libavcodec installed
  266. if(NOT AVCODEC_FOUND)
  267. find_package(AVCODEC QUIET)
  268. if(AVCODEC_FOUND)
  269. include_directories(SYSTEM ${AVCODEC_INCLUDE_DIR})
  270. update_cached_list(MK_LINK_LIBRARIES ${AVCODEC_LIBRARIES})
  271. message(STATUS "found library: ${AVCODEC_LIBRARIES}")
  272. endif()
  273. endif()
  274. # 查找 ffmpeg/libswscale 是否安装
  275. # find ffmpeg/libswscale installed
  276. if(NOT SWSCALE_FOUND)
  277. find_package(SWSCALE QUIET)
  278. if(SWSCALE_FOUND)
  279. include_directories(SYSTEM ${SWSCALE_INCLUDE_DIR})
  280. update_cached_list(MK_LINK_LIBRARIES ${SWSCALE_LIBRARIES})
  281. message(STATUS "found library: ${SWSCALE_LIBRARIES}")
  282. endif()
  283. endif()
  284. # 查找 ffmpeg/libswresample 是否安装
  285. # find ffmpeg/libswresample installed
  286. if(NOT SWRESAMPLE_FOUND)
  287. find_package(SWRESAMPLE QUIET)
  288. if(SWRESAMPLE_FOUND)
  289. include_directories(SYSTEM ${SWRESAMPLE_INCLUDE_DIRS})
  290. update_cached_list(MK_LINK_LIBRARIES ${SWRESAMPLE_LIBRARIES})
  291. message(STATUS "found library: ${SWRESAMPLE_LIBRARIES}")
  292. endif()
  293. endif()
  294. if(AVUTIL_FOUND AND AVCODEC_FOUND AND SWSCALE_FOUND AND SWRESAMPLE_FOUND)
  295. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FFMPEG)
  296. update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
  297. else()
  298. set(ENABLE_FFMPEG OFF)
  299. message(WARNING "ffmpeg related functions not found")
  300. endif()
  301. endif()
  302. if(ENABLE_MEM_DEBUG)
  303. update_cached_list(MK_LINK_LIBRARIES
  304. "-Wl,-wrap,free;-Wl,-wrap,malloc;-Wl,-wrap,realloc;-Wl,-wrap,calloc")
  305. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_MEM_DEBUG)
  306. message(STATUS "Memory debugging enabled")
  307. endif()
  308. if(ENABLE_ASAN)
  309. list(APPEND COMPILE_OPTIONS_DEFAULT
  310. "-fsanitize=address;-fno-omit-frame-pointer")
  311. # https://github.com/google/sanitizers/wiki/AddressSanitizer#using-addresssanitizer
  312. # > In order to use AddressSanitizer you will need to
  313. # > compile and link your program using clang with the -fsanitize=address switch.
  314. update_cached_list(MK_LINK_LIBRARIES "-fsanitize=address")
  315. message(STATUS "Address Sanitize enabled")
  316. endif()
  317. # 下载jemalloc后静态编译
  318. # Static compilation after downloading jemalloc
  319. set(DEP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/external-${CMAKE_SYSTEM_NAME})
  320. if(ENABLE_JEMALLOC_STATIC)
  321. if(NOT EXISTS ${DEP_ROOT_DIR})
  322. file(MAKE_DIRECTORY ${DEP_ROOT_DIR})
  323. endif()
  324. if (ENABLE_JEMALLOC_DUMP)
  325. set(ENABLE_JEMALLOC_STAT ON)
  326. else ()
  327. set(ENABLE_JEMALLOC_STAT OFF)
  328. endif ()
  329. include(Jemalloc)
  330. include_directories(SYSTEM ${DEP_ROOT_DIR}/${JEMALLOC_NAME}/include)
  331. link_directories(${DEP_ROOT_DIR}/${JEMALLOC_NAME}/lib)
  332. # 用于影响后续查找过程
  333. # Used to affect subsequent lookup process
  334. set(JEMALLOC_ROOT_DIR "${DEP_ROOT_DIR}/${JEMALLOC_NAME}")
  335. endif()
  336. # 默认链接 jemalloc 库避免内存碎片
  337. # Link the jemalloc library by default to avoid memory fragmentation
  338. find_package(JEMALLOC QUIET)
  339. if(JEMALLOC_FOUND)
  340. message(STATUS "found library: ${JEMALLOC_LIBRARIES}")
  341. include_directories(${JEMALLOC_INCLUDE_DIR})
  342. update_cached_list(MK_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
  343. add_definitions(-DUSE_JEMALLOC)
  344. message(STATUS "jemalloc will be used to avoid memory fragmentation")
  345. if (ENABLE_JEMALLOC_DUMP)
  346. add_definitions(-DENABLE_JEMALLOC_DUMP)
  347. message(STATUS "jemalloc will save memory usage statistics when the program exits")
  348. endif ()
  349. endif()
  350. # 查找 openssl 是否安装
  351. # find openssl installed
  352. find_package(OpenSSL QUIET)
  353. if(OPENSSL_FOUND AND ENABLE_OPENSSL)
  354. message(STATUS "found library: ${OPENSSL_LIBRARIES}, ENABLE_OPENSSL defined")
  355. include_directories(${OPENSSL_INCLUDE_DIR})
  356. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_OPENSSL)
  357. update_cached_list(MK_LINK_LIBRARIES ${OPENSSL_LIBRARIES})
  358. if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND OPENSSL_USE_STATIC_LIBS)
  359. update_cached_list(MK_LINK_LIBRARIES ${CMAKE_DL_LIBS})
  360. elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND OPENSSL_USE_STATIC_LIBS)
  361. update_cached_list(MK_LINK_LIBRARIES Crypt32)
  362. endif()
  363. else()
  364. set(ENABLE_OPENSSL OFF)
  365. set(ENABLE_WEBRTC OFF)
  366. message(WARNING "openssl 未找到, rtmp 将不支持 flash 播放器, https/wss/rtsps/rtmps/webrtc 也将失效")
  367. endif()
  368. # 查找 mysql 是否安装
  369. # find mysql installed
  370. find_package(MYSQL QUIET)
  371. if(MYSQL_FOUND AND ENABLE_MYSQL)
  372. message(STATUS "found library: ${MYSQL_LIBRARIES}, ENABLE_MYSQL defined")
  373. include_directories(SYSTEM
  374. ${MYSQL_INCLUDE_DIR}
  375. ${MYSQL_INCLUDE_DIR}/mysql)
  376. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_MYSQL)
  377. update_cached_list(MK_LINK_LIBRARIES ${MYSQL_LIBRARIES})
  378. endif()
  379. # 查找 x264 是否安装
  380. # find x264 installed
  381. find_package(X264 QUIET)
  382. if(X264_FOUND AND ENABLE_X264)
  383. message(STATUS "found library: ${X264_LIBRARIES}, ENABLE_X264 defined")
  384. include_directories(SYSTEM ${X264_INCLUDE_DIRS})
  385. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_X264)
  386. update_cached_list(MK_LINK_LIBRARIES ${X264_LIBRARIES})
  387. endif()
  388. # 查找 faac 是否安装
  389. # find faac installed
  390. find_package(FAAC QUIET)
  391. if(FAAC_FOUND AND ENABLE_FAAC)
  392. message(STATUS "found library:${FAAC_LIBRARIES}, ENABLE_FAAC defined")
  393. include_directories(SYSTEM ${FAAC_INCLUDE_DIR})
  394. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_FAAC)
  395. update_cached_list(MK_LINK_LIBRARIES ${FAAC_LIBRARIES})
  396. endif()
  397. if(WIN32)
  398. update_cached_list(MK_LINK_LIBRARIES WS2_32 Iphlpapi shlwapi)
  399. elseif(ANDROID)
  400. update_cached_list(MK_LINK_LIBRARIES log)
  401. elseif(NOT ANDROID OR IOS)
  402. update_cached_list(MK_LINK_LIBRARIES pthread)
  403. endif()
  404. if(ENABLE_VIDEOSTACK)
  405. if(ENABLE_FFMPEG AND ENABLE_X264)
  406. message(STATUS "ENABLE_VIDEOSTACK defined")
  407. update_cached_list(MK_COMPILE_DEFINITIONS ENABLE_VIDEOSTACK)
  408. else()
  409. message(WARNING "ENABLE_VIDEOSTACK requires ENABLE_FFMPEG and ENABLE_X264")
  410. endif ()
  411. endif ()
  412. # ----------------------------------------------------------------------------
  413. # Solution folders:
  414. # ----------------------------------------------------------------------------
  415. if(USE_SOLUTION_FOLDERS)
  416. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  417. set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
  418. endif()
  419. if(MSVC AND ENABLE_MSVC_MT)
  420. set(CompilerFlags
  421. CMAKE_CXX_FLAGS
  422. CMAKE_CXX_FLAGS_DEBUG
  423. CMAKE_CXX_FLAGS_RELEASE
  424. CMAKE_C_FLAGS
  425. CMAKE_C_FLAGS_DEBUG
  426. CMAKE_C_FLAGS_RELEASE)
  427. # TODO: 通常应该不需要替换
  428. foreach(CompilerFlag ${CompilerFlags})
  429. string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
  430. endforeach()
  431. endif()
  432. ##############################################################################
  433. # for version.h
  434. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  435. # for assert.h
  436. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdpart)
  437. add_subdirectory(3rdpart)
  438. add_subdirectory(src)
  439. add_subdirectory(ext-codec)
  440. if(ENABLE_SRT)
  441. add_subdirectory(srt)
  442. endif()
  443. if(ENABLE_WEBRTC)
  444. add_subdirectory(webrtc)
  445. endif()
  446. if(ENABLE_API)
  447. add_subdirectory(api)
  448. endif()
  449. ##############################################################################
  450. if(ENABLE_PLAYER AND ENABLE_FFMPEG)
  451. add_subdirectory(player)
  452. endif()
  453. #MediaServer主程序
  454. #MediaServer main program
  455. if(ENABLE_SERVER)
  456. add_subdirectory(server)
  457. endif()
  458. # Android 会 add_subdirectory 并依赖该变量
  459. # Android will add_subdirectory and depend on this variable
  460. if(ENABLE_SERVER_LIB AND NOT CMAKE_PARENT_LIST_FILE STREQUAL CMAKE_CURRENT_LIST_FILE)
  461. set(MK_LINK_LIBRARIES ${MK_LINK_LIBRARIES} PARENT_SCOPE)
  462. endif()
  463. # IOS 不编译可执行程序
  464. # IOS does not compile executable programs
  465. if(IOS)
  466. return()
  467. endif()
  468. #cpp测试demo程序
  469. #cpp test demo program
  470. if (ENABLE_TESTS)
  471. add_subdirectory(tests)
  472. endif ()
  473. # 拷贝www文件夹、配置文件、默认证书
  474. # Copy www folder, configuration file, default certificate
  475. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/www" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
  476. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/conf/config.ini" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
  477. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/default.pem" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
  478. # 拷贝VideoStack 无视频流时默认填充的背景图片
  479. # Copy the default background image used by VideoStack when there is no video stream
  480. if (ENABLE_VIDEOSTACK AND ENABLE_FFMPEG AND ENABLE_X264)
  481. file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/conf/novideo.yuv" DESTINATION ${EXECUTABLE_OUTPUT_PATH})
  482. endif ()