]> git.sesse.net Git - nageru/blob - meson.build
Release Nageru and Futatabi 2.0.2.
[nageru] / meson.build
1 project('nageru', 'cpp', default_options: ['buildtype=debugoptimized'], version: '2.0.2')
2
3 cxx = meson.get_compiler('cpp')
4 qt5 = import('qt5')
5 protoc = find_program('protoc')
6
7 embedded_bmusb = get_option('embedded_bmusb')
8
9 alsadep = dependency('alsa')
10 bmusbdep = dependency('bmusb', required: not embedded_bmusb)
11 dldep = cxx.find_library('dl')
12 eigendep = dependency('eigen3')
13 epoxydep = dependency('epoxy')
14 libavcodecdep = dependency('libavcodec')
15 libavformatdep = dependency('libavformat')
16 libswresampledep = dependency('libswresample')
17 libavutildep = dependency('libavutil')
18 libdrmdep = dependency('libdrm')
19 libjpegdep = dependency('libjpeg')
20 libswscaledep = dependency('libswscale')
21 libusbdep = dependency('libusb-1.0')
22 luajitdep = dependency('luajit')
23 movitdep = dependency('movit')
24 protobufdep = dependency('protobuf')
25 qcustomplotdep = cxx.find_library('qcustomplot')
26 qt5deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'OpenGLExtensions', 'OpenGL', 'Network'])
27 sdl2_imagedep = dependency('SDL2_image', required: false)
28 sdl2dep = dependency('sdl2', required: false)
29 srtdep = dependency('srt', required: false)
30 sqlite3dep = dependency('sqlite3')
31 threaddep = dependency('threads')
32 vadrmdep = dependency('libva-drm')
33 vax11dep = dependency('libva-x11')
34 x11dep = dependency('x11')
35 x264dep = dependency('x264')
36 zitaresamplerdep = cxx.find_library('zita-resampler')
37
38 # Use lld if we can; it links a lot faster than ld.bfd or gold.
39 code = '''#include <stdio.h>
40 int main() { printf("Hello, world!\n"); return 0; }
41 '''
42 if cxx.links(code, args: '-fuse-ld=lld', name: 'check for LLD')
43         add_project_link_arguments('-fuse-ld=lld', language: 'cpp')
44 endif
45
46 # Add the right MOVIT_SHADER_DIR definition.
47 movit_shader_dir = movitdep.get_pkgconfig_variable('shaderdir')
48 add_project_arguments('-DMOVIT_SHADER_DIR="' + movit_shader_dir + '"', language: 'cpp')
49
50 # Make the Nageru version available as a #define.
51 add_project_arguments('-DNAGERU_VERSION="' + meson.project_version() + '"', language: 'cpp')
52
53 # Make the prefix (e.g. /usr/local) available as a #define.
54 add_project_arguments('-DPREFIX="' + get_option('prefix') + '"', language: 'cpp')
55
56 # This needs to be done before declaring any build targets.
57 if get_option('cef_dir') != ''
58         add_project_arguments('-DHAVE_CEF=1', language: 'cpp')
59 endif
60
61 if srtdep.found()
62         # NOTE: Seemingly there's no way to figure out if we have OpenSSL libsrt
63         # or gnutls libsrt, so we cannot check license compatibility here.
64         add_project_arguments('-DHAVE_SRT=1', language: 'cpp')
65 endif
66
67 top_include = include_directories('.')
68
69 subdir('shared')
70
71 # Nageru. (Not a subdir() because we don't want the output in nageru/nageru.)
72
73 nageru_srcs = []
74 nageru_deps = [shareddep, qt5deps, libjpegdep, movitdep, protobufdep,
75         vax11dep, vadrmdep, x11dep, libavformatdep, libswresampledep, libavcodecdep, libavutildep,
76         libswscaledep, libusbdep, luajitdep, dldep, x264dep, alsadep, zitaresamplerdep,
77         qcustomplotdep, threaddep, eigendep, srtdep, libdrmdep]
78 nageru_include_dirs = [include_directories('nageru')]
79 nageru_link_with = []
80 nageru_build_rpath = ''
81 nageru_install_rpath = ''
82
83 kaeru_link_with = []
84 kaeru_extra_deps = []
85
86 # CEF.
87 exe_dir = join_paths(get_option('prefix'), 'lib/nageru')
88 cef_dir = get_option('cef_dir')
89 cef_build_type = get_option('cef_build_type')
90 have_cef = (cef_dir != '')
91 if have_cef
92         # This is done in the top-level file; just kept here for reference.
93         # add_project_arguments('-DHAVE_CEF=1', language: 'cpp')
94
95         system_cef = (cef_build_type == 'system')
96         if system_cef
97                 cef_lib_dir = cef_dir
98                 cef_resource_dir = cef_dir
99         else
100                 cef_lib_dir = join_paths(cef_dir, cef_build_type)
101                 cef_resource_dir = join_paths(cef_dir, 'Resources')
102
103                 nageru_include_dirs += include_directories(cef_dir)
104                 nageru_include_dirs += include_directories(join_paths(cef_dir, 'include'))
105                 nageru_build_rpath = cef_lib_dir
106                 nageru_install_rpath = '$ORIGIN/'
107         endif
108
109         # CEF wrapper library; not built as part of the CEF binary distribution,
110         # but should be if CEF is installed as a system library.
111         if system_cef
112                 cefdlldep = cxx.find_library('cef_dll_wrapper')
113                 nageru_deps += cefdlldep
114         else
115                 cmake = find_program('cmake')
116                 cef_compile_script = find_program('nageru/scripts/compile_cef_dll_wrapper.sh')
117
118                 cef_dll_target = custom_target('libcef_dll_wrapper',
119                         input: join_paths(cef_dir, 'libcef_dll/CMakeLists.txt'),
120                         output: ['libcef_dll_wrapper.a', 'cef-stamp'],
121                         command: [cef_compile_script, '@BUILD_DIR@', cef_dir, cmake, '@OUTPUT@'])
122
123                 # Putting the .a in sources seemingly hits a bug where the .a files get sorted
124                 # in the wrong order. This is a workaround; see
125                 # https://github.com/mesonbuild/meson/issues/3613#issuecomment-408276296 .
126                 cefdlldep = declare_dependency(sources: cef_dll_target[1], link_args: cef_dll_target.full_path())
127                 nageru_deps += cefdlldep
128         endif
129
130         cef_libs = ['libEGL.so', 'libGLESv2.so', 'snapshot_blob.bin', 'v8_context_snapshot.bin']
131         cef_resources = ['cef.pak', 'cef_100_percent.pak', 'cef_200_percent.pak', 'cef_extensions.pak', 'devtools_resources.pak']
132         if not get_option('cef_no_icudtl')
133                 cef_resources += ['icudtl.dat']
134         endif
135         if cef_build_type != 'system'
136                 cef_libs += ['libcef.so']
137         endif
138
139         # Symlink the files into the build directory, so that running nageru without ninja install works.
140         run_command('mkdir', join_paths(meson.current_build_dir(), 'locales/'))
141         foreach file : cef_libs
142                 run_command('ln', '-s', join_paths(cef_lib_dir, file), meson.current_build_dir())
143                 install_data(join_paths(cef_lib_dir, file), install_dir: exe_dir)
144         endforeach
145         foreach file : cef_resources
146                 run_command('ln', '-s', join_paths(cef_resource_dir, file), meson.current_build_dir())
147                 install_data(join_paths(cef_resource_dir, file), install_dir: exe_dir)
148         endforeach
149         run_command('ln', '-s', join_paths(cef_resource_dir, 'locales/en-US.pak'), join_paths(meson.current_build_dir(), 'locales/'))
150         install_data(join_paths(cef_resource_dir, 'locales/en-US.pak'), install_dir: join_paths(exe_dir, 'locales'))
151
152         # NOTE: We link against libcef.so in the local directory, _not_ in the CEF directory,
153         # since upstream CEF searches for icudtl.dat in whatever path dladdr() says libcef.so
154         # comes from, and the upstream CEF tarballs have libcef.so and icudtl.dat in different
155         # directories. Thus, get both from the local symlinks we just created.
156         cefdep = cxx.find_library('cef', dirs: meson.current_build_dir())
157         nageru_deps += cefdep
158 endif
159
160 # bmusb.
161 if embedded_bmusb
162         bmusb_dir = include_directories('nageru/bmusb')
163         nageru_include_dirs += bmusb_dir
164
165         bmusb = static_library('bmusb', 'nageru/bmusb/bmusb.cpp', 'nageru/bmusb/fake_capture.cpp',
166                 dependencies: [libusbdep],
167                 include_directories: [bmusb_dir])
168         nageru_link_with += bmusb
169         kaeru_link_with += bmusb
170 else
171         nageru_deps += bmusbdep
172         kaeru_extra_deps += bmusbdep
173 endif
174
175 # Protobuf compilation.
176 gen = generator(protoc, \
177         output    : ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
178         arguments : ['--proto_path=@CURRENT_SOURCE_DIR@/nageru', '--cpp_out=@BUILD_DIR@', '-I@CURRENT_SOURCE_DIR@/shared', '@INPUT@'])
179 proto_generated = gen.process(['nageru/state.proto', 'nageru/json.proto', 'nageru/nageru_midi_mapping.proto'])
180 protobuf_lib = static_library('nageru_protobufs', proto_generated, dependencies: nageru_deps, include_directories: nageru_include_dirs)
181 protobuf_hdrs = declare_dependency(sources: proto_generated)
182 nageru_link_with += protobuf_lib
183
184 # Preprocess Qt as needed.
185 qt_files = qt5.preprocess(
186         moc_headers: ['nageru/analyzer.h', 'nageru/clickable_label.h', 'nageru/compression_reduction_meter.h', 'nageru/correlation_meter.h',
187                 'nageru/ellipsis_label.h', 'nageru/glwidget.h', 'nageru/input_mapping_dialog.h', 'nageru/lrameter.h', 'nageru/mainwindow.h', 'nageru/midi_mapping_dialog.h',
188                 'nageru/nonlinear_fader.h', 'nageru/vumeter.h'],
189         ui_files: ['nageru/analyzer.ui', 'nageru/audio_expanded_view.ui', 'nageru/audio_miniview.ui', 'nageru/display.ui',
190                 'nageru/input_mapping.ui', 'nageru/mainwindow.ui', 'nageru/midi_mapping.ui'],
191         dependencies: qt5deps)
192
193 # Qt objects.
194 nageru_srcs += ['nageru/glwidget.cpp', 'nageru/mainwindow.cpp', 'nageru/vumeter.cpp', 'nageru/lrameter.cpp', 'nageru/compression_reduction_meter.cpp',
195         'nageru/correlation_meter.cpp', 'nageru/analyzer.cpp', 'nageru/input_mapping_dialog.cpp', 'nageru/midi_mapping_dialog.cpp',
196         'nageru/nonlinear_fader.cpp', 'nageru/context_menus.cpp', 'nageru/vu_common.cpp', 'nageru/piecewise_interpolator.cpp', 'nageru/midi_mapper.cpp']
197
198 # Auxiliary objects used for nearly everything.
199 aux_srcs = ['nageru/flags.cpp']
200 aux = static_library('aux', aux_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
201 nageru_link_with += aux
202
203 # Audio objects.
204 audio_mixer_srcs = ['nageru/audio_mixer.cpp', 'nageru/alsa_input.cpp', 'nageru/alsa_pool.cpp', 'nageru/ebu_r128_proc.cc', 'nageru/stereocompressor.cpp',
205         'nageru/resampling_queue.cpp', 'nageru/flags.cpp', 'nageru/correlation_measurer.cpp', 'nageru/filter.cpp', 'nageru/input_mapping.cpp']
206 audio = static_library('audio', audio_mixer_srcs, dependencies: [nageru_deps, protobuf_hdrs], include_directories: nageru_include_dirs)
207 nageru_link_with += audio
208
209 # Mixer objects.
210 nageru_srcs += ['nageru/chroma_subsampler.cpp', 'nageru/v210_converter.cpp', 'nageru/mixer.cpp', 'nageru/pbo_frame_allocator.cpp',
211         'nageru/theme.cpp', 'nageru/scene.cpp', 'nageru/image_input.cpp', 'nageru/alsa_output.cpp',
212         'nageru/timecode_renderer.cpp', 'nageru/tweaked_inputs.cpp', 'nageru/mjpeg_encoder.cpp']
213
214 # Streaming and encoding objects (largely the set that is shared between Nageru and Kaeru).
215 stream_srcs = ['nageru/quicksync_encoder.cpp', 'nageru/x264_encoder.cpp', 'nageru/x264_dynamic.cpp', 'nageru/x264_speed_control.cpp', 'nageru/video_encoder.cpp',
216         'nageru/audio_encoder.cpp', 'nageru/ffmpeg_util.cpp', 'nageru/ffmpeg_capture.cpp',
217         'nageru/print_latency.cpp', 'nageru/basic_stats.cpp', 'nageru/ref_counted_frame.cpp',
218         'nageru/v4l_output.cpp']
219 stream = static_library('stream', stream_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
220 nageru_link_with += stream
221
222 # DeckLink.
223 decklink_dir = include_directories('nageru/decklink', is_system: true)
224 decklink_lib = static_library('decklink', 'nageru/decklink/DeckLinkAPIDispatch.cpp', include_directories: decklink_dir, cpp_args: '-w')
225 nageru_link_with += decklink_lib
226
227 nageru_srcs += ['nageru/decklink_capture.cpp', 'nageru/decklink_util.cpp', 'nageru/decklink_output.cpp']
228 nageru_include_dirs += decklink_dir
229
230 # CEF input.
231 if have_cef
232         nageru_srcs += ['nageru/nageru_cef_app.cpp', 'nageru/cef_capture.cpp']
233 endif
234
235 nageru_srcs += qt_files
236 nageru_srcs += proto_generated
237
238 # Shaders needed at runtime.
239 shaders = ['nageru/cbcr_subsample.vert', 'nageru/cbcr_subsample.frag', 'nageru/uyvy_subsample.vert', 'nageru/uyvy_subsample.frag', 'nageru/v210_subsample.comp', 'nageru/timecode.vert', 'nageru/timecode.frag', 'nageru/timecode_10bit.frag']
240 foreach shader : shaders
241         run_command('ln', '-s', join_paths(meson.current_source_dir(), shader), meson.current_build_dir())
242 endforeach
243
244 nageru_shader_srcs = bin2h_gen.process(shaders)
245 nageru_srcs += nageru_shader_srcs
246
247 # Everything except main.cpp. (We do this because if you specify a .cpp file in
248 # both Nageru and Kaeru, it gets compiled twice. In the older Makefiles, Kaeru
249 # depended on a smaller set of objects.)
250 core = static_library('core', nageru_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
251 nageru_link_with += core
252
253 # Nageru executable; it goes into /usr/lib/nageru since CEF files go there, too
254 # (we can't put them straight into /usr/bin).
255 executable('nageru', 'nageru/main.cpp',
256         dependencies: nageru_deps,
257         include_directories: nageru_include_dirs,
258         link_with: nageru_link_with,
259         build_rpath: nageru_build_rpath,
260         install_rpath: nageru_install_rpath,
261         install: true,
262         install_dir: exe_dir
263 )
264 meson.add_install_script('nageru/scripts/setup_nageru_symlink.sh')
265
266 # Kaeru executable.
267 executable('kaeru', 'nageru/kaeru.cpp',
268         dependencies: [nageru_deps, kaeru_extra_deps],
269         include_directories: nageru_include_dirs,
270         link_with: [stream, aux, kaeru_link_with],
271         install: true)
272
273 # Audio mixer microbenchmark.
274 executable('benchmark_audio_mixer', 'nageru/benchmark_audio_mixer.cpp', dependencies: nageru_deps, include_directories: nageru_include_dirs, link_with: [audio, aux])
275
276 # These are needed for a default run.
277 data_files = ['nageru/theme.lua', 'nageru/simple.lua', 'nageru/bg.jpeg', 'nageru/akai_midimix.midimapping', 'futatabi/behringer_cmd_pl1.midimapping']
278 install_data(data_files, install_dir: join_paths(get_option('prefix'), 'share/nageru'))
279 foreach file : data_files
280         run_command('ln', '-s', join_paths(meson.current_source_dir(), file), meson.current_build_dir())
281 endforeach
282
283 # Futatabi. (Not a subdir() because we don't want the output in nageru/nageru.)
284
285 # Protobuf compilation.
286 gen = generator(protoc, \
287         output    : ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
288         arguments : ['--proto_path=@CURRENT_SOURCE_DIR@/futatabi', '--cpp_out=@BUILD_DIR@', '-I@CURRENT_SOURCE_DIR@/shared', '@INPUT@'])
289 proto_generated = gen.process('futatabi/state.proto', 'futatabi/frame.proto', 'futatabi/futatabi_midi_mapping.proto')
290
291 # Preprocess Qt as needed.
292 moc_files = qt5.preprocess(
293         moc_headers: ['futatabi/mainwindow.h', 'futatabi/jpeg_frame_view.h', 'futatabi/clip_list.h', 'futatabi/midi_mapping_dialog.h'],
294         ui_files: ['futatabi/mainwindow.ui', 'futatabi/midi_mapping.ui'],
295         qresources: ['futatabi/mainwindow.qrc'],
296         dependencies: qt5deps)
297
298 # Flow objects.
299 futatabi_srcs = ['futatabi/flow.cpp', 'futatabi/gpu_timers.cpp']
300
301 # All the other files.
302 futatabi_srcs += ['futatabi/main.cpp', 'futatabi/player.cpp', 'futatabi/video_stream.cpp', 'futatabi/chroma_subsampler.cpp']
303 futatabi_srcs += ['futatabi/vaapi_jpeg_decoder.cpp', 'futatabi/db.cpp', 'futatabi/ycbcr_converter.cpp', 'futatabi/flags.cpp']
304 futatabi_srcs += ['futatabi/mainwindow.cpp', 'futatabi/jpeg_frame_view.cpp', 'futatabi/clip_list.cpp', 'futatabi/frame_on_disk.cpp']
305 futatabi_srcs += ['futatabi/export.cpp', 'futatabi/midi_mapper.cpp', 'futatabi/midi_mapping_dialog.cpp']
306 futatabi_srcs += ['futatabi/exif_parser.cpp', 'futatabi/pbo_pool.cpp']
307 futatabi_srcs += moc_files
308 futatabi_srcs += proto_generated
309
310 # Shaders needed at runtime.
311 shaders = ['futatabi/chroma_subsample.vert', 'futatabi/densify.vert', 'futatabi/equations.vert', 'futatabi/hole_fill.vert', 'futatabi/motion_search.vert', 'futatabi/sor.vert', 'futatabi/splat.vert', 'futatabi/vs.vert']
312 shaders += ['futatabi/add_base_flow.frag', 'futatabi/blend.frag', 'futatabi/chroma_subsample.frag', 'futatabi/densify.frag', 'futatabi/derivatives.frag', 'futatabi/diffusivity.frag',
313         'futatabi/equations.frag', 'futatabi/gray.frag', 'futatabi/hole_blend.frag', 'futatabi/hole_fill.frag', 'futatabi/motion_search.frag', 'futatabi/prewarp.frag', 'futatabi/resize_flow.frag',
314         'futatabi/sobel.frag', 'futatabi/sor.frag', 'futatabi/splat.frag']
315
316 foreach shader : shaders
317         run_command('ln', '-s', join_paths(meson.current_source_dir(), shader), meson.current_build_dir())
318 endforeach
319
320 futatabi_shader_srcs = bin2h_gen.process(shaders)
321 futatabi_srcs += futatabi_shader_srcs
322
323 executable('futatabi', futatabi_srcs,
324         dependencies: [shareddep, qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep, sqlite3dep, vax11dep, vadrmdep, x11dep, threaddep, libavformatdep, libavcodecdep, libavutildep, libswscaledep, eigendep],
325         link_with: shared,
326         include_directories: [include_directories('futatabi')],
327         install: true)
328
329 # Test binaries for the optical flow code.
330 if sdl2dep.found() and sdl2_imagedep.found()
331         executable('flow', 'futatabi/flow_main.cpp', 'futatabi/flow.cpp', 'futatabi/gpu_timers.cpp', futatabi_shader_srcs, dependencies: [shareddep, epoxydep, sdl2dep, sdl2_imagedep])
332 endif
333 executable('eval', 'futatabi/eval.cpp', 'futatabi/util.cpp')
334 executable('vis', 'futatabi/vis.cpp', 'futatabi/util.cpp')