]> git.sesse.net Git - nageru/blob - meson.build
Switch build systems to Meson.
[nageru] / meson.build
1 project('nageru', 'cpp', default_options: ['buildtype=debugoptimized'])
2 qt5 = import('qt5')
3 protoc = find_program('protoc')
4 cxx = meson.get_compiler('cpp')
5
6 embedded_bmusb = get_option('embedded_bmusb')
7
8 alsadep = dependency('alsa')
9 bmusbdep = dependency('bmusb', required: not embedded_bmusb)
10 dldep = cxx.find_library('dl')
11 epoxydep = dependency('epoxy')
12 libavcodecdep = dependency('libavcodec')
13 libavformatdep = dependency('libavformat')
14 libavresampledep = dependency('libavresample')
15 libavutildep = dependency('libavutil')
16 libjpegdep = dependency('libjpeg')
17 libmicrohttpddep = dependency('libmicrohttpd')
18 libswscaledep = dependency('libswscale')
19 libusbdep = dependency('libusb-1.0')
20 luajitdep = dependency('luajit')
21 movitdep = dependency('movit')
22 protobufdep = dependency('protobuf')
23 qcustomplotdep = cxx.find_library('qcustomplot')
24 qt5deps = dependency('qt5', modules: ['Core', 'Gui', 'Widgets', 'OpenGLExtensions', 'OpenGL', 'PrintSupport'])
25 threaddep = dependency('threads')
26 vadrmdep = dependency('libva-drm')
27 vax11dep = dependency('libva-x11')
28 x11dep = dependency('x11')
29 x264dep = dependency('x264')
30 zitaresamplerdep = cxx.find_library('zita-resampler')
31
32 srcs = []
33 nageru_deps = [qt5deps, libjpegdep, movitdep, libmicrohttpddep, protobufdep,
34         vax11dep, vadrmdep, x11dep, libavformatdep, libavresampledep, libavcodecdep, libavutildep,
35         libswscaledep, libusbdep, luajitdep, dldep, x264dep, alsadep, zitaresamplerdep,
36         qcustomplotdep, threaddep]
37 nageru_include_dirs = []
38 nageru_link_with = []
39 nageru_link_args = []
40 nageru_build_rpath = ''
41 nageru_install_rpath = ''
42
43 kaeru_link_with = []
44 kaeru_extra_deps = []
45
46 # DeckLink has these issues, and we include it from various places.
47 if cxx.has_argument('-Wno-non-virtual-dtor')
48         add_project_arguments('-Wno-non-virtual-dtor', language: 'cpp')
49 endif
50
51 # FFmpeg has a lot of deprecated APIs whose replacements are not available
52 # in Debian stable, so we suppress these warnings.
53 if cxx.has_argument('-Wno-deprecated-declarations')
54         add_project_arguments('-Wno-deprecated-declarations', language: 'cpp')
55 endif
56
57 # Add the right MOVIT_SHADER_DIR definition.
58 r = run_command('pkg-config', '--variable=shaderdir', 'movit')
59 if r.returncode() != 0
60         error('Movit pkg-config installation is broken.')
61 endif
62 add_project_arguments('-DMOVIT_SHADER_DIR="' + r.stdout().strip() + '"', language: 'cpp')
63
64 # CEF.
65 exe_dir = join_paths(get_option('prefix'), 'lib/nageru')
66 cef_dir = get_option('cef_dir')
67 cef_build_type = get_option('cef_build_type')
68 have_cef = (cef_dir != '')
69 if have_cef
70         add_project_arguments('-DHAVE_CEF=1', language: 'cpp')
71
72         system_cef = (cef_build_type == 'system')
73         if system_cef
74                 cef_lib_dir = cef_dir
75                 cef_resource_dir = '/usr/share/cef/Resources'
76         else
77                 cef_lib_dir = join_paths(cef_dir, cef_build_type)
78                 cef_resource_dir = join_paths(cef_dir, 'Resources')
79
80                 nageru_include_dirs += include_directories(cef_dir)
81                 nageru_include_dirs += include_directories(join_paths(cef_dir, 'include'))
82                 nageru_build_rpath = cef_lib_dir
83                 nageru_install_rpath = '$ORIGIN/'
84         endif
85
86         cefdep = cxx.find_library('cef')
87         nageru_deps += cefdep
88
89         # CEF wrapper library; not built as part of the CEF binary distribution,
90         # but should be if CEF is installed as a system library.
91         if system_cef
92                 cefdlldep = cxx.find_library('cef_dll_wrapper')
93                 nageru_deps += cefdlldep
94         else
95                 cmake = find_program('cmake')
96                 cef_compile_script = find_program('scripts/compile_cef_dll_wrapper.sh')
97
98                 cef_dll_target = custom_target('libcef_dll_wrapper',
99                         input: join_paths(cef_dir, 'libcef_dll/CMakeLists.txt'),
100                         output: ['libcef_dll_wrapper.a', 'cef-stamp'],
101                         command: [cef_compile_script, '@BUILD_DIR@', cef_dir, cmake, '@OUTPUT@'])
102
103                 # Putting the .a in sources seemingly hits a bug where the .a files get sorted
104                 # in the wrong order. This is a workaround; see
105                 # https://github.com/mesonbuild/meson/issues/3613#issuecomment-408276296 .
106                 cefdlldep = declare_dependency(sources: cef_dll_target[1], link_args: cef_dll_target.full_path())
107                 nageru_deps += cefdlldep
108         endif
109
110         cef_libs = ['libEGL.so', 'libGLESv2.so', 'natives_blob.bin', 'snapshot_blob.bin', 'v8_context_snapshot.bin']
111         cef_resources = ['cef.pak', 'cef_100_percent.pak', 'cef_200_percent.pak', 'cef_extensions.pak', 'devtools_resources.pak']
112         if not get_option('cef_no_icudtl')
113                 cef_resources += ['icudtl.dat']
114         endif
115         if cef_build_type != 'system'
116                 cef_libs += ['libcef.so']
117         endif
118
119         # Symlink the files into the build directory, so that running nageru without ninja install works.
120         run_command('mkdir', join_paths(meson.current_build_dir(), 'locales/'))
121         foreach file : cef_libs
122                 run_command('ln', '-s', join_paths(cef_lib_dir, file), meson.current_build_dir())
123                 install_data(join_paths(cef_lib_dir, file), install_dir: exe_dir)
124         endforeach
125         foreach file : cef_resources
126                 run_command('ln', '-s', join_paths(cef_resource_dir, file), meson.current_build_dir())
127                 install_data(join_paths(cef_resource_dir, file), install_dir: exe_dir)
128         endforeach
129         run_command('ln', '-s', join_paths(cef_resource_dir, 'locales/en-US.pak'), join_paths(meson.current_build_dir(), 'locales/'))
130         install_data(join_paths(cef_resource_dir, 'locales/en-US.pak'), install_dir: join_paths(exe_dir, 'locales'))
131 endif
132
133 # bmusb.
134 if embedded_bmusb
135         bmusb_dir = include_directories('bmusb')
136         nageru_include_dirs += bmusb_dir
137
138         bmusb = static_library('bmusb', 'bmusb/bmusb.cpp', 'bmusb/fake_capture.cpp',
139                 dependencies: [libusbdep],
140                 include_directories: [bmusb_dir])
141         nageru_link_with += bmusb
142         kaeru_link_with += bmusb
143 else
144         nageru_deps += bmusbdep
145         kaeru_extra_deps += bmusbdep
146 endif
147
148 # Protobuf compilation.
149 gen = generator(protoc, \
150         output    : ['@BASENAME@.pb.cc', '@BASENAME@.pb.h'],
151         arguments : ['--proto_path=@CURRENT_SOURCE_DIR@', '--cpp_out=@BUILD_DIR@', '@INPUT@'])
152 proto_generated = gen.process(['state.proto', 'midi_mapping.proto', 'json.proto'])
153 protobuf_lib = static_library('protobufs', proto_generated, dependencies: nageru_deps, include_directories: nageru_include_dirs)
154 protobuf_hdrs = declare_dependency(sources: proto_generated)
155 nageru_link_with += protobuf_lib
156
157 # Preprocess Qt as needed.
158 qt_files = qt5.preprocess(
159         moc_headers: ['aboutdialog.h', 'analyzer.h', 'clickable_label.h', 'compression_reduction_meter.h', 'correlation_meter.h',
160                 'ellipsis_label.h', 'glwidget.h', 'input_mapping_dialog.h', 'lrameter.h', 'mainwindow.h', 'midi_mapping_dialog.h',
161                 'nonlinear_fader.h', 'vumeter.h'],
162         ui_files: ['aboutdialog.ui', 'analyzer.ui', 'audio_expanded_view.ui', 'audio_miniview.ui', 'display.ui',
163                 'input_mapping.ui', 'mainwindow.ui', 'midi_mapping.ui'],
164         dependencies: qt5deps)
165
166 # Qt objects.
167 srcs += ['glwidget.cpp', 'mainwindow.cpp', 'vumeter.cpp', 'lrameter.cpp', 'compression_reduction_meter.cpp',
168         'correlation_meter.cpp', 'aboutdialog.cpp', 'analyzer.cpp', 'input_mapping_dialog.cpp', 'midi_mapping_dialog.cpp',
169         'nonlinear_fader.cpp', 'context_menus.cpp', 'vu_common.cpp', 'piecewise_interpolator.cpp', 'midi_mapper.cpp']
170
171 # Auxiliary objects used for nearly everything.
172 aux_srcs = ['metrics.cpp', 'flags.cpp']
173 aux = static_library('aux', aux_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
174 nageru_link_with += aux
175
176 # Audio objects.
177 audio_mixer_srcs = ['audio_mixer.cpp', 'alsa_input.cpp', 'alsa_pool.cpp', 'ebu_r128_proc.cc', 'stereocompressor.cpp',
178         'resampling_queue.cpp', 'flags.cpp', 'correlation_measurer.cpp', 'filter.cpp', 'input_mapping.cpp']
179 audio = static_library('audio', audio_mixer_srcs, dependencies: [nageru_deps, protobuf_hdrs], include_directories: nageru_include_dirs)
180 nageru_link_with += audio
181
182 # Mixer objects.
183 srcs += ['chroma_subsampler.cpp', 'v210_converter.cpp', 'mixer.cpp', 'pbo_frame_allocator.cpp',
184         'context.cpp', 'theme.cpp', 'image_input.cpp', 'alsa_output.cpp',
185         'disk_space_estimator.cpp', 'timecode_renderer.cpp', 'tweaked_inputs.cpp']
186
187 # Streaming and encoding objects (largely the set that is shared between Nageru and Kaeru).
188 stream_srcs = ['quicksync_encoder.cpp', 'x264_encoder.cpp', 'x264_dynamic.cpp', 'x264_speed_control.cpp', 'video_encoder.cpp',
189         'metacube2.cpp', 'mux.cpp', 'audio_encoder.cpp', 'ffmpeg_raii.cpp', 'ffmpeg_util.cpp', 'httpd.cpp', 'ffmpeg_capture.cpp',
190         'print_latency.cpp', 'basic_stats.cpp', 'ref_counted_frame.cpp']
191 stream = static_library('stream', stream_srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
192 nageru_link_with += stream
193
194 # DeckLink.
195 srcs += ['decklink_capture.cpp', 'decklink_util.cpp', 'decklink_output.cpp', 'memcpy_interleaved.cpp',
196         'decklink/DeckLinkAPIDispatch.cpp']
197 decklink_dir = include_directories('decklink')
198 nageru_include_dirs += decklink_dir
199
200 # CEF input.
201 if have_cef
202         srcs += ['nageru_cef_app.cpp', 'cef_capture.cpp']
203 endif
204
205 srcs += qt_files
206 srcs += proto_generated
207
208 # Everything except main.cpp. (We do this because if you specify a .cpp file in
209 # both Nageru and Kaeru, it gets compiled twice. In the older Makefiles, Kaeru
210 # depended on a smaller set of objects.)
211 core = static_library('core', srcs, dependencies: nageru_deps, include_directories: nageru_include_dirs)
212 nageru_link_with += core
213
214 # Nageru executable; it goes into /usr/lib/nageru since CEF files go there, too
215 # (we can't put them straight into /usr/bin).
216 executable('nageru', 'main.cpp',
217         dependencies: nageru_deps,
218         include_directories: nageru_include_dirs,
219         link_with: nageru_link_with,
220         link_args: nageru_link_args,
221         build_rpath: nageru_build_rpath,
222         install_rpath: nageru_install_rpath,
223         install: true,
224         install_dir: exe_dir
225 )
226 meson.add_install_script('scripts/setup_nageru_symlink.sh')
227
228 # Kaeru executable.
229 executable('kaeru', 'kaeru.cpp',
230         dependencies: [nageru_deps, kaeru_extra_deps],
231         include_directories: nageru_include_dirs,
232         link_with: [stream, aux, kaeru_link_with],
233         install: true)
234
235 # Audio mixer microbenchmark.
236 executable('benchmark_audio_mixer', 'benchmark_audio_mixer.cpp', dependencies: nageru_deps, include_directories: nageru_include_dirs, link_with: [audio, aux])
237
238 # These are needed for a default run.
239 data_files = ['theme.lua', 'simple.lua', 'bg.jpeg', 'akai_midimix.midimapping']
240 install_data(data_files, install_dir: join_paths(get_option('prefix'), 'share/nageru'))
241 foreach file : data_files
242         run_command('ln', '-s', join_paths(meson.current_source_dir(), file), meson.current_build_dir())
243 endforeach