forked from i3/i3status
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
264 lines (230 loc) · 6.87 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# -*- mode: meson -*-
# Style objective: be consistent with what mesonbuild.com documents/uses, and/or
# the meson book: https://meson-manual.com/
project(
'i3status',
'c',
version: '2.14',
default_options: [
'c_std=c11',
'warning_level=1', # enable all warnings (-Wall)
# TODO(https://github.com/i3/i3/issues/4087): switch to
# 'buildtype=debugoptimized',
],
# Ubuntu 18.04 (supported until 2023) has meson 0.45.
# We can revisit our minimum supported meson version
# if it turns out to be too hard to maintain.
meson_version: '>=0.45.0',
)
cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(['-Wunused-value']), language: 'c')
if meson.version().version_compare('>=0.48.0')
# https://github.com/mesonbuild/meson/issues/2166#issuecomment-629696911
meson.add_dist_script('meson/meson-dist-script')
else
message('meson <0.48.0 detected, dist tarballs will not be filtered')
endif
################################################################################
# Version handling
################################################################################
cdata = configuration_data()
version_array = meson.project_version().split('.')
cdata.set_quoted('I3STATUS_VERSION', '@VCS_TAG@')
cdata.set_quoted('SYSCONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir')))
if get_option('b_sanitize').split(',').contains('address')
cdata.set('I3STATUS_ASAN_ENABLED', 1)
endif
cdata.set('HAVE_STRNDUP', cc.has_function('strndup'))
cdata.set('HAVE_MKDIRP', cc.has_function('mkdirp'))
if get_option('pulseaudio')
cdata.set('HAS_PULSEAUDIO', 1)
endif
# Instead of generating config.h directly, make vcs_tag generate it so that
# @VCS_TAG@ is replaced.
config_h_in = configure_file(
output: 'config.h.in',
configuration: cdata,
)
config_h = declare_dependency(
sources: vcs_tag(
input: config_h_in,
output: 'config.h',
fallback: meson.project_version() + '-non-git',
)
)
################################################################################
# manpages
################################################################################
man1 = join_paths(get_option('mandir'), 'man1')
if get_option('mans')
asciidoc = find_program('asciidoc')
asciidoc_cdata = configuration_data()
asciidoc_cdata.set('PACKAGE_VERSION', meson.project_version())
asciidoc_conf = configure_file(
input: 'man/asciidoc.conf.in',
output: 'asciidoc.conf',
configuration: asciidoc_cdata,
)
xmlto = find_program('xmlto')
pod2man = find_program('pod2man')
man_inputs = [
'man/i3status.man',
]
foreach m : man_inputs
xml = custom_target(
m.underscorify()+'_asciidoc',
input: m,
output: '@[email protected]',
command: [
asciidoc,
'-d', 'manpage',
'-b', 'docbook',
'-f', asciidoc_conf,
'-o', '@OUTPUT@',
'@INPUT@',
],
)
custom_target(
m.underscorify()+'_xmlto',
input: xml,
output: '@[email protected]',
command: [
xmlto,
'man',
'-o',
'@OUTDIR@',
'@INPUT@',
],
# We should use install and install_dir instead of install_man as per:
# https://github.com/mesonbuild/meson/issues/4981#issuecomment-467084867
# https://github.com/mesonbuild/meson/issues/1550#issuecomment-370164307
install: true,
install_dir: man1,
)
endforeach
else
if run_command('[', '-f', 'man/i3status.1', ']').returncode() == 0
install_data(
[
'man/i3status.1',
],
install_dir: man1,
)
endif
endif
if meson.version().version_compare('>=0.53')
summary('build manpages (-Dmans)', get_option('mans'))
summary('build pulseaudio support (-Dpulseaudio)', get_option('pulseaudio'))
endif
# Required for e.g. struct ucred to be defined as per unix(7).
add_project_arguments('-D_GNU_SOURCE', language: 'c')
# https://mesonbuild.com/howtox.html#add-math-library-lm-portably
m_dep = cc.find_library('m', required: false)
rt_dep = cc.find_library('rt', required: false)
confuse_dep = dependency('libconfuse', method: 'pkg-config')
yajl_dep = dependency('yajl', method: 'pkg-config')
i3status_srcs = [
'i3status.c',
'src/auto_detect_format.c',
'src/first_network_device.c',
'src/format_placeholders.c',
'src/general.c',
'src/output.c',
'src/print_battery_info.c',
'src/print_cpu_temperature.c',
'src/print_cpu_usage.c',
'src/print_ddate.c',
'src/print_disk_info.c',
'src/print_eth_info.c',
'src/print_ip_addr.c',
'src/print_ipv6_addr.c',
'src/print_load.c',
'src/print_mem.c',
'src/print_path_exists.c',
'src/print_run_watch.c',
'src/print_time.c',
'src/print_volume.c',
'src/print_wireless_info.c',
'src/print_file_contents.c',
'src/process_runs.c',
]
thread_dep = dependency('threads')
i3status_deps = [
thread_dep,
m_dep,
rt_dep,
confuse_dep,
yajl_dep,
config_h,
]
if get_option('pulseaudio')
pulse_dep = dependency('libpulse', method: 'pkg-config')
i3status_deps += [pulse_dep]
i3status_srcs += ['src/pulse.c']
endif
host_os = host_machine.system()
if host_os == 'linux'
nlgenl_dep = dependency('libnl-genl-3.0', method: 'pkg-config')
alsa_dep = dependency('alsa', method: 'pkg-config')
i3status_deps += [nlgenl_dep, alsa_dep]
endif
if host_os == 'netbsd'
prop_dep = cc.find_library('prop')
i3status_deps += [prop_dep]
endif
inc = include_directories('include')
executable(
'i3status',
i3status_srcs,
install: true,
include_directories: inc,
dependencies: i3status_deps,
)
install_subdir(
'etc',
strip_directory: true,
install_dir: get_option('sysconfdir'),
)
# We cannot use configure_file for run-tests.pl.in
# because configure_file strips the backslash in e.g. \@display,
# resulting in @display, breaking our Perl code:
# https://github.com/mesonbuild/meson/issues/7165
sh = find_program('sh')
replace_dirs = [
sh, '-c', # Use bash to capture output and mark as executable
'sed -e \'s,@abs_top_builddir@,'
+ meson.current_build_dir()
+ ',g;s,@abs_top_srcdir@,'
+ meson.current_source_dir()+',g\''
# Only mark files ending in .pl as executables
+ ' "$0" > "$1" && { [ "${1##*.}" = pl ] && chmod +x "$1" || true; }',
'@INPUT0@', # $0
'@OUTPUT0@', # $1
]
run_tests = custom_target(
'run-tests',
input: ['travis/run-tests.pl.in'],
output: ['run-tests.pl'],
command: replace_dirs,
# build this target when running e.g. ninja or ninja test.
# This is required for older meson versions (< 0.46.0).
build_by_default: true,
)
perl = find_program('perl')
if meson.version().version_compare('>=0.46.0')
test(
'run-tests',
perl,
args: [run_tests],
timeout: 120, # Default of 30 seconds can cause timeouts on slower machines
)
else
# meson < 0.46.0 does not support the depends arg in test targets.
# Just hope for the best.
test(
'run-tests',
perl,
args: [run_tests],
)
message('meson < 0.46 detected, you might need to run ninja test twice')
endif