meson.build 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. src = [
  2. 'src/main.c',
  3. 'src/adb/adb.c',
  4. 'src/adb/adb_device.c',
  5. 'src/adb/adb_parser.c',
  6. 'src/adb/adb_tunnel.c',
  7. 'src/cli.c',
  8. 'src/clock.c',
  9. 'src/compat.c',
  10. 'src/control_msg.c',
  11. 'src/controller.c',
  12. 'src/decoder.c',
  13. 'src/demuxer.c',
  14. 'src/device_msg.c',
  15. 'src/icon.c',
  16. 'src/file_pusher.c',
  17. 'src/fps_counter.c',
  18. 'src/frame_buffer.c',
  19. 'src/input_manager.c',
  20. 'src/keyboard_inject.c',
  21. 'src/mouse_inject.c',
  22. 'src/opengl.c',
  23. 'src/options.c',
  24. 'src/receiver.c',
  25. 'src/recorder.c',
  26. 'src/scrcpy.c',
  27. 'src/screen.c',
  28. 'src/server.c',
  29. 'src/version.c',
  30. 'src/video_buffer.c',
  31. 'src/util/acksync.c',
  32. 'src/util/file.c',
  33. 'src/util/intmap.c',
  34. 'src/util/intr.c',
  35. 'src/util/log.c',
  36. 'src/util/net.c',
  37. 'src/util/net_intr.c',
  38. 'src/util/process.c',
  39. 'src/util/process_intr.c',
  40. 'src/util/rand.c',
  41. 'src/util/strbuf.c',
  42. 'src/util/str.c',
  43. 'src/util/term.c',
  44. 'src/util/thread.c',
  45. 'src/util/tick.c',
  46. ]
  47. conf = configuration_data()
  48. conf.set('_POSIX_C_SOURCE', '200809L')
  49. conf.set('_XOPEN_SOURCE', '700')
  50. conf.set('_GNU_SOURCE', true)
  51. if host_machine.system() == 'windows'
  52. windows = import('windows')
  53. src += [
  54. 'src/sys/win/file.c',
  55. 'src/sys/win/process.c',
  56. windows.compile_resources('scrcpy-windows.rc'),
  57. ]
  58. conf.set('_WIN32_WINNT', '0x0600')
  59. conf.set('WINVER', '0x0600')
  60. else
  61. src += [
  62. 'src/sys/unix/file.c',
  63. 'src/sys/unix/process.c',
  64. ]
  65. if host_machine.system() == 'darwin'
  66. conf.set('_DARWIN_C_SOURCE', true)
  67. endif
  68. endif
  69. v4l2_support = get_option('v4l2') and host_machine.system() == 'linux'
  70. if v4l2_support
  71. src += [ 'src/v4l2_sink.c' ]
  72. endif
  73. usb_support = get_option('usb')
  74. if usb_support
  75. src += [
  76. 'src/usb/aoa_hid.c',
  77. 'src/usb/hid_keyboard.c',
  78. 'src/usb/hid_mouse.c',
  79. 'src/usb/scrcpy_otg.c',
  80. 'src/usb/screen_otg.c',
  81. 'src/usb/usb.c',
  82. ]
  83. endif
  84. cc = meson.get_compiler('c')
  85. crossbuild_windows = meson.is_cross_build() and host_machine.system() == 'windows'
  86. if not crossbuild_windows
  87. # native build
  88. dependencies = [
  89. dependency('libavformat', version: '>= 57.33'),
  90. dependency('libavcodec', version: '>= 57.37'),
  91. dependency('libavutil'),
  92. dependency('sdl2', version: '>= 2.0.5'),
  93. ]
  94. if v4l2_support
  95. dependencies += dependency('libavdevice')
  96. endif
  97. if usb_support
  98. dependencies += dependency('libusb-1.0')
  99. endif
  100. else
  101. # cross-compile mingw32 build (from Linux to Windows)
  102. prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
  103. sdl2_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_sdl2 + '/bin'
  104. sdl2_lib_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_sdl2 + '/lib'
  105. sdl2_include_dir = 'prebuilt-deps/data/' + prebuilt_sdl2 + '/include'
  106. sdl2 = declare_dependency(
  107. dependencies: [
  108. cc.find_library('SDL2', dirs: sdl2_bin_dir),
  109. cc.find_library('SDL2main', dirs: sdl2_lib_dir),
  110. ],
  111. include_directories: include_directories(sdl2_include_dir)
  112. )
  113. prebuilt_ffmpeg = meson.get_cross_property('prebuilt_ffmpeg')
  114. ffmpeg_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_ffmpeg + '/bin'
  115. ffmpeg_include_dir = 'prebuilt-deps/data/' + prebuilt_ffmpeg + '/include'
  116. # ffmpeg versions are different for win32 and win64 builds
  117. ffmpeg_avcodec = meson.get_cross_property('ffmpeg_avcodec')
  118. ffmpeg_avformat = meson.get_cross_property('ffmpeg_avformat')
  119. ffmpeg_avutil = meson.get_cross_property('ffmpeg_avutil')
  120. ffmpeg = declare_dependency(
  121. dependencies: [
  122. cc.find_library(ffmpeg_avcodec, dirs: ffmpeg_bin_dir),
  123. cc.find_library(ffmpeg_avformat, dirs: ffmpeg_bin_dir),
  124. cc.find_library(ffmpeg_avutil, dirs: ffmpeg_bin_dir),
  125. ],
  126. include_directories: include_directories(ffmpeg_include_dir)
  127. )
  128. prebuilt_libusb = meson.get_cross_property('prebuilt_libusb')
  129. prebuilt_libusb_root = meson.get_cross_property('prebuilt_libusb_root')
  130. libusb_bin_dir = meson.current_source_dir() + '/prebuilt-deps/data/' + prebuilt_libusb
  131. libusb_include_dir = 'prebuilt-deps/data/' + prebuilt_libusb_root + '/include'
  132. libusb = declare_dependency(
  133. dependencies: [
  134. cc.find_library('msys-usb-1.0', dirs: libusb_bin_dir),
  135. ],
  136. include_directories: include_directories(libusb_include_dir)
  137. )
  138. dependencies = [
  139. ffmpeg,
  140. sdl2,
  141. libusb,
  142. cc.find_library('mingw32')
  143. ]
  144. endif
  145. if host_machine.system() == 'windows'
  146. dependencies += cc.find_library('ws2_32')
  147. endif
  148. check_functions = [
  149. 'strdup',
  150. 'asprintf',
  151. 'vasprintf',
  152. 'nrand48',
  153. 'jrand48',
  154. ]
  155. foreach f : check_functions
  156. if cc.has_function(f)
  157. define = 'HAVE_' + f.underscorify().to_upper()
  158. conf.set(define, true)
  159. endif
  160. endforeach
  161. conf.set('HAVE_SOCK_CLOEXEC', host_machine.system() != 'windows' and
  162. cc.has_header_symbol('sys/socket.h', 'SOCK_CLOEXEC'))
  163. # the version, updated on release
  164. conf.set_quoted('SCRCPY_VERSION', meson.project_version())
  165. # the prefix used during configuration (meson --prefix=PREFIX)
  166. conf.set_quoted('PREFIX', get_option('prefix'))
  167. # build a "portable" version (with scrcpy-server accessible from the same
  168. # directory as the executable)
  169. conf.set('PORTABLE', get_option('portable'))
  170. # the default client TCP port range for the "adb reverse" tunnel
  171. # overridden by option --port
  172. conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
  173. conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')
  174. # the default video bitrate, in bits/second
  175. # overridden by option --bit-rate
  176. conf.set('DEFAULT_BIT_RATE', '8000000') # 8Mbps
  177. # run a server debugger and wait for a client to be attached
  178. conf.set('SERVER_DEBUGGER', get_option('server_debugger'))
  179. # select the debugger method ('old' for Android < 9, 'new' for Android >= 9)
  180. conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == 'new')
  181. # enable V4L2 support (linux only)
  182. conf.set('HAVE_V4L2', v4l2_support)
  183. # enable HID over AOA support (linux only)
  184. conf.set('HAVE_USB', usb_support)
  185. configure_file(configuration: conf, output: 'config.h')
  186. src_dir = include_directories('src')
  187. executable('scrcpy', src,
  188. dependencies: dependencies,
  189. include_directories: src_dir,
  190. install: true,
  191. c_args: [])
  192. # <https://mesonbuild.com/Builtin-options.html#directories>
  193. datadir = get_option('datadir') # by default 'share'
  194. install_man('scrcpy.1')
  195. install_data('data/icon.png',
  196. rename: 'scrcpy.png',
  197. install_dir: join_paths(datadir, 'icons/hicolor/256x256/apps'))
  198. install_data('data/zsh-completion/_scrcpy',
  199. install_dir: join_paths(datadir, 'zsh/site-functions'))
  200. install_data('data/bash-completion/scrcpy',
  201. install_dir: join_paths(datadir, 'bash-completion/completions'))
  202. # Desktop entry file for application launchers
  203. if host_machine.system() == 'linux'
  204. # Install a launcher (ex: /usr/local/share/applications/scrcpy.desktop)
  205. install_data('data/scrcpy.desktop',
  206. install_dir: join_paths(datadir, 'applications'))
  207. install_data('data/scrcpy-console.desktop',
  208. install_dir: join_paths(datadir, 'applications'))
  209. endif
  210. ### TESTS
  211. # do not build tests in release (assertions would not be executed at all)
  212. if get_option('buildtype') == 'debug'
  213. tests = [
  214. ['test_adb_parser', [
  215. 'tests/test_adb_parser.c',
  216. 'src/adb/adb_device.c',
  217. 'src/adb/adb_parser.c',
  218. 'src/util/str.c',
  219. 'src/util/strbuf.c',
  220. ]],
  221. ['test_binary', [
  222. 'tests/test_binary.c',
  223. ]],
  224. ['test_cbuf', [
  225. 'tests/test_cbuf.c',
  226. ]],
  227. ['test_cli', [
  228. 'tests/test_cli.c',
  229. 'src/cli.c',
  230. 'src/options.c',
  231. 'src/util/log.c',
  232. 'src/util/net.c',
  233. 'src/util/str.c',
  234. 'src/util/strbuf.c',
  235. 'src/util/term.c',
  236. ]],
  237. ['test_clock', [
  238. 'tests/test_clock.c',
  239. 'src/clock.c',
  240. ]],
  241. ['test_control_msg_serialize', [
  242. 'tests/test_control_msg_serialize.c',
  243. 'src/control_msg.c',
  244. 'src/util/str.c',
  245. 'src/util/strbuf.c',
  246. ]],
  247. ['test_device_msg_deserialize', [
  248. 'tests/test_device_msg_deserialize.c',
  249. 'src/device_msg.c',
  250. ]],
  251. ['test_queue', [
  252. 'tests/test_queue.c',
  253. ]],
  254. ['test_strbuf', [
  255. 'tests/test_strbuf.c',
  256. 'src/util/strbuf.c',
  257. ]],
  258. ['test_str', [
  259. 'tests/test_str.c',
  260. 'src/util/str.c',
  261. 'src/util/strbuf.c',
  262. ]],
  263. ['test_vector', [
  264. 'tests/test_vector.c',
  265. ]],
  266. ]
  267. foreach t : tests
  268. exe = executable(t[0], t[1],
  269. include_directories: src_dir,
  270. dependencies: dependencies,
  271. c_args: ['-DSDL_MAIN_HANDLED', '-DSC_TEST'])
  272. test(t[0], exe)
  273. endforeach
  274. endif