meson.build 5.4 KB
Newer Older
R
Romain Vimont 已提交
1
src = [
R
Romain Vimont 已提交
2
    'src/main.c',
3
    'src/cli.c',
R
Romain Vimont 已提交
4
    'src/command.c',
R
Romain Vimont 已提交
5
    'src/control_msg.c',
R
Romain Vimont 已提交
6
    'src/controller.c',
R
Romain Vimont 已提交
7
    'src/decoder.c',
8
    'src/device.c',
R
Romain Vimont 已提交
9
    'src/device_msg.c',
10
    'src/event_converter.c',
N
npes87184 已提交
11
    'src/file_handler.c',
12 13
    'src/fps_counter.c',
    'src/input_manager.c',
14
    'src/opengl.c',
R
Romain Vimont 已提交
15
    'src/receiver.c',
R
Romain Vimont 已提交
16
    'src/recorder.c',
R
Romain Vimont 已提交
17
    'src/scrcpy.c',
18
    'src/screen.c',
R
Romain Vimont 已提交
19
    'src/server.c',
R
Romain Vimont 已提交
20
    'src/stream.c',
R
Romain Vimont 已提交
21
    'src/tiny_xpm.c',
22
    'src/video_buffer.c',
R
Romain Vimont 已提交
23 24
    'src/util/net.c',
    'src/util/str_util.c'
R
Romain Vimont 已提交
25 26
]

27
if not get_option('crossbuild_windows')
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    # native build
    dependencies = [
        dependency('libavformat'),
        dependency('libavcodec'),
        dependency('libavutil'),
        dependency('sdl2'),
    ]

else

    # cross-compile mingw32 build (from Linux to Windows)
    cc = meson.get_compiler('c')

    prebuilt_sdl2 = meson.get_cross_property('prebuilt_sdl2')
    sdl2_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/bin'
    sdl2_lib_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_sdl2 + '/lib'
    sdl2_include_dir = '../prebuilt-deps/' + prebuilt_sdl2 + '/include'

    sdl2 = declare_dependency(
        dependencies: [
            cc.find_library('SDL2', dirs: sdl2_bin_dir),
            cc.find_library('SDL2main', dirs: sdl2_lib_dir),
        ],
        include_directories: include_directories(sdl2_include_dir)
    )

    prebuilt_ffmpeg_shared = meson.get_cross_property('prebuilt_ffmpeg_shared')
    prebuilt_ffmpeg_dev = meson.get_cross_property('prebuilt_ffmpeg_dev')
    ffmpeg_bin_dir = meson.current_source_dir() + '/../prebuilt-deps/' + prebuilt_ffmpeg_shared + '/bin'
    ffmpeg_include_dir = '../prebuilt-deps/' + prebuilt_ffmpeg_dev + '/include'
    ffmpeg = declare_dependency(
        dependencies: [
            cc.find_library('avcodec-58', dirs: ffmpeg_bin_dir),
            cc.find_library('avformat-58', dirs: ffmpeg_bin_dir),
            cc.find_library('avutil-56', dirs: ffmpeg_bin_dir),
        ],
        include_directories: include_directories(ffmpeg_include_dir)
    )

    dependencies = [
        ffmpeg,
        sdl2,
        cc.find_library('mingw32')
    ]

endif
R
Romain Vimont 已提交
75

76 77 78 79 80 81 82 83 84
cc = meson.get_compiler('c')

if host_machine.system() == 'windows'
    src += [ 'src/sys/win/command.c' ]
    dependencies += cc.find_library('ws2_32')
else
    src += [ 'src/sys/unix/command.c' ]
endif

85 86
conf = configuration_data()

87
# expose the build type
R
Romain Vimont 已提交
88
conf.set('NDEBUG', get_option('buildtype') != 'debug')
89

R
Romain Vimont 已提交
90
# the version, updated on release
91
conf.set_quoted('SCRCPY_VERSION', meson.project_version())
R
Romain Vimont 已提交
92

R
Romain Vimont 已提交
93
# the prefix used during configuration (meson --prefix=PREFIX)
R
Romain Vimont 已提交
94
conf.set_quoted('PREFIX', get_option('prefix'))
R
Romain Vimont 已提交
95

96
# build a "portable" version (with scrcpy-server accessible from the same
R
Romain Vimont 已提交
97
# directory as the executable)
98
conf.set('PORTABLE', get_option('portable'))
R
Romain Vimont 已提交
99

R
Romain Vimont 已提交
100
# the default client TCP port range for the "adb reverse" tunnel
101
# overridden by option --port
R
Romain Vimont 已提交
102 103
conf.set('DEFAULT_LOCAL_PORT_RANGE_FIRST', '27183')
conf.set('DEFAULT_LOCAL_PORT_RANGE_LAST', '27199')
104 105 106 107 108

# the default max video size for both dimensions, in pixels
# overridden by option --max-size
conf.set('DEFAULT_MAX_SIZE', '0')  # 0: unlimited

109 110 111 112 113 114
# the default video orientation
# natural device orientation is 0 and each increment adds 90 degrees
# counterclockwise
# overridden by option --lock-video-orientation
conf.set('DEFAULT_LOCK_VIDEO_ORIENTATION', '-1')  # -1: unlocked

115 116
# the default video bitrate, in bits/second
# overridden by option --bit-rate
R
Romain Vimont 已提交
117
conf.set('DEFAULT_BIT_RATE', '8000000')  # 8Mbps
118

119 120 121
# disable console on Windows
conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))

122 123 124
# run a server debugger and wait for a client to be attached
conf.set('SERVER_DEBUGGER', get_option('server_debugger'))

125 126 127
# select the debugger method ('old' for Android < 9, 'new' for Android >= 9)
conf.set('SERVER_DEBUGGER_METHOD_NEW', get_option('server_debugger_method') == 'new')

R
Romain Vimont 已提交
128
configure_file(configuration: conf, output: 'config.h')
129

R
Romain Vimont 已提交
130
src_dir = include_directories('src')
131 132

if get_option('windows_noconsole')
R
Romain Vimont 已提交
133
    link_args = [ '-Wl,--subsystem,windows' ]
134 135 136 137
else
    link_args = []
endif

138 139 140 141
executable('scrcpy', src,
           dependencies: dependencies,
           include_directories: src_dir,
           install: true,
R
Romain Vimont 已提交
142
           c_args: [],
143
           link_args: link_args)
R
Romain Vimont 已提交
144

Y
yangfl 已提交
145 146
install_man('scrcpy.1')

R
Romain Vimont 已提交
147 148 149

### TESTS

R
Romain Vimont 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
# do not build tests in release (assertions would not be executed at all)
if get_option('buildtype') == 'debug'
    tests = [
        ['test_buffer_util', [
            'tests/test_buffer_util.c'
        ]],
        ['test_cbuf', [
            'tests/test_cbuf.c',
        ]],
        ['test_cli', [
            'tests/test_cli.c',
            'src/cli.c',
            'src/util/str_util.c',
        ]],
        ['test_control_event_serialize', [
            'tests/test_control_msg_serialize.c',
            'src/control_msg.c',
            'src/util/str_util.c',
        ]],
        ['test_device_event_deserialize', [
            'tests/test_device_msg_deserialize.c',
            'src/device_msg.c',
        ]],
        ['test_queue', [
            'tests/test_queue.c',
        ]],
        ['test_strutil', [
            'tests/test_strutil.c',
            'src/util/str_util.c',
        ]],
    ]
R
Romain Vimont 已提交
181

R
Romain Vimont 已提交
182 183 184 185 186 187 188 189
    foreach t : tests
        exe = executable(t[0], t[1],
                         include_directories: src_dir,
                         dependencies: dependencies,
                         c_args: ['-DSDL_MAIN_HANDLED'])
        test(t[0], exe)
    endforeach
endif