1project('musicpc', 'c',
2  version: '0.33',
3  meson_version: '>= 0.47',
4  default_options: [
5    'c_std=c99',
6  ],
7  license: 'GPLv2+',
8)
9
10cc = meson.get_compiler('c')
11
12conf = configuration_data()
13conf.set_quoted('PACKAGE', meson.project_name())
14conf.set_quoted('VERSION', meson.project_version())
15
16conf.set('HAVE_STRNDUP', cc.has_function('strndup', prefix: '#define _GNU_SOURCE\n#include <string.h>'))
17
18iconv = get_option('iconv')
19if iconv.disabled()
20  iconv = false
21elif cc.has_function('iconv')
22  iconv = true
23elif iconv.auto()
24  iconv = false
25else
26  error('iconv() not available')
27endif
28conf.set('HAVE_ICONV', iconv)
29
30configure_file(output: 'config.h', configuration: conf)
31
32common_cflags = [
33  # for localtime_r() with glibc
34  '-D_GNU_SOURCE',
35]
36
37test_cflags = [
38  '-Wall',
39  '-Wextra',
40  '-Wno-deprecated-declarations',
41  '-Wmissing-prototypes',
42  '-Wshadow',
43  '-Wpointer-arith',
44  '-Wstrict-prototypes',
45  '-Wcast-qual',
46  '-Wwrite-strings',
47  '-fvisibility=hidden',
48]
49
50if get_option('buildtype') != 'debug'
51  test_cflags += [
52    '-ffunction-sections',
53    '-fdata-sections',
54  ]
55
56  add_global_link_arguments(
57    cc.get_supported_link_arguments(
58      '-Wl,--gc-sections',
59      '-Wl,--icf=all',
60    ),
61    language: 'c'
62  )
63endif
64
65common_cflags += cc.get_supported_arguments(test_cflags)
66
67add_global_arguments(common_cflags, language: 'c')
68
69libmpdclient_dep = dependency('libmpdclient', version: '>= 2.9')
70
71inc = include_directories(
72  'src',
73
74  # for the generated config.h
75  '.',
76)
77
78if iconv
79  iconv_sources = files('src/charset.c')
80else
81  iconv_sources = []
82endif
83
84executable('mpc',
85  'src/main.c',
86  'src/list.c',
87  'src/password.c',
88  'src/status.c',
89  'src/args.c',
90  'src/format.c',
91  'src/song_format.c',
92  'src/tags.c',
93  'src/util.c',
94  'src/command.c',
95  'src/queue.c',
96  'src/output.c',
97  'src/sticker.c',
98  'src/tab.c',
99  'src/idle.c',
100  'src/message.c',
101  'src/mount.c',
102  'src/neighbors.c',
103  'src/search.c',
104  'src/options.c',
105  'src/path.c',
106  iconv_sources,
107  include_directories: inc,
108  dependencies: [
109    libmpdclient_dep,
110  ],
111  install: true
112)
113
114install_data('AUTHORS', 'NEWS', 'README.rst',
115  install_dir : join_paths(get_option('datadir'), 'doc', meson.project_name()))
116
117install_data(
118  'contrib/mpd-m3u-handler.sh', 'contrib/mpd-pls-handler.sh',
119  'contrib/mpc-completion.bash',
120  install_dir: join_paths(get_option('datadir'), 'examples', meson.project_name(), 'contrib'))
121
122if get_option('test')
123  check_dep = dependency('check')
124  subdir('test')
125endif
126
127with_documentation = get_option('documentation')
128if not with_documentation.disabled()
129  sphinx = find_program('sphinx-build', required: with_documentation)
130  if sphinx.found()
131    subdir('doc')
132  endif
133endif
134