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

24
if not get_option('crossbuild_windows')
25 26 27 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

    # 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 已提交
72

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

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

84 85
conf = configuration_data()

86 87 88
# expose the build type
conf.set('BUILD_DEBUG', get_option('buildtype') == 'debug')

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

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

# the path of the server, which will be appended to the prefix
96
# ignored if OVERRIDE_SERVER_PATH if defined
R
Romain Vimont 已提交
97
# must be consistent with the install_dir in server/meson.build
98
conf.set_quoted('PREFIXED_SERVER_PATH', '/share/scrcpy/scrcpy-server.jar')
R
Romain Vimont 已提交
99 100 101 102

# the path of the server to be used "as is"
# this is useful for building a "portable" version (with the server in the same
# directory as the client)
103 104 105
override_server_path = get_option('override_server_path')
if override_server_path != ''
    conf.set_quoted('OVERRIDE_SERVER_PATH', override_server_path)
R
Romain Vimont 已提交
106 107
else
    # undefine it
108
    conf.set('OVERRIDE_SERVER_PATH', false)
R
Romain Vimont 已提交
109 110
endif

111 112 113 114 115 116 117 118 119 120
# the default client TCP port for the "adb reverse" tunnel
# overridden by option --port
conf.set('DEFAULT_LOCAL_PORT', '27183')

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

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

123 124 125
# whether the app should always display the most recent available frame, even
# if the previous one has not been displayed
# SKIP_FRAMES improves latency at the cost of framerate
126
conf.set('SKIP_FRAMES', get_option('skip_frames'))
127

128 129 130
# enable High DPI support
conf.set('HIDPI_SUPPORT', get_option('hidpi_support'))

131 132 133
# disable console on Windows
conf.set('WINDOWS_NOCONSOLE', get_option('windows_noconsole'))

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

R
Romain Vimont 已提交
136
src_dir = include_directories('src')
137 138 139 140 141 142 143 144 145

if get_option('windows_noconsole')
    c_args = [ '-mwindows' ]
    link_args = [ '-mwindows' ]
else
    c_args = []
    link_args = []
endif

146 147 148 149 150 151
executable('scrcpy', src,
           dependencies: dependencies,
           include_directories: src_dir,
           install: true,
           c_args: c_args,
           link_args: link_args)
R
Romain Vimont 已提交
152 153 154 155 156


### TESTS

tests = [
R
Romain Vimont 已提交
157 158 159
    ['test_cbuf', [
        'tests/test_cbuf.c',
    ]],
160 161
    ['test_control_event_serialize', [
        'tests/test_control_event_serialize.c',
162 163
        'src/control_event.c',
        'src/str_util.c'
164 165 166 167 168
    ]],
    ['test_strutil', [
        'tests/test_strutil.c',
        'src/str_util.c'
    ]],
R
Romain Vimont 已提交
169 170 171
]

foreach t : tests
172 173 174
    exe = executable(t[0], t[1],
                     include_directories: src_dir,
                     dependencies: dependencies)
R
Romain Vimont 已提交
175 176
    test(t[0], exe)
endforeach