CMakeLists.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. add_library(WebRTCLib STATIC)
  2. target_sources(WebRTCLib
  3. PRIVATE
  4. Context.cpp
  5. Context.h
  6. CreateSessionDescriptionObserver.cpp
  7. CreateSessionDescriptionObserver.h
  8. DataChannelObject.cpp
  9. DataChannelObject.h
  10. DummyAudioDevice.cpp
  11. DummyAudioDevice.h
  12. AudioTrackSinkAdapter.h
  13. AudioTrackSinkAdapter.cpp
  14. Logger.cpp
  15. MediaStreamObserver.cpp
  16. MediaStreamObserver.h
  17. pch.cpp
  18. pch.h
  19. PeerConnectionObject.cpp
  20. PeerConnectionObject.h
  21. PeerConnectionStatsCollectorCallback.cpp
  22. PeerConnectionStatsCollectorCallback.h
  23. PlatformBase.h
  24. ProfilerMarkerFactory.cpp
  25. ProfilerMarkerFactory.h
  26. SetSessionDescriptionObserver.cpp
  27. SetSessionDescriptionObserver.h
  28. ScopedProfiler.h
  29. ScopedProfiler.cpp
  30. targetver.h
  31. UnityAudioDecoderFactory.cpp
  32. UnityAudioDecoderFactory.h
  33. UnityAudioEncoderFactory.cpp
  34. UnityAudioEncoderFactory.h
  35. UnityAudioTrackSource.cpp
  36. UnityAudioTrackSource.h
  37. UnityProfilerInterfaceFunctions.cpp
  38. UnityProfilerInterfaceFunctions.h
  39. UnityVideoDecoderFactory.cpp
  40. UnityVideoDecoderFactory.h
  41. UnityVideoEncoderFactory.cpp
  42. UnityVideoEncoderFactory.h
  43. UnityVideoRenderer.cpp
  44. UnityVideoRenderer.h
  45. UnityVideoTrackSource.cpp
  46. UnityVideoTrackSource.h
  47. WebRTCMacros.h
  48. WebRTCPlugin.h
  49. UnityLogStream.h
  50. UnityLogStream.cpp
  51. VideoFrame.cpp
  52. VideoFrame.h
  53. VideoFrameAdapter.cpp
  54. VideoFrameAdapter.h
  55. VideoFrameScheduler.cpp
  56. VideoFrameScheduler.h
  57. VideoFrameUtil.cpp
  58. VideoFrameUtil.h
  59. GpuMemoryBuffer.cpp
  60. GpuMemoryBuffer.h
  61. GpuMemoryBufferPool.cpp
  62. GpuMemoryBufferPool.h
  63. )
  64. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  65. # Visual Studio Generator has not been supported supression warnings of external headers yet.
  66. # https://gitlab.kitware.com/cmake/cmake/-/issues/17904
  67. if(CMAKE_GENERATOR MATCHES "Visual Studio")
  68. set(VISUALSTUDIO_GENERATOR 1)
  69. else()
  70. set(VISUALSTUDIO_GENERATOR 0)
  71. endif()
  72. target_compile_options(WebRTCLib
  73. PUBLIC
  74. $<$<NOT:${VISUALSTUDIO_GENERATOR}>:-Werror>
  75. $<${VISUALSTUDIO_GENERATOR}:-Wno-c++98-compat>
  76. $<${VISUALSTUDIO_GENERATOR}:-Wno-c++98-compat-pedantic>
  77. -Wall
  78. -Wextra
  79. -Wformat=2
  80. -Wno-unused-parameter
  81. )
  82. endif()
  83. target_compile_definitions(WebRTCLib
  84. PUBLIC
  85. $<$<CONFIG:Debug>:DEBUG>
  86. )
  87. set_target_properties(WebRTCLib
  88. PROPERTIES
  89. CXX_VISIBILITY_PRESET hidden
  90. VISIBILITY_INLINES_HIDDEN ON
  91. )
  92. if(iOS OR macOS)
  93. target_sources(WebRTCLib
  94. PRIVATE
  95. ../libcxx/debug.cpp
  96. )
  97. else()
  98. target_sources(WebRTCLib
  99. PRIVATE
  100. UnityVulkanInterfaceFunctions.cpp
  101. UnityVulkanInterfaceFunctions.h
  102. )
  103. endif()
  104. if(Android)
  105. add_subdirectory(Android)
  106. endif()
  107. add_subdirectory(Codec)
  108. add_subdirectory(GraphicsDevice)
  109. if(Windows)
  110. # Force to always compile with W4
  111. if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
  112. string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  113. else()
  114. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
  115. endif()
  116. # Replace /GR option to disable RTTI
  117. foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  118. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  119. string(REPLACE /GR /GR- "${flag_var}" "${${flag_var}}")
  120. endforeach()
  121. endif()
  122. if(Windows)
  123. # Use precompiled header
  124. set(CMAKE_CXX_FLAGS
  125. "${CMAKE_CXX_FLAGS} /Yu /Yupch.h")
  126. set(PROJECT_BINARY_DIR
  127. "${CMAKE_SOURCE_DIR}/../Runtime/Plugins/x86_64")
  128. target_compile_definitions(WebRTCLib
  129. PUBLIC
  130. WEBRTC_WIN
  131. NOMINMAX
  132. VK_NO_PROTOTYPES
  133. )
  134. target_link_libraries(WebRTCLib
  135. PRIVATE
  136. ${WEBRTC_LIBRARY}
  137. ${Vulkan_LIBRARY}
  138. ${CUDA_CUDA_LIBRARY}
  139. ${NVCODEC_LIBRARIES}
  140. d3d11
  141. winmm
  142. Secur32
  143. Msdmo
  144. Dmoguids
  145. wmcodecdspuuid
  146. Strmiids
  147. )
  148. target_include_directories(WebRTCLib
  149. SYSTEM
  150. PUBLIC
  151. ${CUDA_INCLUDE_DIRS}
  152. ${Vulkan_INCLUDE_DIR}
  153. ${NVCODEC_INCLUDE_DIR}
  154. )
  155. # Select runtime library (MT, MTD) on windows platform
  156. set_target_properties(WebRTCLib
  157. PROPERTIES
  158. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  159. )
  160. # Creare precompiled header
  161. set_source_files_properties(pch.cpp
  162. PROPERTIES
  163. COMPILE_FLAGS "/Yc /Ycpch.h"
  164. )
  165. elseif(macOS)
  166. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c")
  167. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto -fno-rtti")
  168. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++")
  169. set(PROJECT_BINARY_DIR
  170. "${CMAKE_SOURCE_DIR}/../Runtime/Plugins/macOS")
  171. target_compile_definitions(WebRTCLib
  172. PUBLIC
  173. WEBRTC_MAC
  174. WEBRTC_POSIX
  175. )
  176. target_link_libraries(WebRTCLib
  177. PRIVATE
  178. ${WEBRTC_LIBRARY}
  179. ${FRAMEWORK_LIBS}
  180. )
  181. target_include_directories(WebRTCLib
  182. SYSTEM
  183. PUBLIC
  184. ${WEBRTC_OBJC_INCLUDE_DIR}
  185. )
  186. set_target_properties(WebRTCLib
  187. PROPERTIES
  188. LINK_FLAGS "-ObjC"
  189. )
  190. elseif(Linux)
  191. set(PROJECT_BINARY_DIR "${CMAKE_SOURCE_DIR}/../Runtime/Plugins/x86_64")
  192. set(GLAD_SOURCES_DIR "${CMAKE_SOURCE_DIR}/glad")
  193. add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
  194. glad_add_library(glad_gl_core_46 REPRODUCIBLE STATIC LOADER API gl:core=4.6)
  195. glad_add_library(glad_vulkan_11 REPRODUCIBLE STATIC LOADER API vulkan=1.1)
  196. glad_add_library(glad_glx_14 REPRODUCIBLE STATIC LOADER API glx=1.4)
  197. set_target_properties(glad_gl_core_46
  198. PROPERTIES
  199. POSITION_INDEPENDENT_CODE ON
  200. )
  201. set_target_properties(glad_vulkan_11
  202. PROPERTIES
  203. POSITION_INDEPENDENT_CODE ON
  204. )
  205. set_target_properties(glad_glx_14
  206. PROPERTIES
  207. POSITION_INDEPENDENT_CODE ON
  208. )
  209. target_link_libraries(glad_glx_14
  210. PUBLIC
  211. glad_gl_core_46
  212. )
  213. find_package(PkgConfig REQUIRED)
  214. pkg_check_modules(GLIB REQUIRED glib-2.0)
  215. target_compile_definitions(WebRTCLib
  216. PUBLIC
  217. WEBRTC_LINUX
  218. WEBRTC_POSIX
  219. VK_NO_PROTOTYPES
  220. )
  221. target_link_libraries(WebRTCLib
  222. PUBLIC
  223. NvCodec
  224. glad_gl_core_46
  225. glad_vulkan_11
  226. glad_glx_14
  227. ${WEBRTC_LIBRARY}
  228. ${GLIB_LIBRARIES}
  229. ${CXX_LIBRARY}
  230. ${CXXABI_LIBRARY}
  231. )
  232. target_include_directories(WebRTCLib
  233. SYSTEM
  234. PUBLIC
  235. ${CUDA_INCLUDE_DIRS}
  236. glad_gl_core_46
  237. glad_vulkan_11
  238. glad_glx_14
  239. ${NVCODEC_INCLUDE_DIR}
  240. )
  241. # enable -fPIC option
  242. set_target_properties(WebRTCLib
  243. PROPERTIES
  244. POSITION_INDEPENDENT_CODE ON
  245. )
  246. elseif(iOS)
  247. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -fembed-bitcode")
  248. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto -fno-rtti -fembed-bitcode")
  249. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++")
  250. set(PROJECT_BINARY_DIR
  251. "${CMAKE_SOURCE_DIR}/../Runtime/Plugins/iOS"
  252. )
  253. target_compile_definitions(WebRTCLib
  254. PUBLIC
  255. WEBRTC_IOS
  256. WEBRTC_MAC
  257. WEBRTC_POSIX
  258. )
  259. target_include_directories(WebRTCLib
  260. SYSTEM
  261. PUBLIC
  262. ${WEBRTC_OBJC_INCLUDE_DIR}
  263. )
  264. target_link_libraries(WebRTCLib
  265. PRIVATE
  266. ${WEBRTC_LIBRARY}
  267. ${FRAMEWORK_LIBS}
  268. )
  269. set_target_properties(WebRTCLib
  270. PROPERTIES
  271. LINK_FLAGS "-ObjC"
  272. )
  273. elseif(Android)
  274. target_compile_definitions(WebRTCLib
  275. PUBLIC
  276. WEBRTC_ANDROID
  277. WEBRTC_POSIX
  278. VK_NO_PROTOTYPES
  279. )
  280. target_link_libraries(WebRTCLib
  281. PRIVATE
  282. ${WEBRTC_LIBRARY}
  283. log
  284. OpenSLES
  285. GLESv3
  286. EGL
  287. )
  288. target_compile_options(WebRTCLib
  289. PUBLIC
  290. -fno-lto -fno-rtti
  291. )
  292. # Linker excludes unused symbols from the shared library
  293. # when linking the archive file (libwebrtc.a).
  294. file(READ "${CMAKE_SOURCE_DIR}/tools/android/jni_symbols.txt" JNI_SYMBOLS)
  295. string(REPLACE "\n" ";" JNI_SYMBOLS ${JNI_SYMBOLS})
  296. list(TRANSFORM JNI_SYMBOLS PREPEND "-Wl,--require-defined=")
  297. target_link_options(WebRTCLib
  298. PUBLIC
  299. ${JNI_SYMBOLS}
  300. )
  301. set(PROJECT_BINARY_DIR
  302. "${CMAKE_SOURCE_DIR}/../Runtime/Plugins/Android"
  303. )
  304. endif()
  305. target_include_directories(WebRTCLib
  306. SYSTEM
  307. PUBLIC
  308. ${CMAKE_SOURCE_DIR}/unity/include
  309. ${WEBRTC_INCLUDE_DIR}
  310. )
  311. target_include_directories(WebRTCLib
  312. PUBLIC
  313. .
  314. )
  315. add_library(WebRTCPlugin SHARED)
  316. set_target_properties(WebRTCPlugin
  317. PROPERTIES
  318. CXX_VISIBILITY_PRESET hidden
  319. VISIBILITY_INLINES_HIDDEN ON
  320. )
  321. if(iOS)
  322. set_target_properties(WebRTCPlugin
  323. PROPERTIES
  324. FRAMEWORK TRUE
  325. )
  326. endif()
  327. if(Windows)
  328. # link delayimp.lib to use delayload when building with Clang on Windows.
  329. target_link_libraries(WebRTCPlugin
  330. PRIVATE
  331. WebRTCLib
  332. delayimp.lib
  333. )
  334. else()
  335. target_link_libraries(WebRTCPlugin
  336. PRIVATE
  337. WebRTCLib
  338. )
  339. endif()
  340. target_sources(WebRTCPlugin
  341. PRIVATE
  342. pch.cpp
  343. pch.h
  344. WebRTCPlugin.cpp
  345. WebRTCPlugin.h
  346. UnityRenderEvent.cpp
  347. )
  348. # rename dll/framework filename
  349. set_target_properties(WebRTCPlugin
  350. PROPERTIES
  351. OUTPUT_NAME webrtc
  352. RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}
  353. RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}
  354. LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}
  355. LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}
  356. )
  357. if(Windows)
  358. # Set linker option
  359. set_target_properties(WebRTCPlugin
  360. PROPERTIES
  361. LINK_FLAGS "/SUBSYSTEM:WINDOWS -delayload:nvcuda.dll -delayload:nvEncodeAPI64.dll -delayload:nvcuvid.dll"
  362. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  363. )
  364. elseif(macOS)
  365. set_target_properties(WebRTCPlugin
  366. PROPERTIES
  367. LINK_FLAGS "-ObjC"
  368. )
  369. elseif(iOS)
  370. #
  371. # Build Setting Reference
  372. # https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
  373. #
  374. set_target_properties(WebRTCPlugin
  375. PROPERTIES
  376. LINK_FLAGS "-ObjC"
  377. MACOSX_FRAMEWORK_IDENTIFIER "com.unity.webrtc"
  378. MACOSX_FRAMEWORK_BUNDLE_VERSION ${CMAKE_PROJECT_VERSION}
  379. MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${CMAKE_PROJECT_VERSION}
  380. XCODE_ATTRIBUTE_SKIP_INSTALL "NO"
  381. XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
  382. XCODE_ATTRIBUTE_STRIP_STYLE non-global
  383. XCODE_ATTRIBUTE_STRIP_INSTALLED_PRODUCT $<IF:$<CONFIG:Debug>,NO,YES>
  384. XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN $<IF:$<CONFIG:Debug>,NO,YES>
  385. )
  386. endif()