CMakeLists.txt 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. #
  2. # SRT - Secure, Reliable, Transport
  3. # Copyright (c) 2018 Haivision Systems Inc.
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public
  6. # License, v. 2.0. If a copy of the MPL was not distributed with this
  7. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. #
  9. cmake_minimum_required (VERSION 2.8.12 FATAL_ERROR)
  10. set (SRT_VERSION 1.5.3)
  11. set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
  12. include(haiUtil) # needed for set_version_variables
  13. # CMake version 3.0 introduced the VERSION option of the project() command
  14. # to specify a project version as well as the name.
  15. if(${CMAKE_VERSION} VERSION_LESS "3.0.0")
  16. project(SRT C CXX)
  17. # Sets SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH
  18. set_version_variables(SRT_VERSION ${SRT_VERSION})
  19. else()
  20. cmake_policy(SET CMP0048 NEW)
  21. # Also sets SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH
  22. project(SRT VERSION ${SRT_VERSION} LANGUAGES C CXX)
  23. endif()
  24. include(FindPkgConfig)
  25. # XXX See 'if (MINGW)' condition below, may need fixing.
  26. include(FindThreads)
  27. include(CheckFunctionExists)
  28. # Platform shortcuts
  29. string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSNAME_LC)
  30. set_if(DARWIN (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  31. OR (${CMAKE_SYSTEM_NAME} MATCHES "iOS")
  32. OR (${CMAKE_SYSTEM_NAME} MATCHES "tvOS")
  33. OR (${CMAKE_SYSTEM_NAME} MATCHES "watchOS"))
  34. set_if(LINUX ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  35. set_if(BSD ${SYSNAME_LC} MATCHES "bsd$")
  36. set_if(MICROSOFT WIN32 AND (NOT MINGW AND NOT CYGWIN))
  37. set_if(GNU ${CMAKE_SYSTEM_NAME} MATCHES "GNU")
  38. set_if(ANDROID ${SYSNAME_LC} MATCHES "android")
  39. set_if(SUNOS "${SYSNAME_LC}" MATCHES "sunos")
  40. set_if(POSIX LINUX OR DARWIN OR BSD OR SUNOS OR ANDROID OR (CYGWIN AND CYGWIN_USE_POSIX))
  41. set_if(SYMLINKABLE LINUX OR DARWIN OR BSD OR SUNOS OR CYGWIN OR GNU)
  42. set_if(NEED_DESTINATION ${CMAKE_VERSION} VERSION_LESS "3.14.0")
  43. include(GNUInstallDirs)
  44. # The CMAKE_BUILD_TYPE seems not to be always set, weird.
  45. if (NOT DEFINED ENABLE_DEBUG)
  46. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  47. set (ENABLE_DEBUG ON)
  48. else()
  49. set (ENABLE_DEBUG OFF)
  50. endif()
  51. endif()
  52. # XXX This is a kind of workaround - this part to set the build
  53. # type and associated other flags should not be done for build
  54. # systems (cmake generators) that generate a multi-configuration
  55. # build definition. At least it is known that MSVC does it and it
  56. # sets _DEBUG and NDEBUG flags itself, so this shouldn't be done
  57. # at all in this case.
  58. if (NOT MICROSOFT)
  59. # Set CMAKE_BUILD_TYPE properly, now that you know
  60. # that ENABLE_DEBUG is set as it should.
  61. if (ENABLE_DEBUG EQUAL 2)
  62. set (CMAKE_BUILD_TYPE "RelWithDebInfo")
  63. add_definitions(-DNDEBUG)
  64. elseif (ENABLE_DEBUG) # 1, ON, YES, TRUE, Y, or any other non-zero number
  65. set (CMAKE_BUILD_TYPE "Debug")
  66. # Add _DEBUG macro in debug mode only, to enable SRT_ASSERT().
  67. add_definitions(-D_DEBUG)
  68. else()
  69. set (CMAKE_BUILD_TYPE "Release")
  70. add_definitions(-DNDEBUG)
  71. endif()
  72. endif()
  73. message(STATUS "BUILD TYPE: ${CMAKE_BUILD_TYPE}")
  74. getVarsWith(ENFORCE_ enforcers)
  75. foreach(ef ${enforcers})
  76. set (val ${${ef}})
  77. if (NOT val STREQUAL "")
  78. set(val =${val})
  79. endif()
  80. string(LENGTH ENFORCE_ pflen)
  81. string(LENGTH ${ef} eflen)
  82. math(EXPR alen ${eflen}-${pflen})
  83. string(SUBSTRING ${ef} ${pflen} ${alen} ef)
  84. message(STATUS "FORCED PP VARIABLE: ${ef}${val}")
  85. add_definitions(-D${ef}${val})
  86. endforeach()
  87. # NOTE: Known options you can change using ENFORCE_ variables:
  88. # SRT_ENABLE_ECN 1 /* Early Congestion Notification (for source bitrate control) */
  89. # SRT_DEBUG_TSBPD_OUTJITTER 1 /* Packet Delivery histogram */
  90. # SRT_DEBUG_TRACE_DRIFT 1 /* Create a trace log for Encoder-Decoder Clock Drift */
  91. # SRT_DEBUG_TSBPD_WRAP 1 /* Debug packet timestamp wraparound */
  92. # SRT_DEBUG_TLPKTDROP_DROPSEQ 1
  93. # SRT_DEBUG_SNDQ_HIGHRATE 1
  94. # SRT_DEBUG_BONDING_STATES 1
  95. # SRT_DEBUG_RTT 1 /* RTT trace */
  96. # SRT_MAVG_SAMPLING_RATE 40 /* Max sampling rate */
  97. # option defaults
  98. set(ENABLE_HEAVY_LOGGING_DEFAULT OFF)
  99. # Always turn logging on if the build type is debug
  100. if (ENABLE_DEBUG)
  101. set(ENABLE_HEAVY_LOGGING_DEFAULT ON)
  102. endif()
  103. # Note that the IP_PKTINFO has a limited portability and may not work on some platforms
  104. # (Windows, FreeBSD, ...).
  105. set (ENABLE_PKTINFO_DEFAULT OFF)
  106. set(ENABLE_STDCXX_SYNC_DEFAULT OFF)
  107. set(ENABLE_MONOTONIC_CLOCK_DEFAULT OFF)
  108. set(MONOTONIC_CLOCK_LINKLIB "")
  109. if (MICROSOFT)
  110. set(ENABLE_STDCXX_SYNC_DEFAULT ON)
  111. elseif (POSIX)
  112. test_requires_clock_gettime(ENABLE_MONOTONIC_CLOCK_DEFAULT MONOTONIC_CLOCK_LINKLIB)
  113. endif()
  114. # options
  115. option(CYGWIN_USE_POSIX "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin." OFF)
  116. if (CMAKE_CXX_COMPILER_ID MATCHES "^GNU$" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
  117. option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" OFF)
  118. else()
  119. option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ON)
  120. endif()
  121. option(ENABLE_APPS "Should the Support Applications be Built?" ON)
  122. option(ENABLE_BONDING "Should the bonding functionality be enabled?" OFF)
  123. option(ENABLE_TESTING "Should the Developer Test Applications be Built?" OFF)
  124. option(ENABLE_PROFILE "Should instrument the code for profiling. Ignored for non-GNU compiler." $ENV{HAI_BUILD_PROFILE})
  125. option(ENABLE_LOGGING "Should logging be enabled" ON)
  126. option(ENABLE_HEAVY_LOGGING "Should heavy debug logging be enabled" ${ENABLE_HEAVY_LOGGING_DEFAULT})
  127. option(ENABLE_HAICRYPT_LOGGING "Should logging in haicrypt be enabled" 0)
  128. option(ENABLE_SHARED "Should libsrt be built as a shared library" ON)
  129. option(ENABLE_STATIC "Should libsrt be built as a static library" ON)
  130. option(ENABLE_PKTINFO "Enable using IP_PKTINFO to allow the listener extracting the target IP address from incoming packets" ${ENABLE_PKTINFO_DEFAULT})
  131. option(ENABLE_RELATIVE_LIBPATH "Should application contain relative library paths, like ../lib" OFF)
  132. option(ENABLE_GETNAMEINFO "In-logs sockaddr-to-string should do rev-dns" OFF)
  133. option(ENABLE_UNITTESTS "Enable unit tests" OFF)
  134. option(ENABLE_ENCRYPTION "Enable encryption in SRT" ON)
  135. option(ENABLE_AEAD_API_PREVIEW "Enable AEAD API preview in SRT" Off)
  136. option(ENABLE_MAXREXMITBW "Enable SRTO_MAXREXMITBW (v1.6.0 API preview)" Off)
  137. option(ENABLE_CXX_DEPS "Extra library dependencies in srt.pc for the CXX libraries useful with C language" ON)
  138. option(USE_STATIC_LIBSTDCXX "Should use static rather than shared libstdc++" OFF)
  139. option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
  140. option(ENABLE_CODE_COVERAGE "Enable code coverage reporting" OFF)
  141. option(ENABLE_MONOTONIC_CLOCK "Enforced clock_gettime with monotonic clock on GC CV" ${ENABLE_MONOTONIC_CLOCK_DEFAULT})
  142. option(ENABLE_STDCXX_SYNC "Use C++11 chrono and threads for timing instead of pthreads" ${ENABLE_STDCXX_SYNC_DEFAULT})
  143. option(USE_OPENSSL_PC "Use pkg-config to find OpenSSL libraries" ON)
  144. option(OPENSSL_USE_STATIC_LIBS "Link OpenSSL libraries statically." OFF)
  145. option(USE_BUSY_WAITING "Enable more accurate sending times at a cost of potentially higher CPU load" OFF)
  146. option(USE_GNUSTL "Get c++ library/headers from the gnustl.pc" OFF)
  147. option(ENABLE_SOCK_CLOEXEC "Enable setting SOCK_CLOEXEC on a socket" ON)
  148. option(ENABLE_SHOW_PROJECT_CONFIG "Enable show Project Configuration" OFF)
  149. option(ENABLE_CLANG_TSA "Enable Clang Thread Safety Analysis" OFF)
  150. # NOTE: Use ATOMIC_USE_SRT_SYNC_MUTEX and will override the auto-detection of the
  151. # Atomic implemetation in srtcore/atomic.h.
  152. option(ATOMIC_USE_SRT_SYNC_MUTEX "Use srt::sync::Mutex to Implement Atomics" OFF)
  153. if (ATOMIC_USE_SRT_SYNC_MUTEX)
  154. add_definitions(-DATOMIC_USE_SRT_SYNC_MUTEX=1)
  155. endif()
  156. set(TARGET_srt "srt" CACHE STRING "The name for the SRT library")
  157. # Use application-defined group reader
  158. # (currently the only one implemented)
  159. add_definitions(-DSRT_ENABLE_APP_READER)
  160. # XXX This was added once as experimental, it is now in force for
  161. # write-blocking-mode sockets. Still unclear if all issues around
  162. # closing while data still not written are eliminated.
  163. add_definitions(-DSRT_ENABLE_CLOSE_SYNCH)
  164. if (NOT ENABLE_LOGGING)
  165. set (ENABLE_HEAVY_LOGGING OFF)
  166. message(STATUS "LOGGING: DISABLED")
  167. else()
  168. if (ENABLE_HEAVY_LOGGING)
  169. message(STATUS "LOGGING: HEAVY")
  170. else()
  171. message(STATUS "LOGGING: ENABLED")
  172. endif()
  173. endif()
  174. if (USE_BUSY_WAITING)
  175. message(STATUS "USE_BUSY_WAITING: ON")
  176. list(APPEND SRT_EXTRA_CFLAGS "-DUSE_BUSY_WAITING=1")
  177. else()
  178. message(STATUS "USE_BUSY_WAITING: OFF (default)")
  179. endif()
  180. # Reduce the frequency of some frequent logs, milliseconds
  181. set(SRT_LOG_SLOWDOWN_FREQ_MS_DEFAULT 1000) # 1s
  182. if (NOT DEFINED SRT_LOG_SLOWDOWN_FREQ_MS)
  183. if (ENABLE_HEAVY_LOGGING)
  184. set(SRT_LOG_SLOWDOWN_FREQ_MS 0) # Just show every log message.
  185. else()
  186. set(SRT_LOG_SLOWDOWN_FREQ_MS ${SRT_LOG_SLOWDOWN_FREQ_MS_DEFAULT})
  187. endif()
  188. endif()
  189. if ( CYGWIN AND NOT CYGWIN_USE_POSIX )
  190. set(WIN32 1)
  191. set(CMAKE_LEGACY_CYGWIN_WIN32 1)
  192. add_definitions(-DWIN32=1 -DCYGWIN=1)
  193. message(STATUS "HAVE CYGWIN. Setting backward compat CMAKE_LEGACY_CYGWIN_WIN32 and -DWIN32")
  194. endif()
  195. if (NOT USE_ENCLIB)
  196. if (USE_GNUTLS)
  197. message("NOTE: USE_GNUTLS is deprecated. Use -DUSE_ENCLIB=gnutls instead.")
  198. set (USE_ENCLIB gnutls)
  199. else()
  200. set (USE_ENCLIB openssl)
  201. endif()
  202. endif()
  203. set(USE_ENCLIB "${USE_ENCLIB}" CACHE STRING "The crypto library that SRT uses")
  204. set_property(CACHE USE_ENCLIB PROPERTY STRINGS "openssl" "gnutls" "mbedtls")
  205. # Make sure DLLs and executabes go to the same path regardles of subdirectory
  206. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  207. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  208. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
  209. if (NOT DEFINED WITH_COMPILER_TYPE)
  210. # This is for a case when you provided the prefix, but you didn't
  211. # provide compiler type. This option is in this form predicted to work
  212. # only on POSIX systems. Just typical compilers for Linux and Mac are
  213. # included.
  214. if (DARWIN)
  215. set (WITH_COMPILER_TYPE clang)
  216. elseif (POSIX) # Posix, but not DARWIN
  217. set(WITH_COMPILER_TYPE gcc)
  218. else()
  219. get_filename_component(WITH_COMPILER_TYPE ${CMAKE_C_COMPILER} NAME)
  220. endif()
  221. set (USING_DEFAULT_COMPILER_PREFIX 1)
  222. endif()
  223. if (NOT USING_DEFAULT_COMPILER_PREFIX OR DEFINED WITH_COMPILER_PREFIX)
  224. message(STATUS "Handling compiler with PREFIX=${WITH_COMPILER_PREFIX} TYPE=${WITH_COMPILER_TYPE}")
  225. parse_compiler_type(${WITH_COMPILER_TYPE} COMPILER_TYPE COMPILER_SUFFIX)
  226. if (${COMPILER_TYPE} STREQUAL gcc)
  227. set (CMAKE_C_COMPILER ${WITH_COMPILER_PREFIX}gcc${COMPILER_SUFFIX})
  228. set (CMAKE_CXX_COMPILER ${WITH_COMPILER_PREFIX}g++${COMPILER_SUFFIX})
  229. set (HAVE_COMPILER_GNU_COMPAT 1)
  230. elseif (${COMPILER_TYPE} STREQUAL cc)
  231. set (CMAKE_C_COMPILER ${WITH_COMPILER_PREFIX}cc${COMPILER_SUFFIX})
  232. set (CMAKE_CXX_COMPILER ${WITH_COMPILER_PREFIX}c++${COMPILER_SUFFIX})
  233. set (HAVE_COMPILER_GNU_COMPAT 1)
  234. elseif (${COMPILER_TYPE} STREQUAL icc)
  235. set (CMAKE_C_COMPILER ${WITH_COMPILER_PREFIX}icc${COMPILER_SUFFIX})
  236. set (CMAKE_CXX_COMPILER ${WITH_COMPILER_PREFIX}icpc${COMPILER_SUFFIX})
  237. set (HAVE_COMPILER_GNU_COMPAT 1)
  238. else()
  239. # Use blindly <command> for C compiler and <command>++ for C++.
  240. # At least this matches clang.
  241. set (CMAKE_C_COMPILER ${WITH_COMPILER_PREFIX}${WITH_COMPILER_TYPE})
  242. set (CMAKE_CXX_COMPILER ${WITH_COMPILER_PREFIX}${COMPILER_TYPE}++${COMPILER_SUFFIX})
  243. if (${COMPILER_TYPE} STREQUAL clang)
  244. set (HAVE_COMPILER_GNU_COMPAT 1)
  245. endif()
  246. endif()
  247. message(STATUS "Compiler type: ${WITH_COMPILER_TYPE}. C: ${CMAKE_C_COMPILER}; C++: ${CMAKE_CXX_COMPILER}")
  248. unset(USING_DEFAULT_COMPILER_PREFIX)
  249. else()
  250. message(STATUS "No WITH_COMPILER_PREFIX - using C++ compiler ${CMAKE_CXX_COMPILER}")
  251. endif()
  252. if (DEFINED WITH_SRT_TARGET)
  253. set (TARGET_haisrt ${WITH_SRT_TARGET})
  254. endif()
  255. # When you use crosscompiling, you have to take care that PKG_CONFIG_PATH
  256. # and CMAKE_PREFIX_PATH are set properly.
  257. # symbol exists in win32, but function does not.
  258. if(WIN32)
  259. if(ENABLE_INET_PTON)
  260. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  261. check_function_exists(inet_pton HAVE_INET_PTON)
  262. try_compile(AT_LEAST_VISTA
  263. ${CMAKE_BINARY_DIR}
  264. "${CMAKE_CURRENT_SOURCE_DIR}/scripts/test_vista.c")
  265. if(NOT AT_LEAST_VISTA)
  266. # force targeting Vista
  267. add_definitions(-D_WIN32_WINNT=0x0600)
  268. endif()
  269. else()
  270. add_definitions(-D_WIN32_WINNT=0x0501)
  271. endif()
  272. else()
  273. check_function_exists(inet_pton HAVE_INET_PTON)
  274. endif()
  275. if (DEFINED HAVE_INET_PTON)
  276. add_definitions(-DHAVE_INET_PTON=1)
  277. endif()
  278. # Defines HAVE_PTHREAD_GETNAME_* and HAVE_PTHREAD_SETNAME_*
  279. include(FindPThreadGetSetName)
  280. FindPThreadGetSetName()
  281. if (ENABLE_MONOTONIC_CLOCK)
  282. if (NOT ENABLE_MONOTONIC_CLOCK_DEFAULT)
  283. message(FATAL_ERROR "Your platform does not support CLOCK_MONOTONIC. Build with -DENABLE_MONOTONIC_CLOCK=OFF.")
  284. endif()
  285. set (WITH_EXTRALIBS "${WITH_EXTRALIBS} ${MONOTONIC_CLOCK_LINKLIB}")
  286. add_definitions(-DENABLE_MONOTONIC_CLOCK=1)
  287. endif()
  288. if (ENABLE_ENCRYPTION)
  289. if ("${USE_ENCLIB}" STREQUAL "gnutls")
  290. set (SSL_REQUIRED_MODULES "gnutls nettle")
  291. if (WIN32)
  292. if (MINGW)
  293. set (SSL_REQUIRED_MODULES "${SSL_REQUIRED_MODULES} zlib")
  294. endif()
  295. endif()
  296. pkg_check_modules (SSL REQUIRED ${SSL_REQUIRED_MODULES})
  297. add_definitions(
  298. -DUSE_GNUTLS=1
  299. )
  300. link_directories(
  301. ${SSL_LIBRARY_DIRS}
  302. )
  303. elseif ("${USE_ENCLIB}" STREQUAL "mbedtls")
  304. add_definitions(-DUSE_MBEDTLS=1)
  305. if ("${SSL_LIBRARY_DIRS}" STREQUAL "")
  306. set(MBEDTLS_PREFIX "${CMAKE_PREFIX_PATH}" CACHE PATH "The path of mbedtls")
  307. find_package(MbedTLS REQUIRED)
  308. set (SSL_INCLUDE_DIRS ${MBEDTLS_INCLUDE_DIR})
  309. set (SSL_LIBRARIES ${MBEDTLS_LIBRARIES})
  310. endif()
  311. if ("${SSL_LIBRARIES}" STREQUAL "")
  312. set (SSL_LIBRARIES mbedtls mbedcrypto)
  313. endif()
  314. message(STATUS "SSL enforced mbedtls: -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
  315. foreach(LIB ${SSL_LIBRARIES})
  316. if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
  317. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${LIB})
  318. else()
  319. set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} "-l${LIB}")
  320. endif()
  321. endforeach()
  322. elseif ("${USE_ENCLIB}" STREQUAL "openssl-evp")
  323. # Openssl-EVP requires CRYSPR2
  324. add_definitions(-DUSE_OPENSSL_EVP=1 -DCRYSPR2)
  325. set (SSL_REQUIRED_MODULES "openssl libcrypto")
  326. # Try using pkg-config method first if enabled,
  327. # fall back to find_package method otherwise
  328. if (USE_OPENSSL_PC)
  329. pkg_check_modules(SSL ${SSL_REQUIRED_MODULES})
  330. if (OPENSSL_USE_STATIC_LIBS)
  331. # use `pkg-config --static xxx` found libs
  332. set(SSL_LIBRARIES ${SSL_STATIC_LIBRARIES})
  333. endif()
  334. endif()
  335. if (SSL_FOUND)
  336. # We have some cases when pkg-config is improperly configured
  337. # When it doesn't ship the -L and -I options, and the CMAKE_PREFIX_PATH
  338. # is set (also through `configure`), then we have this problem. If so,
  339. # set forcefully the -I and -L contents to prefix/include and
  340. # prefix/lib.
  341. if ("${SSL_LIBRARY_DIRS}" STREQUAL "")
  342. if (NOT "${CMAKE_PREFIX_PATH}" STREQUAL "")
  343. message(STATUS "WARNING: pkg-config has incorrect prefix - enforcing target path prefix: ${CMAKE_PREFIX_PATH}")
  344. set (SSL_LIBRARY_DIRS ${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR})
  345. set (SSL_INCLUDE_DIRS ${CMAKE_PREFIX_PATH}/include)
  346. endif()
  347. endif()
  348. link_directories(
  349. ${SSL_LIBRARY_DIRS}
  350. )
  351. message(STATUS "SSL via pkg-config: -L ${SSL_LIBRARY_DIRS} -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
  352. else()
  353. find_package(OpenSSL REQUIRED)
  354. set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
  355. set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
  356. message(STATUS "SSL via find_package(OpenSSL): -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
  357. endif()
  358. else() # openssl
  359. # Openssl (Direct-AES API) can use CRYSPR2
  360. add_definitions(-DUSE_OPENSSL=1 -DCRYSPR2)
  361. set (SSL_REQUIRED_MODULES "openssl libcrypto")
  362. # Try using pkg-config method first if enabled,
  363. # fall back to find_package method otherwise
  364. if (USE_OPENSSL_PC)
  365. pkg_check_modules(SSL ${SSL_REQUIRED_MODULES})
  366. endif()
  367. if (SSL_FOUND)
  368. # We have some cases when pkg-config is improperly configured
  369. # When it doesn't ship the -L and -I options, and the CMAKE_PREFIX_PATH
  370. # is set (also through `configure`), then we have this problem. If so,
  371. # set forcefully the -I and -L contents to prefix/include and
  372. # prefix/lib.
  373. if ("${SSL_LIBRARY_DIRS}" STREQUAL "")
  374. if (NOT "${CMAKE_PREFIX_PATH}" STREQUAL "")
  375. message(STATUS "WARNING: pkg-config has incorrect prefix - enforcing target path prefix: ${CMAKE_PREFIX_PATH}")
  376. set (SSL_LIBRARY_DIRS ${CMAKE_PREFIX_PATH}/${CMAKE_INSTALL_LIBDIR})
  377. set (SSL_INCLUDE_DIRS ${CMAKE_PREFIX_PATH}/include)
  378. endif()
  379. endif()
  380. link_directories(
  381. ${SSL_LIBRARY_DIRS}
  382. )
  383. message(STATUS "SSL via pkg-config: -L ${SSL_LIBRARY_DIRS} -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
  384. else()
  385. find_package(OpenSSL REQUIRED)
  386. set (SSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
  387. set (SSL_LIBRARIES ${OPENSSL_LIBRARIES})
  388. message(STATUS "SSL via find_package(OpenSSL): -I ${SSL_INCLUDE_DIRS} -l;${SSL_LIBRARIES}")
  389. endif()
  390. endif()
  391. add_definitions(-DSRT_ENABLE_ENCRYPTION)
  392. message(STATUS "ENCRYPTION: ENABLED, using: ${SSL_REQUIRED_MODULES}")
  393. message (STATUS "SSL libraries: ${SSL_LIBRARIES}")
  394. if (ENABLE_AEAD_API_PREVIEW)
  395. if ("${USE_ENCLIB}" STREQUAL "openssl-evp")
  396. add_definitions(-DENABLE_AEAD_API_PREVIEW)
  397. message(STATUS "ENCRYPTION AEAD API: ENABLED")
  398. else()
  399. message(FATAL_ERROR "ENABLE_AEAD_API_PREVIEW is only available with USE_ENCLIB=openssl-evp!")
  400. endif()
  401. else()
  402. message(STATUS "ENCRYPTION AEAD API: DISABLED")
  403. endif()
  404. else()
  405. message(STATUS "ENCRYPTION: DISABLED")
  406. message(STATUS "ENCRYPTION AEAD API: N/A")
  407. endif()
  408. if (USE_GNUSTL)
  409. pkg_check_modules (GNUSTL REQUIRED gnustl)
  410. link_directories(${GNUSTL_LIBRARY_DIRS})
  411. include_directories(${GNUSTL_INCLUDE_DIRS})
  412. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${GNUSTL_LIBRARIES} ${GNUSTL_LDFLAGS})
  413. endif()
  414. if (ENABLE_MAXREXMITBW)
  415. add_definitions(-DENABLE_MAXREXMITBW)
  416. message(STATUS "MAXREXMITBW API: ENABLED")
  417. else()
  418. message(STATUS "MAXREXMITBW API: DISABLED")
  419. endif()
  420. if (USING_DEFAULT_COMPILER_PREFIX)
  421. # Detect if the compiler is GNU compatible for flags
  422. if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Intel|Clang|AppleClang")
  423. message(STATUS "COMPILER: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) - GNU compat")
  424. set(HAVE_COMPILER_GNU_COMPAT 1)
  425. # See https://gcc.gnu.org/projects/cxx-status.html
  426. # At the bottom there's information about C++98, which is default up to 6.1 version.
  427. # For all other compilers - including Clang - we state that the default C++ standard is AT LEAST 11.
  428. if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 6.1)
  429. message(STATUS "NOTE: GCC ${CMAKE_CXX_COMPILER_VERSION} is detected with default C++98. Forcing C++11 on applications.")
  430. set (FORCE_CXX_STANDARD 1)
  431. elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang|AppleClang")
  432. message(STATUS "NOTE: CLANG ${CMAKE_CXX_COMPILER_VERSION} detected, unsure if >=C++11 is default, forcing C++11 on applications")
  433. set (FORCE_CXX_STANDARD 1)
  434. else()
  435. message(STATUS "NOTE: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} - assuming default C++11.")
  436. endif()
  437. else()
  438. message(STATUS "COMPILER: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER}) - NOT GNU compat")
  439. set(HAVE_COMPILER_GNU_COMPAT 0)
  440. endif()
  441. else() # Compiler altered by WITH_COMPILER_TYPE/PREFIX - can't rely on CMAKE_CXX_*
  442. # Force the C++ standard as C++11
  443. # HAVE_COMPILER_GNU_COMPAT was set in the handler of WITH_COMPILER_TYPE
  444. set (FORCE_CXX_STANDARD 1)
  445. message(STATUS "COMPILER CHANGED TO: ${COMPILER_TYPE} - forcing C++11 standard for apps")
  446. endif()
  447. # Check for GCC Atomic Intrinsics and C++11 Atomics.
  448. # Sets:
  449. # HAVE_LIBATOMIC
  450. # HAVE_LIBATOMIC_COMPILES
  451. # HAVE_LIBATOMIC_COMPILES_STATIC
  452. # HAVE_GCCATOMIC_INTRINSICS
  453. # HAVE_GCCATOMIC_INTRINSICS_REQUIRES_LIBATOMIC
  454. include(CheckGCCAtomicIntrinsics)
  455. CheckGCCAtomicIntrinsics()
  456. # HAVE_CXX_ATOMIC
  457. # HAVE_CXX_ATOMIC_STATIC
  458. include(CheckCXXAtomic)
  459. CheckCXXAtomic()
  460. # Check for std::put_time():
  461. # Sets:
  462. # HAVE_CXX_STD_PUT_TIME
  463. include(CheckCXXStdPutTime)
  464. CheckCXXStdPutTime()
  465. if (HAVE_CXX_STD_PUT_TIME)
  466. add_definitions(-DHAVE_CXX_STD_PUT_TIME=1)
  467. endif()
  468. if (DISABLE_CXX11)
  469. set (ENABLE_CXX11 0)
  470. elseif( DEFINED ENABLE_CXX11 )
  471. else()
  472. set (ENABLE_CXX11 1)
  473. endif()
  474. function (srt_check_cxxstd stdval OUT_STD OUT_PFX)
  475. set (STDPFX c++)
  476. if (stdval MATCHES "([^+]+\\++)([0-9]*)")
  477. set (STDPFX ${CMAKE_MATCH_1})
  478. set (STDCXX ${CMAKE_MATCH_2})
  479. elseif (stdval MATCHES "[0-9]*")
  480. set (STDCXX ${stdval})
  481. else()
  482. set (STDCXX 0)
  483. endif()
  484. # Handle C++98 < C++11
  485. # Please fix this around 2070 year.
  486. if (${STDCXX} GREATER 80)
  487. set (STDCXX 03)
  488. endif()
  489. # return
  490. set (${OUT_STD} ${STDCXX} PARENT_SCOPE)
  491. set (${OUT_PFX} ${STDPFX} PARENT_SCOPE)
  492. endfunction()
  493. if (NOT ENABLE_CXX11)
  494. message(WARNING "Parts that require C++11 support will be disabled (srt-live-transmit)")
  495. if (ENABLE_STDCXX_SYNC)
  496. message(FATAL_ERROR "ENABLE_STDCXX_SYNC is set, but C++11 is disabled by ENABLE_CXX11")
  497. endif()
  498. elseif (ENABLE_STDCXX_SYNC)
  499. add_definitions(-DENABLE_STDCXX_SYNC=1)
  500. if (DEFINED USE_CXX_STD)
  501. srt_check_cxxstd(${USE_CXX_STD} STDCXX STDPFX)
  502. # If defined, make sure it's at least C++11
  503. if (${STDCXX} LESS 11)
  504. message(FATAL_ERROR "If ENABLE_STDCXX_SYNC, then USE_CXX_STD must specify at least C++11")
  505. endif()
  506. else()
  507. set (USE_CXX_STD 11)
  508. endif()
  509. endif()
  510. message(STATUS "STDCXX_SYNC: ${ENABLE_STDCXX_SYNC}")
  511. message(STATUS "MONOTONIC_CLOCK: ${ENABLE_MONOTONIC_CLOCK}")
  512. if (ENABLE_SOCK_CLOEXEC)
  513. add_definitions(-DENABLE_SOCK_CLOEXEC=1)
  514. endif()
  515. if (CMAKE_MAJOR_VERSION LESS 3)
  516. set (FORCE_CXX_STANDARD_GNUONLY 1)
  517. endif()
  518. if (DEFINED USE_CXX_STD)
  519. srt_check_cxxstd(${USE_CXX_STD} STDCXX STDPFX)
  520. if (${STDCXX} EQUAL 0)
  521. message(FATAL_ERROR "USE_CXX_STD: Must specify 03/11/14/17/20 possibly with c++/gnu++ prefix")
  522. endif()
  523. if (NOT STDCXX STREQUAL "")
  524. if (${STDCXX} LESS 11)
  525. if (ENABLE_STDCXX_SYNC)
  526. message(FATAL_ERROR "If ENABLE_STDCXX_SYNC, then you can't USE_CXX_STD less than 11")
  527. endif()
  528. # Set back to 98 because cmake doesn't understand 03.
  529. set (STDCXX 98)
  530. # This enforces C++03 standard on SRT.
  531. # Apps still use C++11
  532. # Set this through independent flags
  533. set (USE_CXX_STD_LIB ${STDCXX})
  534. set (FORCE_CXX_STANDARD 1)
  535. if (NOT ENABLE_APPS)
  536. set (USE_CXX_STD_APP ${STDCXX})
  537. message(STATUS "C++ STANDARD: library: C++${STDCXX}, apps disabled (examples will follow C++${STDCXX})")
  538. else()
  539. set (USE_CXX_STD_APP "")
  540. message(STATUS "C++ STANDARD: library: C++${STDCXX}, but apps still at least C++11")
  541. endif()
  542. elseif (FORCE_CXX_STANDARD_GNUONLY)
  543. # CMake is too old to handle CMAKE_CXX_STANDARD,
  544. # use bare GNU options.
  545. set (FORCE_CXX_STANDARD 1)
  546. set (USE_CXX_STD_APP ${STDCXX})
  547. set (USE_CXX_STD_LIB ${STDCXX})
  548. message(STATUS "C++ STANDARD: using C++${STDCXX} for all - GNU only")
  549. else()
  550. # This enforces this standard on both apps and library,
  551. # so set this as global C++ standard option
  552. set (CMAKE_CXX_STANDARD ${STDCXX})
  553. unset (FORCE_CXX_STANDARD)
  554. # Do not set variables to not duplicate flags
  555. set (USE_CXX_STD_LIB "")
  556. set (USE_CXX_STD_APP "")
  557. message(STATUS "C++ STANDARD: using C++${STDCXX} for all")
  558. endif()
  559. message(STATUS "C++: Setting C++ standard for gnu compiler: lib: ${USE_CXX_STD_LIB} apps: ${USE_CXX_STD_APP}")
  560. endif()
  561. else()
  562. set (USE_CXX_STD_LIB "")
  563. set (USE_CXX_STD_APP "")
  564. endif()
  565. if (FORCE_CXX_STANDARD)
  566. message(STATUS "C++ STD: Forcing C++11 on applications")
  567. if (USE_CXX_STD_APP STREQUAL "")
  568. set (USE_CXX_STD_APP 11)
  569. endif()
  570. if (USE_CXX_STD_LIB STREQUAL "" AND ENABLE_STDCXX_SYNC)
  571. message(STATUS "C++ STD: Forcing C++11 on library, as C++11 sync requested")
  572. set (USE_CXX_STD_LIB 11)
  573. endif()
  574. endif()
  575. # add extra warning flags for gccish compilers
  576. if (HAVE_COMPILER_GNU_COMPAT)
  577. set (SRT_GCC_WARN "-Wall -Wextra")
  578. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  579. set (SRT_GCC_WARN "${SRT_GCC_WARN} -Wshadow=local")
  580. endif()
  581. else()
  582. # cpp debugging on Windows :D
  583. #set (SRT_GCC_WARN "/showIncludes")
  584. endif()
  585. if (USE_STATIC_LIBSTDCXX)
  586. if (HAVE_COMPILER_GNU_COMPAT)
  587. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
  588. else()
  589. message(FATAL_ERROR "On non-GNU-compat compiler it's not known how to use static C++ standard library.")
  590. endif()
  591. endif()
  592. # This options is necessary on some systems; on a cross-ARM compiler it
  593. # has been detected, for example, that -lrt is necessary for some applications
  594. # because clock_gettime is needed by some functions and it is alternatively
  595. # provided by libc, but only in newer versions. This options is rarely necessary,
  596. # but may help in several corner cases in unusual platforms.
  597. if (WITH_EXTRALIBS)
  598. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WITH_EXTRALIBS}")
  599. endif()
  600. # CMake has only discovered in 3.3 version that some set-finder is
  601. # necessary. Using variables for shortcut to a clumsy check syntax.
  602. set (srt_libspec_shared ${ENABLE_SHARED})
  603. set (srt_libspec_static ${ENABLE_STATIC})
  604. set (srtpack_libspec_common)
  605. if (srt_libspec_shared)
  606. list(APPEND srtpack_libspec_common ${TARGET_srt}_shared)
  607. endif()
  608. if (srt_libspec_static)
  609. list(APPEND srtpack_libspec_common ${TARGET_srt}_static)
  610. endif()
  611. set (SRT_SRC_HAICRYPT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/haicrypt)
  612. set (SRT_SRC_SRTCORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/srtcore)
  613. set (SRT_SRC_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common)
  614. set (SRT_SRC_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)
  615. set (SRT_SRC_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
  616. if(WIN32)
  617. message(STATUS "DETECTED SYSTEM: WINDOWS; WIN32=1; PTW32_STATIC_LIB=1")
  618. add_definitions(-DWIN32=1 -DPTW32_STATIC_LIB=1)
  619. elseif(DARWIN)
  620. message(STATUS "DETECTED SYSTEM: DARWIN")
  621. elseif(BSD)
  622. message(STATUS "DETECTED SYSTEM: BSD; BSD=1")
  623. add_definitions(-DBSD=1)
  624. elseif(LINUX)
  625. add_definitions(-DLINUX=1)
  626. message(STATUS "DETECTED SYSTEM: LINUX; LINUX=1" )
  627. elseif(ANDROID)
  628. add_definitions(-DLINUX=1)
  629. message(STATUS "DETECTED SYSTEM: ANDROID; LINUX=1" )
  630. elseif(CYGWIN)
  631. add_definitions(-DCYGWIN=1)
  632. message(STATUS "DETECTED SYSTEM: CYGWIN (posix mode); CYGWIN=1")
  633. elseif(GNU)
  634. add_definitions(-DGNU=1)
  635. message(STATUS "DETECTED SYSTEM: GNU; GNU=1" )
  636. elseif(SUNOS)
  637. add_definitions(-DSUNOS=1)
  638. message(STATUS "DETECTED SYSTEM: SunOS|Solaris; SUNOS=1" )
  639. else()
  640. message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
  641. endif()
  642. add_definitions(
  643. -D_GNU_SOURCE
  644. -DHAI_PATCH=1
  645. -DHAI_ENABLE_SRT=1
  646. -DSRT_VERSION="${SRT_VERSION}"
  647. )
  648. if (LINUX)
  649. # This is an option supported only on Linux
  650. add_definitions(-DSRT_ENABLE_BINDTODEVICE)
  651. endif()
  652. # This is obligatory include directory for all targets. This is only
  653. # for private headers. Installable headers should be exclusively used DIRECTLY.
  654. include_directories(${SRT_SRC_COMMON_DIR} ${SRT_SRC_SRTCORE_DIR} ${SRT_SRC_HAICRYPT_DIR})
  655. if (ENABLE_LOGGING)
  656. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_LOGGING=1")
  657. if (ENABLE_HEAVY_LOGGING)
  658. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_HEAVY_LOGGING=1")
  659. endif()
  660. if (ENABLE_HAICRYPT_LOGGING)
  661. if (ENABLE_HAICRYPT_LOGGING STREQUAL 2) # Allow value 2 for INSECURE DEBUG logging
  662. message(WARNING " *** ENABLED INSECURE HAICRYPT LOGGING - USE FOR TESTING ONLY!!! ***")
  663. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_HAICRYPT_LOGGING=2")
  664. else()
  665. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_HAICRYPT_LOGGING=1")
  666. endif()
  667. endif()
  668. endif()
  669. if (ENABLE_GETNAMEINFO)
  670. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_GETNAMEINFO=1")
  671. endif()
  672. if (ENABLE_PKTINFO)
  673. if (WIN32 OR BSD)
  674. message(FATAL_ERROR "PKTINFO is not implemented on Windows or *BSD.")
  675. endif()
  676. list(APPEND SRT_EXTRA_CFLAGS "-DSRT_ENABLE_PKTINFO=1")
  677. endif()
  678. # ENABLE_EXPERIMENTAL_BONDING is deprecated. Use ENABLE_BONDING. ENABLE_EXPERIMENTAL_BONDING is be removed in v1.6.0.
  679. if (ENABLE_EXPERIMENTAL_BONDING)
  680. message(DEPRECATION "ENABLE_EXPERIMENTAL_BONDING is deprecated. Please use ENABLE_BONDING instead.")
  681. set (ENABLE_BONDING ON)
  682. endif()
  683. if (ENABLE_BONDING)
  684. list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_BONDING=1")
  685. message(STATUS "ENABLE_BONDING: ON")
  686. else()
  687. message(STATUS "ENABLE_BONDING: OFF")
  688. endif()
  689. if (ENABLE_THREAD_CHECK)
  690. add_definitions(
  691. -DSRT_ENABLE_THREADCHECK=1
  692. -DFUGU_PLATFORM=1
  693. -I${WITH_THREAD_CHECK_INCLUDEDIR}
  694. )
  695. endif()
  696. if (ENABLE_CLANG_TSA)
  697. list(APPEND SRT_EXTRA_CFLAGS "-Wthread-safety")
  698. message(STATUS "Clang TSA: Enabled")
  699. endif()
  700. if (ENABLE_PROFILE)
  701. if (HAVE_COMPILER_GNU_COMPAT)
  702. # They are actually cflags, not definitions, but CMake is stupid enough.
  703. add_definitions(-g -pg)
  704. link_libraries(-g -pg)
  705. else()
  706. message(FATAL_ERROR "Profiling option is not supported on this platform")
  707. endif()
  708. endif()
  709. if (ENABLE_CODE_COVERAGE)
  710. if (HAVE_COMPILER_GNU_COMPAT)
  711. add_definitions(-g -O0 --coverage)
  712. link_libraries(--coverage)
  713. message(STATUS "ENABLE_CODE_COVERAGE: ON")
  714. else()
  715. message(FATAL_ERROR "ENABLE_CODE_COVERAGE: option is not supported on this platform")
  716. endif()
  717. endif()
  718. # On Linux pthreads have to be linked even when using C++11 threads
  719. if (ENABLE_STDCXX_SYNC AND NOT LINUX)
  720. message(STATUS "Pthread library: C++11")
  721. elseif (PTHREAD_LIBRARY AND PTHREAD_INCLUDE_DIR)
  722. message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
  723. message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
  724. elseif (MICROSOFT)
  725. find_package(pthreads QUIET)
  726. if (NOT PTHREAD_INCLUDE_DIR OR NOT PTHREAD_LIBRARY)
  727. #search package folders with GLOB to add as extra hint for headers
  728. file(GLOB PTHREAD_PACKAGE_INCLUDE_HINT ./_packages/cinegy.pthreads-win*/sources)
  729. if (PTHREAD_PACKAGE_INCLUDE_HINT)
  730. message(STATUS "PTHREAD_PACKAGE_INCLUDE_HINT value: ${PTHREAD_PACKAGE_INCLUDE_HINT}")
  731. endif()
  732. # find pthread header
  733. find_path(PTHREAD_INCLUDE_DIR pthread.h HINTS C:/pthread-win32/include ${PTHREAD_PACKAGE_INCLUDE_HINT})
  734. if (PTHREAD_INCLUDE_DIR)
  735. message(STATUS "Pthread include dir: ${PTHREAD_INCLUDE_DIR}")
  736. else()
  737. message(FATAL_ERROR "Failed to find pthread.h. Specify PTHREAD_INCLUDE_DIR.")
  738. endif()
  739. #search package folders with GLOB to add as extra hint for libs
  740. file(GLOB PTHREAD_PACKAGE_LIB_HINT ./_packages/cinegy.pthreads-win*/runtimes/win-*/native/release)
  741. if (PTHREAD_PACKAGE_LIB_HINT)
  742. message(STATUS "PTHREAD_PACKAGE_LIB_HINT value: ${PTHREAD_PACKAGE_LIB_HINT}")
  743. endif()
  744. #find pthread library
  745. set(PTHREAD_LIB_SUFFIX "")
  746. if (ENABLE_DEBUG)
  747. set(PTHREAD_LIB_SUFFIX "d")
  748. endif ()
  749. set(PTHREAD_COMPILER_FLAG "")
  750. if (MICROSOFT)
  751. set(PTHREAD_COMPILER_FLAG "V")
  752. elseif (MINGW)
  753. set(PTHREAD_COMPILER_FLAG "G")
  754. endif ()
  755. foreach(EXHAND C CE SE)
  756. foreach(COMPAT 1 2)
  757. list(APPEND PTHREAD_W32_LIBRARY "pthread${PTHREAD_COMPILER_FLAG}${EXHAND}${PTHREAD_LIB_SUFFIX}${COMPAT}")
  758. endforeach()
  759. endforeach()
  760. find_library(PTHREAD_LIBRARY NAMES ${PTHREAD_W32_LIBRARY} pthread pthread_dll pthread_lib HINTS C:/pthread-win32/lib C:/pthread-win64/lib ${PTHREAD_PACKAGE_LIB_HINT})
  761. if (PTHREAD_LIBRARY)
  762. message(STATUS "Pthread library: ${PTHREAD_LIBRARY}")
  763. else()
  764. message(FATAL_ERROR "Failed to find pthread library. Specify PTHREAD_LIBRARY.")
  765. endif()
  766. endif()
  767. else ()
  768. find_package(Threads REQUIRED)
  769. set(PTHREAD_LIBRARY ${CMAKE_THREAD_LIBS_INIT})
  770. endif()
  771. # This is required in some projects that add some other sources
  772. # to the SRT library to be compiled together (aka "virtual library").
  773. if (DEFINED SRT_EXTRA_LIB_INC)
  774. include(${SRT_EXTRA_LIB_INC}.cmake)
  775. # Expected to provide variables:
  776. # - SOURCES_srt_extra
  777. # - EXTRA_stransmit
  778. endif()
  779. # ---------------------------------------------------------------------------
  780. # ---
  781. # Target: haicrypt.
  782. # Completing sources and installable headers. Flag settings will follow.
  783. # ---
  784. if (ENABLE_ENCRYPTION)
  785. set (HAICRYPT_FILELIST_MAF "filelist-${USE_ENCLIB}.maf")
  786. MafReadDir(haicrypt ${HAICRYPT_FILELIST_MAF}
  787. SOURCES SOURCES_haicrypt
  788. PUBLIC_HEADERS HEADERS_haicrypt
  789. PROTECTED_HEADERS HEADERS_haicrypt
  790. )
  791. endif()
  792. if (WIN32)
  793. MafReadDir(common filelist_win32.maf
  794. SOURCES SOURCES_common
  795. PUBLIC_HEADERS HEADERS_srt_win32
  796. PROTECTED_HEADERS HEADERS_srt_win32
  797. )
  798. message(STATUS "WINDOWS detected: adding compat sources: ${SOURCES_common}")
  799. endif()
  800. # Make the OBJECT library for haicrypt and srt. Then they'll be bound into
  801. # real libraries later, either one common, or separate.
  802. # This is needed for Xcode to properly handle CMake OBJECT Libraries
  803. # From docs (https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries):
  804. #
  805. # ... Some native build systems (such as Xcode) may not like targets that have only object files,
  806. # so consider adding at least one real source file to any target that references $<TARGET_OBJECTS:objlib>.
  807. set(OBJECT_LIB_SUPPORT "${PROJECT_SOURCE_DIR}/cmake_object_lib_support.c")
  808. # NOTE: The "virtual library" is a library specification that cmake
  809. # doesn't support (the library of OBJECT type is something in kind of that,
  810. # but not fully supported - for example it doesn't support transitive flags,
  811. # so this can't be used desired way). It's a private-only dependency type,
  812. # where the project isn't compiled into any library file at all - instead, all
  813. # of its source files are incorporated directly to the source list of the
  814. # project that depends on it. In cmake this must be handled manually.
  815. # ---
  816. # Target: srt. DEFINITION ONLY. Haicrypt flag settings follow.
  817. # ---
  818. if (ENABLE_SHARED AND MICROSOFT)
  819. #add resource files to shared library, to set DLL metadata on Windows DLLs
  820. set (EXTRA_WIN32_SHARED 1)
  821. message(STATUS "WIN32: extra resource file will be added")
  822. endif()
  823. MafReadDir(srtcore filelist.maf
  824. SOURCES SOURCES_srt
  825. PUBLIC_HEADERS HEADERS_srt
  826. PROTECTED_HEADERS HEADERS_srt
  827. PRIVATE_HEADERS HEADERS_srt_private
  828. )
  829. # Auto generated version file and add it to the HEADERS_srt list.
  830. if(DEFINED ENV{APPVEYOR_BUILD_NUMBER})
  831. set(SRT_VERSION_BUILD ON)
  832. set(CI_BUILD_NUMBER_STRING $ENV{APPVEYOR_BUILD_NUMBER})
  833. message(STATUS "AppVeyor build environment detected: Adding build number to version header")
  834. endif()
  835. if(DEFINED ENV{TEAMCITY_VERSION})
  836. set(SRT_VERSION_BUILD ON)
  837. set(CI_BUILD_NUMBER_STRING $ENV{CI_BUILD_COUNTER})
  838. message(STATUS "TeamCity build environment detected: Adding build counter to version header")
  839. endif()
  840. configure_file("srtcore/version.h.in" "version.h" @ONLY)
  841. list(INSERT HEADERS_srt 0 "${CMAKE_CURRENT_BINARY_DIR}/version.h")
  842. include_directories("${CMAKE_CURRENT_BINARY_DIR}")
  843. add_library(srt_virtual OBJECT ${SOURCES_srt} ${SOURCES_srt_extra} ${HEADERS_srt} ${SOURCES_haicrypt} ${SOURCES_common})
  844. if (ENABLE_SHARED)
  845. # Set this to sources as well, as it won't be automatically handled
  846. set_target_properties(srt_virtual PROPERTIES POSITION_INDEPENDENT_CODE 1)
  847. endif()
  848. macro(srt_set_stdcxx targetname spec)
  849. set (stdcxxspec ${spec})
  850. if (NOT "${stdcxxspec}" STREQUAL "")
  851. if (FORCE_CXX_STANDARD_GNUONLY)
  852. target_compile_options(${targetname} PRIVATE -std=c++${stdcxxspec})
  853. message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - GNU option: -std=c++${stdcxxspec}")
  854. else()
  855. set_target_properties(${targetname} PROPERTIES CXX_STANDARD ${stdcxxspec})
  856. message(STATUS "C++ STD: ${targetname}: forced C++${stdcxxspec} standard - portable way")
  857. endif()
  858. else()
  859. message(STATUS "APP: ${targetname}: using default C++ standard")
  860. endif()
  861. endmacro()
  862. srt_set_stdcxx(srt_virtual "${USE_CXX_STD_LIB}")
  863. set (VIRTUAL_srt $<TARGET_OBJECTS:srt_virtual>)
  864. if (srt_libspec_shared)
  865. add_library(${TARGET_srt}_shared SHARED ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})
  866. # shared libraries need PIC
  867. set (CMAKE_POSITION_INDEPENDENT_CODE ON)
  868. set_property(TARGET ${TARGET_srt}_shared PROPERTY OUTPUT_NAME ${TARGET_srt})
  869. set_target_properties (${TARGET_srt}_shared PROPERTIES VERSION ${SRT_VERSION} SOVERSION ${SRT_VERSION_MAJOR}.${SRT_VERSION_MINOR})
  870. list (APPEND INSTALL_TARGETS ${TARGET_srt}_shared)
  871. if (ENABLE_ENCRYPTION)
  872. target_link_libraries(${TARGET_srt}_shared PRIVATE ${SSL_LIBRARIES})
  873. endif()
  874. if (MICROSOFT)
  875. target_link_libraries(${TARGET_srt}_shared PRIVATE ws2_32.lib)
  876. if (OPENSSL_USE_STATIC_LIBS)
  877. target_link_libraries(${TARGET_srt}_shared PRIVATE crypt32.lib)
  878. else()
  879. set_target_properties(${TARGET_srt}_shared PROPERTIES LINK_FLAGS "/DELAYLOAD:libeay32.dll")
  880. endif()
  881. elseif (MINGW)
  882. target_link_libraries(${TARGET_srt}_shared PRIVATE wsock32 ws2_32)
  883. elseif (APPLE)
  884. set_property(TARGET ${TARGET_srt}_shared PROPERTY MACOSX_RPATH ON)
  885. endif()
  886. if (USE_GNUSTL)
  887. target_link_libraries(${TARGET_srt}_shared PRIVATE ${GNUSTL_LIBRARIES} ${GNUSTL_LDFLAGS})
  888. endif()
  889. endif()
  890. if (srt_libspec_static)
  891. add_library(${TARGET_srt}_static STATIC ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})
  892. # For Windows, leave the name to be "srt_static.lib".
  893. # Windows generates two different library files:
  894. # - a usual static library for static linkage
  895. # - a shared library exposer, which allows pre-resolution and later dynamic
  896. # linkage when running the executable
  897. # Both having unfortunately the same names created by MSVC compiler.
  898. # It's not the case of Cygwin/MINGW - they are named there libsrt.a and libsrt.dll.a
  899. if (MICROSOFT)
  900. # Keep _static suffix. By unknown reason, the name must still be set explicitly.
  901. set_property(TARGET ${TARGET_srt}_static PROPERTY OUTPUT_NAME ${TARGET_srt}_static)
  902. else()
  903. set_property(TARGET ${TARGET_srt}_static PROPERTY OUTPUT_NAME ${TARGET_srt})
  904. endif()
  905. list (APPEND INSTALL_TARGETS ${TARGET_srt}_static)
  906. if (ENABLE_ENCRYPTION)
  907. target_link_libraries(${TARGET_srt}_static PRIVATE ${SSL_LIBRARIES})
  908. endif()
  909. if (MICROSOFT)
  910. target_link_libraries(${TARGET_srt}_static PRIVATE ws2_32.lib)
  911. if (OPENSSL_USE_STATIC_LIBS)
  912. target_link_libraries(${TARGET_srt}_static PRIVATE crypt32.lib)
  913. endif()
  914. elseif (MINGW)
  915. target_link_libraries(${TARGET_srt}_static PRIVATE wsock32 ws2_32)
  916. endif()
  917. if (USE_GNUSTL)
  918. target_link_libraries(${TARGET_srt}_static PRIVATE ${GNUSTL_LIBRARIES} ${GNUSTL_LDFLAGS})
  919. endif()
  920. endif()
  921. target_include_directories(srt_virtual PRIVATE ${SSL_INCLUDE_DIRS})
  922. if (MICROSOFT)
  923. if (OPENSSL_USE_STATIC_LIBS)
  924. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib crypt32.lib)
  925. else()
  926. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib)
  927. endif()
  928. elseif (MINGW)
  929. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} -lwsock32 -lws2_32)
  930. endif()
  931. # Applying this to public includes is not transitive enough.
  932. # On Windows, apps require this as well, so it's safer to
  933. # spread this to all targets.
  934. if (PTHREAD_INCLUDE_DIR)
  935. include_directories(${PTHREAD_INCLUDE_DIR})
  936. endif()
  937. # Link libraries must be applied directly to the derivatives
  938. # as virtual libraries (OBJECT-type) cannot have linkage declarations
  939. # transitive or not.
  940. foreach(tar ${srtpack_libspec_common})
  941. message(STATUS "ADDING TRANSITIVE LINK DEP to:${tar} : ${PTHREAD_LIBRARY} ${dep}")
  942. target_link_libraries (${tar} PUBLIC ${PTHREAD_LIBRARY} ${dep})
  943. endforeach()
  944. set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${PTHREAD_LIBRARY})
  945. target_compile_definitions(srt_virtual PRIVATE -DSRT_EXPORTS )
  946. if (ENABLE_SHARED)
  947. target_compile_definitions(srt_virtual PUBLIC -DSRT_DYNAMIC)
  948. endif()
  949. target_compile_definitions(srt_virtual PRIVATE -DSRT_LOG_SLOWDOWN_FREQ_MS=${SRT_LOG_SLOWDOWN_FREQ_MS})
  950. if (srt_libspec_shared)
  951. if (MICROSOFT)
  952. target_link_libraries(${TARGET_srt}_shared PUBLIC Ws2_32.lib)
  953. if (OPENSSL_USE_STATIC_LIBS)
  954. target_link_libraries(${TARGET_srt}_shared PUBLIC crypt32.lib)
  955. endif()
  956. endif()
  957. endif()
  958. # Required by some toolchains when statically linking this library if the
  959. # GCC Atomic Intrinsics are being used.
  960. if (HAVE_GCCATOMIC_INTRINSICS_REQUIRES_LIBATOMIC AND HAVE_LIBATOMIC)
  961. if (srt_libspec_static)
  962. target_link_libraries(${TARGET_srt}_static PUBLIC atomic)
  963. endif()
  964. if (srt_libspec_shared)
  965. target_link_libraries(${TARGET_srt}_shared PUBLIC atomic)
  966. endif()
  967. elseif (HAVE_LIBATOMIC AND HAVE_LIBATOMIC_COMPILES_STATIC)
  968. # This is a workaround for ANDROID NDK<17 builds, which need to link
  969. # to libatomic when linking statically to the SRT library.
  970. if (srt_libspec_static)
  971. target_link_libraries(${TARGET_srt}_static PUBLIC atomic)
  972. endif()
  973. elseif (LINUX AND HAVE_LIBATOMIC AND HAVE_LIBATOMIC_COMPILES)
  974. # This is a workaround for some older Linux Toolchains.
  975. if (srt_libspec_static)
  976. target_link_libraries(${TARGET_srt}_static PUBLIC atomic)
  977. endif()
  978. endif()
  979. # Cygwin installs the *.dll libraries in bin directory and uses PATH.
  980. set (INSTALL_SHARED_DIR ${CMAKE_INSTALL_LIBDIR})
  981. if (CYGWIN)
  982. set (INSTALL_SHARED_DIR ${CMAKE_INSTALL_BINDIR})
  983. endif()
  984. message(STATUS "INSTALL DIRS: bin=${CMAKE_INSTALL_BINDIR} lib=${CMAKE_INSTALL_LIBDIR} shlib=${INSTALL_SHARED_DIR} include=${CMAKE_INSTALL_INCLUDEDIR}")
  985. if (NEED_DESTINATION)
  986. if (DEFINED CMAKE_INSTALL_BINDIR AND DEFINED CMAKE_INSTALL_LIBDIR AND NOT INSTALL_SHARED_DIR STREQUAL "")
  987. install(TARGETS ${INSTALL_TARGETS}
  988. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  989. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  990. LIBRARY DESTINATION ${INSTALL_SHARED_DIR}
  991. )
  992. else()
  993. message(WARNING "No location to install ${INSTALL_TARGETS}")
  994. endif()
  995. elseif (NOT INSTALL_SHARED_DIR STREQUAL "")
  996. install(TARGETS ${INSTALL_TARGETS}
  997. LIBRARY DESTINATION ${INSTALL_SHARED_DIR}
  998. )
  999. else()
  1000. install(TARGETS ${INSTALL_TARGETS})
  1001. endif()
  1002. if (DEFINED CMAKE_INSTALL_INCLUDEDIR)
  1003. install(FILES ${HEADERS_srt} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/srt)
  1004. if (WIN32)
  1005. install(FILES ${HEADERS_srt_win32} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/srt/win)
  1006. endif()
  1007. endif()
  1008. # ---
  1009. # That's all for target definition
  1010. # ---
  1011. join_arguments(SRT_EXTRA_CFLAGS ${SRT_EXTRA_CFLAGS})
  1012. #message(STATUS "Target srt: LIBSPEC: ${srtpack_libspec_common} SOURCES: {${SOURCES_srt}} HEADERS: {${HEADERS_srt}}")
  1013. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SRT_DEBUG_OPT} ${SRT_EXTRA_CFLAGS} ${SRT_GCC_WARN}")
  1014. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SRT_DEBUG_OPT} ${SRT_EXTRA_CFLAGS} ${SRT_GCC_WARN}")
  1015. # PC file generation.
  1016. if (NOT DEFINED INSTALLDIR)
  1017. set (INSTALLDIR ${CMAKE_INSTALL_PREFIX})
  1018. get_filename_component(INSTALLDIR ${INSTALLDIR} ABSOLUTE)
  1019. endif()
  1020. # Required if linking a C application.
  1021. # This may cause trouble when you want to compile your app with static libstdc++;
  1022. # if your build requires it, you'd probably remove -lstdc++ from the list
  1023. # obtained by `pkg-config --libs`.
  1024. if(ENABLE_CXX_DEPS)
  1025. foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
  1026. if((IS_ABSOLUTE ${LIB} AND EXISTS ${LIB}) OR (${LIB} MATCHES "^-l"))
  1027. set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${LIB})
  1028. else()
  1029. set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} "-l${LIB}")
  1030. endif()
  1031. endforeach()
  1032. endif()
  1033. join_arguments(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE})
  1034. if (DEFINED CMAKE_INSTALL_LIBDIR)
  1035. # haisrt.pc left temporarily for backward compatibility. To be removed in future!
  1036. configure_file(scripts/srt.pc.in haisrt.pc @ONLY)
  1037. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/haisrt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1038. configure_file(scripts/srt.pc.in srt.pc @ONLY)
  1039. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/srt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  1040. endif()
  1041. # Applications
  1042. # If static is available, link apps against static one.
  1043. # Otherwise link against shared one.
  1044. if (srt_libspec_static)
  1045. set (srt_link_library ${TARGET_srt}_static)
  1046. if (ENABLE_RELATIVE_LIBPATH)
  1047. message(STATUS "ENABLE_RELATIVE_LIBPATH=ON will be ignored due to static linking.")
  1048. endif()
  1049. elseif(srt_libspec_shared)
  1050. set (srt_link_library ${TARGET_srt}_shared)
  1051. else()
  1052. message(FATAL_ERROR "Either ENABLE_STATIC or ENABLE_SHARED has to be ON!")
  1053. endif()
  1054. macro(srt_add_program_dont_install name)
  1055. add_executable(${name} ${ARGN})
  1056. target_include_directories(${name} PRIVATE apps)
  1057. target_include_directories(${name} PRIVATE common)
  1058. endmacro()
  1059. macro(srt_add_program name)
  1060. srt_add_program_dont_install(${name} ${ARGN})
  1061. if(NOT NEED_DESTINATION)
  1062. install(TARGETS ${name} RUNTIME)
  1063. elseif (DEFINED CMAKE_INSTALL_BINDIR)
  1064. install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  1065. else()
  1066. message(WARNING "No location to install program ${name}")
  1067. endif()
  1068. endmacro()
  1069. macro(srt_make_application name)
  1070. srt_set_stdcxx(${name} "${USE_CXX_STD_APP}")
  1071. # This is recommended by cmake, but it doesn't work anyway.
  1072. # What is needed is that this below CMAKE_INSTALL_RPATH (yes, relative)
  1073. # is added as is.
  1074. # set (CMAKE_SKIP_RPATH FALSE)
  1075. # set (CMAKE_SKIP_BUILD_RPATH FALSE)
  1076. # set (CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
  1077. # set (CMAKE_INSTALL_RPATH "../${CMAKE_INSTALL_LIBDIR}")
  1078. # set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
  1079. # set (FORCE_RPATH BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH_USE_LINK_PATH TRUE)
  1080. if (LINUX AND ENABLE_RELATIVE_LIBPATH AND NOT srt_libspec_static)
  1081. # This is only needed on Linux, on Windows (including Cygwin) the library file will
  1082. # be placed into the binrary directory anyway.
  1083. # XXX not sure about Mac.
  1084. # See this name used already in install(${TARGET_srt} LIBRARY DESTINATION...).
  1085. set(FORCE_RPATH LINK_FLAGS -Wl,-rpath,.,-rpath,../${CMAKE_INSTALL_LIBDIR} BUILD_WITH_INSTALL_RPATH TRUE INSTALL_RPATH_USE_LINK_PATH TRUE)
  1086. set_target_properties(${name} PROPERTIES ${FORCE_RPATH})
  1087. endif()
  1088. target_link_libraries(${name} ${srt_link_library})
  1089. if (USE_GNUSTL)
  1090. target_link_libraries(${name} PRIVATE ${GNUSTL_LIBRARIES} ${GNUSTL_LDFLAGS})
  1091. endif()
  1092. if (srt_libspec_static AND CMAKE_DL_LIBS)
  1093. target_link_libraries(${name} ${CMAKE_DL_LIBS})
  1094. endif()
  1095. endmacro()
  1096. macro(srt_add_application name) # ARGN=sources...
  1097. srt_add_program(${name} apps/${name}.cpp ${ARGN})
  1098. srt_make_application(${name})
  1099. if(NOT NEED_DESTINATION)
  1100. install(TARGETS ${name} RUNTIME)
  1101. elseif (DEFINED CMAKE_INSTALL_BINDIR)
  1102. install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
  1103. else()
  1104. message(WARNING "No location to install program ${name}")
  1105. endif()
  1106. endmacro()
  1107. ## FIXME: transmitmedia.cpp does not build on OpenBSD
  1108. ## Issue: https://github.com/Haivision/srt/issues/590
  1109. if (BSD
  1110. AND ${SYSNAME_LC} MATCHES "^openbsd$")
  1111. set(ENABLE_APPS OFF)
  1112. endif()
  1113. ## The applications currently require c++11.
  1114. if (NOT ENABLE_CXX11)
  1115. set(ENABLE_APPS OFF)
  1116. endif()
  1117. if (ENABLE_APPS)
  1118. message(STATUS "APPS: ENABLED, std=${USE_CXX_STD_APP}")
  1119. # Make a virtual library of all shared app files
  1120. MafReadDir(apps support.maf
  1121. SOURCES SOURCES_support
  1122. )
  1123. # A special trick that makes the shared application sources
  1124. # to be compiled once for all applications. Maybe this virtual
  1125. # library should be changed into a static one and made useful
  1126. # for users.
  1127. add_library(srtsupport_virtual OBJECT ${SOURCES_support})
  1128. srt_set_stdcxx(srtsupport_virtual "${USE_CXX_STD_APP}")
  1129. set (VIRTUAL_srtsupport $<TARGET_OBJECTS:srtsupport_virtual>)
  1130. # Applications
  1131. srt_add_application(srt-live-transmit ${VIRTUAL_srtsupport})
  1132. if (DEFINED EXTRA_stransmit)
  1133. set_target_properties(srt-live-transmit PROPERTIES COMPILE_FLAGS "${EXTRA_stransmit}")
  1134. endif()
  1135. srt_add_application(srt-file-transmit ${VIRTUAL_srtsupport})
  1136. if (MINGW)
  1137. # FIXME: with MINGW, it fails to build apps that require C++11
  1138. # https://github.com/Haivision/srt/issues/177
  1139. message(WARNING "On MinGW, some C++11 apps are blocked due to lacking proper C++11 headers for <thread>. FIX IF POSSIBLE.")
  1140. else()
  1141. # srt-multiplex temporarily blocked
  1142. #srt_add_application(srt-multiplex ${VIRTUAL_srtsupport})
  1143. srt_add_application(srt-tunnel ${VIRTUAL_srtsupport})
  1144. target_compile_definitions(srt-tunnel PUBLIC -DSRT_ENABLE_VERBOSE_LOCK)
  1145. endif()
  1146. if (ENABLE_TESTING)
  1147. message(STATUS "DEVEL APPS (testing): ENABLED")
  1148. macro(srt_add_testprogram name)
  1149. # Variables in macros are not local. Clear them forcefully.
  1150. set (SOURCES_app_indir "")
  1151. set (SOURCES_app "")
  1152. # Unlike Silvercat, in cmake you must know the full list
  1153. # of source files at the moment when defining the target
  1154. # and it can't be altered later.
  1155. #
  1156. # For testing applications, every application has its exclusive
  1157. # list of source files in its own Manifest file.
  1158. MafReadDir(testing ${name}.maf SOURCES SOURCES_app)
  1159. srt_add_program_dont_install(${name} ${SOURCES_app})
  1160. endmacro()
  1161. srt_add_testprogram(utility-test)
  1162. srt_set_stdcxx(utility-test "${USE_CXX_STD_APP}")
  1163. if (NOT WIN32)
  1164. # This program is symlinked under git-cygwin.
  1165. # Avoid misleading syntax error.
  1166. srt_add_testprogram(uriparser-test)
  1167. target_compile_options(uriparser-test PRIVATE -DTEST)
  1168. srt_set_stdcxx(uriparser-test "${USE_CXX_STD_APP}")
  1169. endif()
  1170. srt_add_testprogram(srt-test-live)
  1171. srt_make_application(srt-test-live)
  1172. srt_add_testprogram(srt-test-file)
  1173. srt_make_application(srt-test-file)
  1174. srt_add_testprogram(srt-test-relay)
  1175. srt_make_application(srt-test-relay)
  1176. target_compile_definitions(srt-test-relay PUBLIC -DSRT_ENABLE_VERBOSE_LOCK)
  1177. srt_add_testprogram(srt-test-multiplex)
  1178. srt_make_application(srt-test-multiplex)
  1179. if (ENABLE_BONDING)
  1180. srt_add_testprogram(srt-test-mpbond)
  1181. srt_make_application(srt-test-mpbond)
  1182. endif()
  1183. else()
  1184. message(STATUS "DEVEL APPS (testing): DISABLED")
  1185. endif()
  1186. else()
  1187. message(STATUS "APPS: DISABLED")
  1188. endif()
  1189. if (ENABLE_EXAMPLES)
  1190. # No examples should need C++11
  1191. macro(srt_add_example mainsrc)
  1192. get_filename_component(name ${mainsrc} NAME_WE)
  1193. srt_add_program_dont_install(${name} examples/${mainsrc} ${ARGN})
  1194. target_link_libraries(${name} ${srt_link_library} ${DEPENDS_srt})
  1195. endmacro()
  1196. srt_add_example(recvlive.cpp)
  1197. srt_add_example(sendfile.cpp)
  1198. srt_add_example(recvfile.cpp)
  1199. srt_add_example(sendmsg.cpp)
  1200. srt_add_example(recvmsg.cpp)
  1201. srt_add_example(test-c-client.c)
  1202. srt_add_example(example-client-nonblock.c)
  1203. srt_add_example(test-c-server.c)
  1204. if (ENABLE_BONDING)
  1205. srt_add_example(test-c-client-bonding.c)
  1206. srt_add_example(test-c-server-bonding.c)
  1207. endif()
  1208. srt_add_example(testcapi-connect.c)
  1209. endif()
  1210. if (ENABLE_UNITTESTS AND ENABLE_CXX11)
  1211. if (${CMAKE_VERSION} VERSION_LESS "3.10.0")
  1212. message(STATUS "VERSION < 3.10 -- adding test using the old method")
  1213. set (USE_OLD_ADD_METHOD 1)
  1214. else()
  1215. message(STATUS "VERSION > 3.10 -- using NEW POLICY for in_list operator")
  1216. cmake_policy(SET CMP0057 NEW) # Support the new IN_LIST operator.
  1217. endif()
  1218. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  1219. # Version ranges are only supported with CMake 3.19 or later.
  1220. # Need GTest v1.10 or higher to support GTEST_SKIP.
  1221. if (${CMAKE_VERSION} VERSION_LESS "3.19.0")
  1222. find_package(GTest 1.10)
  1223. else()
  1224. find_package(GTest 1.10...1.12)
  1225. endif()
  1226. if (NOT GTEST_FOUND)
  1227. message(STATUS "GTEST not found! Fetching from git.")
  1228. include(googletest)
  1229. fetch_googletest(
  1230. ${PROJECT_SOURCE_DIR}/scripts
  1231. ${PROJECT_BINARY_DIR}/googletest
  1232. )
  1233. set(GTEST_BOTH_LIBRARIES "gtest_main" CACHE STRING "Add gtest_main target")
  1234. endif()
  1235. MafReadDir(test filelist.maf
  1236. HEADERS SOURCES_unittests
  1237. SOURCES SOURCES_unittests
  1238. )
  1239. srt_add_program_dont_install(test-srt ${SOURCES_unittests})
  1240. srt_make_application(test-srt)
  1241. target_include_directories(test-srt PRIVATE ${SSL_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
  1242. target_link_libraries(
  1243. test-srt
  1244. ${GTEST_BOTH_LIBRARIES}
  1245. ${srt_link_library}
  1246. ${PTHREAD_LIBRARY}
  1247. )
  1248. if (USE_OLD_ADD_METHOD)
  1249. add_test(
  1250. NAME test-srt
  1251. COMMAND ${CMAKE_BINARY_DIR}/test-srt
  1252. )
  1253. #set_tests_properties(test-srt PROPERTIES RUN_SERIAL TRUE)
  1254. else()
  1255. gtest_add_tests(
  1256. TEST_LIST tests_srt
  1257. TARGET test-srt
  1258. )
  1259. set_tests_properties(${tests_srt} PROPERTIES RUN_SERIAL TRUE)
  1260. endif()
  1261. enable_testing()
  1262. endif()
  1263. if(NOT NEED_DESTINATION)
  1264. install(PROGRAMS scripts/srt-ffplay TYPE BIN)
  1265. elseif (DEFINED CMAKE_INSTALL_BINDIR)
  1266. install(PROGRAMS scripts/srt-ffplay DESTINATION ${CMAKE_INSTALL_BINDIR})
  1267. else()
  1268. message(WARNING "No location to install scripts/srt-ffplay")
  1269. endif()
  1270. if (DEFINED SRT_EXTRA_APPS_INC)
  1271. include(${SRT_EXTRA_APPS_INC}.cmake)
  1272. # No extra variables expected. Just use the variables
  1273. # already provided and define additional targets.
  1274. endif()
  1275. if (ENABLE_SHOW_PROJECT_CONFIG)
  1276. include(ShowProjectConfig)
  1277. ShowProjectConfig()
  1278. endif()