CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. add_executable(WebRTCLibTest)
  2. target_sources(WebRTCLibTest
  3. PRIVATE
  4. pch.cpp
  5. pch.h
  6. ContextTest.cpp
  7. CreateVideoCodecFactoryTest.cpp
  8. FrameGenerator.cpp
  9. FrameGenerator.h
  10. GpuMemoryBufferTest.cpp
  11. GpuMemoryBufferPoolTest.cpp
  12. GraphicsDeviceContainer.cpp
  13. GraphicsDeviceContainer.h
  14. GraphicsDeviceContainerTest.cpp
  15. GraphicsDeviceTest.cpp
  16. GraphicsDeviceTestBase.cpp
  17. GraphicsDeviceTestBase.h
  18. H264ProfileLevelIdTest.cpp
  19. InternalCodecsTest.cpp
  20. UnityVideoEncoderFactoryTest.cpp
  21. UnityVideoDecoderFactoryTest.cpp
  22. VideoCodecTest.cpp
  23. VideoCodecTest.h
  24. VideoFrameSchedulerTest.cpp
  25. VideoFrameTest.cpp
  26. VideoRendererTest.cpp
  27. VideoTrackSourceTest.cpp
  28. )
  29. if(Windows OR Linux)
  30. add_subdirectory(NvCodec)
  31. endif()
  32. if(Linux OR Android)
  33. target_sources(WebRTCLibTest
  34. PRIVATE
  35. OpenGLContextTest.cpp
  36. )
  37. endif()
  38. include(FetchContent)
  39. FetchContent_Declare(
  40. googletest
  41. GIT_REPOSITORY https://github.com/google/googletest.git
  42. GIT_TAG release-1.11.0
  43. )
  44. FetchContent_GetProperties(googletest)
  45. if(NOT googletest_POPULATED)
  46. FetchContent_Populate(googletest)
  47. add_subdirectory(
  48. ${googletest_SOURCE_DIR}
  49. ${googletest_BINARY_DIR}
  50. )
  51. endif()
  52. include(GoogleTest)
  53. target_compile_definitions(WebRTCLibTest
  54. PRIVATE
  55. "$<$<CONFIG:Debug>:DEBUG>"
  56. )
  57. if(NOT iOS)
  58. target_include_directories(WebRTCLibTest
  59. PRIVATE
  60. $<TARGET_PROPERTY:gtest,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
  61. $<TARGET_PROPERTY:gtest_main,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
  62. $<TARGET_PROPERTY:gmock,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
  63. $<TARGET_PROPERTY:gmock_main,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
  64. )
  65. set_target_properties(gtest
  66. PROPERTIES
  67. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  68. )
  69. set_target_properties(gtest_main
  70. PROPERTIES
  71. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  72. )
  73. set_target_properties(gmock
  74. PROPERTIES
  75. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  76. )
  77. set_target_properties(gmock_main
  78. PROPERTIES
  79. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  80. )
  81. else()
  82. set(GOOGLETEST_ROOT_DIR ${CMAKE_SOURCE_DIR}/googletest)
  83. set(GTEST_INCLUDE_DIRS
  84. ${GOOGLETEST_ROOT_DIR}/include
  85. )
  86. set(GTEST_MAIN_LIBRARIES
  87. debug ${GOOGLETEST_ROOT_DIR}/lib/libgtest_maind.a
  88. optimized ${GOOGLETEST_ROOT_DIR}/lib/libgtest_main.a
  89. )
  90. set(GTEST_LIBRARIES
  91. debug ${GOOGLETEST_ROOT_DIR}/lib/libgtestd.a
  92. optimized ${GOOGLETEST_ROOT_DIR}/lib/libgtest.a
  93. )
  94. set(GMOCK_LIBRARIES
  95. debug ${GOOGLETEST_ROOT_DIR}/lib/libgmockd.a
  96. optimized ${GOOGLETEST_ROOT_DIR}/lib/libgmock.a
  97. )
  98. endif()
  99. if(Windows)
  100. # Use precompiled header
  101. set(CMAKE_CXX_FLAGS
  102. "${CMAKE_CXX_FLAGS} /Yu /Yupch.h"
  103. )
  104. target_link_libraries(WebRTCLibTest
  105. PRIVATE
  106. ${WEBRTC_LIBRARY}
  107. ${Vulkan_LIBRARY}
  108. ${CUDA_CUDA_LIBRARY}
  109. ${NVCODEC_LIBRARIES}
  110. gtest
  111. gmock
  112. gtest_main
  113. d3d11
  114. d3d12
  115. dxgi
  116. winmm
  117. Secur32
  118. Msdmo
  119. Dmoguids
  120. wmcodecdspuuid
  121. WebRTCLib
  122. Strmiids
  123. delayimp.lib
  124. )
  125. target_include_directories(WebRTCLibTest
  126. PRIVATE
  127. ${CUDA_INCLUDE_DIRS}
  128. ${Vulkan_INCLUDE_DIR}
  129. ${NVCODEC_INCLUDE_DIR}
  130. )
  131. # Creare precompiled header
  132. set_source_files_properties(pch.cpp
  133. PROPERTIES
  134. COMPILE_FLAGS "/Yc /Ycpch.h"
  135. )
  136. set_target_properties(WebRTCLibTest
  137. PROPERTIES
  138. LINK_FLAGS "-delayload:nvcuda.dll -delayload:nvEncodeAPI64.dll -delayload:nvcuvid.dll -delayload:vulkan-1.dll"
  139. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  140. )
  141. elseif(macOS)
  142. set(CMAKE_C_FLAGS "-x objective-c")
  143. set(CMAKE_CXX_FLAGS "-x objective-c++")
  144. set_target_properties(WebRTCLibTest
  145. PROPERTIES
  146. LINK_FLAGS "-ObjC"
  147. CXX_VISIBILITY_PRESET hidden
  148. VISIBILITY_INLINES_HIDDEN ON
  149. )
  150. target_link_libraries(WebRTCLibTest
  151. PRIVATE
  152. ${WEBRTC_LIBRARY}
  153. ${OPENGL_LIBRARIES}
  154. ${FRAMEWORK_LIBS}
  155. gtest
  156. gmock
  157. gtest_main
  158. WebRTCLib
  159. )
  160. target_include_directories(WebRTCLibTest
  161. PRIVATE
  162. ..
  163. ${WEBRTC_OBJC_INCLUDE_DIR}
  164. )
  165. elseif(Linux)
  166. find_package(glfw3 REQUIRED)
  167. target_compile_options(WebRTCLibTest
  168. PUBLIC
  169. -fno-lto
  170. -fno-rtti
  171. $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>
  172. )
  173. target_link_options(WebRTCLibTest
  174. PUBLIC
  175. $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>
  176. )
  177. target_compile_definitions(WebRTCLibTest
  178. PRIVATE
  179. $<$<CONFIG:Debug>:LEAK_SANITIZER>
  180. )
  181. target_link_libraries(WebRTCLibTest
  182. PRIVATE
  183. ${CMAKE_DL_LIBS}
  184. ${CMAKE_THREAD_LIBS_INIT}
  185. glfw
  186. gtest
  187. gmock
  188. gtest_main
  189. WebRTCLib
  190. )
  191. target_include_directories(WebRTCLibTest
  192. PRIVATE
  193. ..
  194. ${CUDA_INCLUDE_DIRS}
  195. ${NVCODEC_INCLUDE_DIR}
  196. )
  197. elseif(iOS)
  198. set(CMAKE_C_FLAGS "-x objective-c")
  199. set(CMAKE_CXX_FLAGS "-x objective-c++")
  200. set_target_properties(WebRTCLibTest
  201. PROPERTIES
  202. LINK_FLAGS "-ObjC"
  203. MACOSX_BUNDLE_GUI_IDENTIFIER "com.unity.WebRTCTest"
  204. MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_PROJECT_VERSION}"
  205. MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_PROJECT_VERSION}"
  206. )
  207. target_link_libraries(WebRTCLibTest
  208. PRIVATE
  209. ${WEBRTC_LIBRARY}
  210. ${OPENGL_LIBRARIES}
  211. ${FRAMEWORK_LIBS}
  212. gtest
  213. gmock
  214. gtest_main
  215. WebRTCLib
  216. )
  217. target_include_directories(WebRTCLibTest
  218. PRIVATE
  219. ..
  220. ${WEBRTC_OBJC_INCLUDE_DIR}
  221. )
  222. elseif(Android)
  223. target_link_libraries(WebRTCLibTest
  224. PRIVATE
  225. gtest
  226. gmock
  227. gtest_main
  228. WebRTCLib
  229. )
  230. endif()
  231. gtest_add_tests(TARGET WebRTCLibTest)
  232. target_include_directories(WebRTCLibTest
  233. PRIVATE
  234. .
  235. ../WebRTCPlugin
  236. ${CMAKE_SOURCE_DIR}/unity/include
  237. ${WEBRTC_INCLUDE_DIR}
  238. ${OPENGL_INCLUDE_DIR}
  239. )