meson.build 14.4 KB
Newer Older
1 2 3
project(
  'mpd',
  ['c', 'cpp'],
4
  version: '0.23.15',
5
  meson_version: '>= 0.56.0',
6
  default_options: [
7 8
    'c_std=c11',
    'build.c_std=c11',
9
    'cpp_std=c++17',
10
    'build.cpp_std=c++17',
11
    'warning_level=3',
12

13 14
    # If we build those libraries as Meson subproject, they shall be
    # linked statically into the MPD executable.
15
    'expat:default_library=static',
16 17 18
    'fmt:default_library=static',
    'gtest:default_library=static',
    'sqlite3:default_library=static',
19
    'vorbis:default_library=static',
20 21

    # Not interested in compiler warnings from subprojects.
22 23
    'expat:werror=false',
    'expat:warning_level=0',
24 25 26
    'fmt:warning_level=0',
    'gtest:warning_level=0',
    'sqlite3:warning_level=0',
27
    'vorbis:warning_level=0',
28 29 30 31 32 33 34 35 36
  ],
  license: 'GPLv2+',
)

version_cxx = vcs_tag(input: 'src/GitVersion.cxx', output: 'GitVersion.cxx')

compiler = meson.get_compiler('cpp')
c_compiler = meson.get_compiler('c')

37 38
if compiler.get_id() == 'gcc' and compiler.version().version_compare('<8')
  warning('Your GCC version is too old.  You need at least version 8.')
39 40
elif compiler.get_id() == 'clang' and compiler.version().version_compare('<7')
  warning('Your clang version is too old.  You need at least version 7.')
41 42
endif

43 44 45 46
version_conf = configuration_data()
version_conf.set_quoted('PACKAGE', meson.project_name())
version_conf.set_quoted('PACKAGE_NAME', meson.project_name())
version_conf.set_quoted('VERSION', meson.project_version())
47
version_conf.set_quoted('PROTOCOL_VERSION', '0.23.5')
48 49
configure_file(output: 'Version.h', configuration: version_conf)

50 51 52 53 54 55 56
conf = configuration_data()
conf.set_quoted('SYSTEM_CONFIG_FILE_LOCATION', join_paths(get_option('prefix'), get_option('sysconfdir'), 'mpd.conf'))

common_cppflags = [
  '-D_GNU_SOURCE',
]

57 58
test_global_common_flags = [
  '-fvisibility=hidden',
59 60 61
]

test_common_flags = [
62 63 64
  '-ffast-math',
  '-ftree-vectorize',

65
  '-Wcast-qual',
66
  '-Wdouble-promotion',
67
  '-Wmissing-declarations',
68
  '-Wshadow',
69
  '-Wunused',
70 71
  '-Wvla',
  '-Wwrite-strings',
72

73 74 75
  # clang specific warning options:
  '-Wunreachable-code-aggressive',
  '-Wused-but-marked-unused',
76 77 78

  # suppress bogus GCC12 warnings in libfmt headers
  '-Wno-stringop-overflow',
79 80
]

81 82 83 84 85 86
test_global_cxxflags = test_global_common_flags + [
]

test_global_cflags = test_global_common_flags + [
]

87 88 89 90
test_cxxflags = test_common_flags + [
  '-fno-threadsafe-statics',
  '-fmerge-all-constants',

91
  '-Wcomma-subscript',
92
  '-Wextra-semi',
93 94 95 96 97
  '-Wmismatched-tags',
  '-Woverloaded-virtual',
  '-Wsign-promo',
  '-Wvolatile',
  '-Wvirtual-inheritance',
98

99
  # a vtable without a dtor is just fine
100 101 102
  '-Wno-non-virtual-dtor',

  # clang specific warning options:
103 104 105
  '-Wcomma',
  '-Wheader-hygiene',
  '-Winconsistent-missing-destructor-override',
106
]
107

108 109 110 111
if compiler.get_id() != 'gcc' or compiler.version().version_compare('>=9')
  # The GCC 8 implementation of this flag is buggy: it complains even
  # if "final" is present, which implies "override".
  test_cxxflags += '-Wsuggest-override'
112
endif
113 114 115 116 117 118 119

test_cflags = test_common_flags + [
  '-Wmissing-prototypes',
  '-Wstrict-prototypes',
]

test_ldflags = [
120 121 122 123 124
  # make relocations read-only (hardening)
  '-Wl,-z,relro',

  # no lazy binding, please - not worth it for a daemon
  '-Wl,-z,now',
125 126 127
]

if get_option('buildtype') != 'debug'
128
  test_global_cxxflags += [
129 130 131
    '-ffunction-sections',
    '-fdata-sections',
  ]
132
  test_global_cflags += [
133 134 135 136 137 138 139 140
    '-ffunction-sections',
    '-fdata-sections',
  ]
  test_ldflags += [
    '-Wl,--gc-sections',
  ]
endif

141
if get_option('fuzzer')
142 143 144 145
  fuzzer_flags = ['-fsanitize=fuzzer']
  if get_option('b_sanitize') == 'none'
    fuzzer_flags += ['-fsanitize=address,undefined']
  endif
146 147 148 149 150
  add_global_arguments(fuzzer_flags, language: 'cpp')
  add_global_arguments(fuzzer_flags, language: 'c')
  add_global_link_arguments(fuzzer_flags, language: 'cpp')
endif

151 152 153 154 155
add_global_arguments(compiler.get_supported_arguments(test_global_cxxflags), language: 'cpp')
add_global_arguments(c_compiler.get_supported_arguments(test_global_cflags), language: 'c')
add_project_arguments(compiler.get_supported_arguments(test_cxxflags), language: 'cpp')
add_project_arguments(c_compiler.get_supported_arguments(test_cflags), language: 'c')
add_project_link_arguments(compiler.get_supported_link_arguments(test_ldflags), language: 'cpp')
156 157 158 159 160

is_linux = host_machine.system() == 'linux'
is_android = get_option('android_ndk') != ''
is_darwin = host_machine.system() == 'darwin'
is_windows = host_machine.system() == 'windows'
Zoltán Mizsei's avatar
Zoltán Mizsei committed
161
is_haiku = host_machine.system() == 'haiku'
162 163 164 165 166 167 168

if is_android
  common_cppflags += '-DANDROID'
endif

if is_windows
  common_cppflags += [
169
    # enable Windows Vista APIs
170
    '-DWINVER=0x0600', '-D_WIN32_WINNT=0x0600',
171 172 173

    # enable Unicode support (TCHAR=wchar_t) in the Windows API (macro
    # "UNICODE) and the C library (macro "_UNICODE")
174
    '-DUNICODE', '-D_UNICODE',
175 176 177 178 179 180 181

    # enable strict type checking in the Windows API headers
    '-DSTRICT',

    # reduce header bloat by disabling obscure and obsolete Windows
    # APIs
    '-DWIN32_LEAN_AND_MEAN',
182 183 184

    # disable more Windows APIs which are not used by MPD
    '-DNOGDI', '-DNOBITMAP', '-DNOCOMM',
185 186 187 188
    '-DNOUSER',

    # reduce COM header bloat
    '-DCOM_NO_WINDOWS_H',
189 190 191

    # disable Internet Explorer specific APIs
    '-D_WIN32_IE=0',
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
  ]

  subdir('win32')
endif

if is_android
  subdir('android')
endif

add_global_arguments(common_cppflags, language: 'c')
add_global_arguments(common_cppflags, language: 'cpp')

enable_daemon = not is_windows and not is_android and get_option('daemon')
conf.set('ENABLE_DAEMON', enable_daemon)

conf.set('HAVE_GETPWNAM_R', compiler.has_function('getpwnam_r'))
conf.set('HAVE_INITGROUPS', compiler.has_function('initgroups'))
conf.set('HAVE_FNMATCH', compiler.has_function('fnmatch'))
210 211 212 213 214 215 216

# Explicitly exclude Windows in this check because
# https://github.com/mesonbuild/meson/issues/3672 (reported in 2018,
# still not fixed in 2020) causes Meson to believe it exists, because
# __builtin_strndup() exists (but strndup() still cannot be used).
conf.set('HAVE_STRNDUP', not is_windows and compiler.has_function('strndup', prefix: '#define _GNU_SOURCE\n#include <string.h>'))

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
conf.set('HAVE_STRCASESTR', compiler.has_function('strcasestr'))

conf.set('HAVE_PRCTL', is_linux)

if not get_option('syslog').disabled()
  if compiler.has_function('syslog')
    conf.set('HAVE_SYSLOG', true)
  elif get_option('syslog').enabled()
    error('syslog() not found')
  endif
endif

enable_database = get_option('database')
conf.set('ENABLE_DATABASE', enable_database)

enable_inotify = get_option('inotify') and is_linux and enable_database
conf.set('ENABLE_INOTIFY', enable_inotify)

conf.set('ENABLE_DSD', get_option('dsd'))

inc = include_directories(
  'src',

  # for the generated config.h
  '.',
)

boost_dep = dependency('boost', version: '>= 1.58')
245 246 247
if boost_dep.version() == '1.67'
  # https://github.com/MusicPlayerDaemon/MPD/pull/384
  # https://github.com/boostorg/lockfree/commit/12726cda009a855073b9bedbdce57b6ce7763da2
248
  warning('Your Boost version 1.67 is known to be buggy, and the MPD build will fail. Please upgrade to Boost 1.68 or later.')
249
endif
250

251
fmt_dep = dependency('fmt', fallback: ['fmt', 'fmt_dep'])
252

253 254 255 256 257 258 259 260
if compiler.get_id() == 'clang' and compiler.version().version_compare('<15')
  fmt_dep = declare_dependency(
    dependencies: fmt_dep,
    # suppress bogus clang 14 warning (the version in Android NDK r25b)
    compile_args: ['-Wno-unused-local-typedef'],
  )
endif

261 262 263 264 265
log = static_library(
  'log',
  'src/Log.cxx',
  'src/LogBackend.cxx',
  include_directories: inc,
266
  dependencies: fmt_dep,
267 268 269 270
)

log_dep = declare_dependency(
  link_with: log,
271
  dependencies: fmt_dep,
272 273
)

274 275 276 277 278
sources = [
  version_cxx,
  'src/Main.cxx',
  'src/protocol/ArgParser.cxx',
  'src/command/CommandError.cxx',
279
  'src/command/PositionArg.cxx',
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
  'src/command/AllCommands.cxx',
  'src/command/QueueCommands.cxx',
  'src/command/TagCommands.cxx',
  'src/command/PlayerCommands.cxx',
  'src/command/PlaylistCommands.cxx',
  'src/command/FileCommands.cxx',
  'src/command/OutputCommands.cxx',
  'src/command/MessageCommands.cxx',
  'src/command/ClientCommands.cxx',
  'src/command/PartitionCommands.cxx',
  'src/command/OtherCommands.cxx',
  'src/command/CommandListBuilder.cxx',
  'src/Idle.cxx',
  'src/IdleFlags.cxx',
  'src/decoder/Thread.cxx',
  'src/decoder/Control.cxx',
  'src/decoder/Bridge.cxx',
  'src/decoder/DecoderPrint.cxx',
  'src/client/Listener.cxx',
  'src/client/Client.cxx',
300
  'src/client/Config.cxx',
301
  'src/client/Domain.cxx',
302 303 304 305 306 307 308 309 310 311 312
  'src/client/Event.cxx',
  'src/client/Expire.cxx',
  'src/client/Idle.cxx',
  'src/client/List.cxx',
  'src/client/New.cxx',
  'src/client/Process.cxx',
  'src/client/Read.cxx',
  'src/client/Write.cxx',
  'src/client/Message.cxx',
  'src/client/Subscribe.cxx',
  'src/client/File.cxx',
313
  'src/client/Response.cxx',
314
  'src/client/ThreadBackgroundCommand.cxx',
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
  'src/Listen.cxx',
  'src/LogInit.cxx',
  'src/ls.cxx',
  'src/Instance.cxx',
  'src/MusicBuffer.cxx',
  'src/MusicPipe.cxx',
  'src/MusicChunk.cxx',
  'src/MusicChunkPtr.cxx',
  'src/Mapper.cxx',
  'src/Partition.cxx',
  'src/Permission.cxx',
  'src/player/CrossFade.cxx',
  'src/player/Thread.cxx',
  'src/player/Control.cxx',
  'src/PlaylistError.cxx',
  'src/PlaylistPrint.cxx',
  'src/PlaylistSave.cxx',
  'src/playlist/PlaylistStream.cxx',
  'src/playlist/PlaylistMapper.cxx',
  'src/playlist/PlaylistAny.cxx',
  'src/playlist/PlaylistSong.cxx',
  'src/playlist/PlaylistQueue.cxx',
  'src/playlist/Print.cxx',
  'src/db/PlaylistVector.cxx',
  'src/queue/Queue.cxx',
  'src/queue/QueuePrint.cxx',
  'src/queue/QueueSave.cxx',
  'src/queue/Playlist.cxx',
  'src/queue/PlaylistControl.cxx',
  'src/queue/PlaylistEdit.cxx',
  'src/queue/PlaylistTag.cxx',
  'src/queue/PlaylistState.cxx',
  'src/ReplayGainGlobal.cxx',
  'src/LocateUri.cxx',
  'src/SongUpdate.cxx',
  'src/SongLoader.cxx',
  'src/SongPrint.cxx',
  'src/SongSave.cxx',
  'src/StateFile.cxx',
  'src/StateFileConfig.cxx',
  'src/Stats.cxx',
  'src/TagPrint.cxx',
  'src/TagSave.cxx',
  'src/TagFile.cxx',
  'src/TagStream.cxx',
360
  'src/TagAny.cxx',
361
  'src/TimePrint.cxx',
362
  'src/mixer/Memento.cxx',
363 364 365
  'src/PlaylistFile.cxx',
]

366 367 368 369 370 371
if is_windows
  sources += [
    'src/win32/Win32Main.cxx',
  ]
endif

372 373 374 375 376 377 378 379
if not is_android
  sources += [
    'src/CommandLine.cxx',
    'src/unix/SignalHandlers.cxx',
  ]
else
  sources += [
    'src/android/Context.cxx',
380
    'src/android/AudioManager.cxx',
381 382 383 384 385 386 387 388 389 390 391
    'src/android/Environment.cxx',
    'src/android/LogListener.cxx',
  ]
endif

if enable_daemon
  sources += 'src/unix/Daemon.cxx'
endif

if enable_database
  sources += [
392
    'src/storage/StorageState.cxx',
393 394 395 396 397 398 399
    'src/queue/PlaylistUpdate.cxx',
    'src/command/StorageCommands.cxx',
    'src/command/DatabaseCommands.cxx',
  ]
endif

subdir('src/util')
400
subdir('src/time')
401
subdir('src/io')
402
subdir('src/io/uring')
403 404
subdir('src/system')
subdir('src/thread')
405
subdir('src/net')
406
subdir('src/event')
407
subdir('src/win32')
408

409 410
subdir('src/apple')

411 412 413 414 415 416
subdir('src/lib/dbus')
subdir('src/lib/icu')
subdir('src/lib/smbclient')
subdir('src/lib/zlib')

subdir('src/lib/alsa')
417
subdir('src/lib/chromaprint')
418 419 420 421 422 423
subdir('src/lib/curl')
subdir('src/lib/expat')
subdir('src/lib/ffmpeg')
subdir('src/lib/gcrypt')
subdir('src/lib/nfs')
subdir('src/lib/oss')
424
subdir('src/lib/pcre')
425
subdir('src/lib/pipewire')
426 427 428 429 430 431 432
subdir('src/lib/pulse')
subdir('src/lib/sndio')
subdir('src/lib/sqlite')
subdir('src/lib/systemd')
subdir('src/lib/upnp')
subdir('src/lib/yajl')

433 434
subdir('src/lib/crypto')

435 436
subdir('src/zeroconf')

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
subdir('src/fs')
subdir('src/config')
subdir('src/tag')
subdir('src/pcm')
subdir('src/neighbor')
subdir('src/input')
subdir('src/archive')
subdir('src/filter')
subdir('src/mixer')
subdir('src/output')
subdir('src/lib/xiph')
subdir('src/decoder')
subdir('src/encoder')
subdir('src/song')
subdir('src/playlist')

if curl_dep.found()
  sources += 'src/RemoteTagCache.cxx'
endif

if sqlite_dep.found()
  sources += [
    'src/command/StickerCommands.cxx',
460 461
    'src/sticker/Database.cxx',
    'src/sticker/Print.cxx',
462 463 464 465
    'src/sticker/SongSticker.cxx',
  ]
endif

466 467 468 469 470 471 472
if chromaprint_dep.found()
  sources += [
    'src/command/FingerprintCommands.cxx',
    'src/lib/chromaprint/DecoderClient.cxx',
  ]
endif

473 474 475 476 477 478 479 480 481 482 483 484 485 486
basic = static_library(
  'basic',
  'src/ReplayGainInfo.cxx',
  'src/ReplayGainMode.cxx',
  'src/SingleMode.cxx',
  include_directories: inc,
)

basic_dep = declare_dependency(
  link_with: basic,
)

if enable_database
  subdir('src/storage')
487 488
else
  storage_glue_dep = dependency('', required: false)
489
endif
490
subdir('src/db')
491 492 493 494 495 496 497 498 499

if neighbor_glue_dep.found()
  sources += 'src/command/NeighborCommands.cxx'
endif

if archive_glue_dep.found()
  sources += [
    'src/TagArchive.cxx',
  ]
500 501 502 503

  if enable_database
    sources += ['src/db/update/Archive.cxx']
  endif
504 505 506 507 508 509 510 511 512 513 514
endif

if is_windows
  sources += windows_resources
endif

link_args = []
more_deps = []
if is_android
  subdir('src/java')
  target_type = 'shared_library'
515
  target_name = 'mpd'
516 517 518 519 520 521 522 523 524
  link_args += [
    '-Wl,--no-undefined,-shared,-Bsymbolic',
    '-llog',
    '-lz',
  ]
  more_deps += [
    declare_dependency(sources: [classes_jar]),
    java_dep,
  ]
525 526
elif is_haiku
  target_type = 'executable'
527
  target_name = 'mpd.nores'
528 529 530 531
  link_args += [
    '-lnetwork',
    '-lbe',
  ]
532 533
else
  target_type = 'executable'
534
  target_name = 'mpd'
535 536 537
endif

mpd = build_target(
538
  target_name,
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
  sources,
  target_type: target_type,
  include_directories: inc,
  dependencies: [
    basic_dep,
    config_dep,
    dbus_dep,
    fs_dep,
    net_dep,
    util_dep,
    event_dep,
    thread_dep,
    neighbor_glue_dep,
    input_glue_dep,
    archive_glue_dep,
    output_glue_dep,
    mixer_glue_dep,
    decoder_glue_dep,
    encoder_glue_dep,
    playlist_glue_dep,
    db_glue_dep,
    storage_glue_dep,
    song_dep,
    systemd_dep,
    sqlite_dep,
    zeroconf_dep,
    more_deps,
566
    chromaprint_dep,
567
    fmt_dep,
568 569
  ],
  link_args: link_args,
570
  build_by_default: not get_option('fuzzer'),
571 572 573 574 575 576 577 578 579
  install: not is_android and not is_haiku,
)

if is_android
  subdir('android/apk')
endif

if is_haiku
  subdir('src/haiku')
580 581 582 583 584 585 586 587
  custom_target(
    'mpd',
    output: 'mpd',
    input: [mpd, rsrc],
    command: [addres, '@OUTPUT@', '@INPUT0@', '@INPUT1@'],
    install: true,
    install_dir: get_option('bindir'),
  )
588 589 590 591 592 593 594 595
endif

configure_file(output: 'config.h', configuration: conf)

if systemd_dep.found()
  subdir('systemd')
endif

596 597 598 599 600
install_data(
  'mpd.svg',
  install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', 'scalable', 'apps'),
)

601 602 603 604 605
install_data(
  'AUTHORS', 'COPYING', 'NEWS', 'README.md',
  install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name()),
)

606
subdir('doc')
607 608 609 610

if get_option('test')
  subdir('test')
endif
611 612 613 614

if get_option('fuzzer')
  subdir('test/fuzzer')
endif