-
Notifications
You must be signed in to change notification settings - Fork 10
/
meson.build
202 lines (161 loc) · 5.67 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
project('ip2unix', 'cpp',
default_options: ['cpp_std=c++17', 'warning_level=3'],
meson_version: '>=0.47.0', version: '2.2.1')
script_generrno = files('scripts/generrno.py')
script_genoffsets = files('scripts/genoffsets.py')
script_gensyms = files('scripts/gensyms.py')
cc = meson.get_compiler('cpp')
std_fs_check = cc.run('''
#include <filesystem>
int main(void) {
return std::filesystem::absolute("foo") != "foo" ? 0 : 1;
}
''', name: 'std::filesystem works')
if std_fs_check.returncode() != 0
error('C++17 Filesystem library not working correctly,' +
' please update your compiler toolchain.')
endif
if get_option('b_lto')
error('Link-time optimisation is not supported,' +
' please build with b_lto set to false (-Db_lto=false)')
endif
warning_flags = [
'-Wcast-qual',
'-Wcovered-switch-default',
'-Weffc++',
'-Wextra-semi',
'-Wimplicit-fallthrough',
'-Wno-trigraphs',
'-Wold-style-cast',
'-Wrange-loop-analysis',
'-Wreserved-id-macro',
'-Wshadow',
'-Wsign-conversion',
'-Wswitch-enum',
'-Wunused-exception-parameter',
'-Wuseless-cast',
'-Wzero-as-null-pointer-constant',
]
add_project_arguments(cc.get_supported_arguments(warning_flags),
language: 'cpp')
python = import('python').find_installation('python3')
cflags = ['-DVERSION="' + meson.project_version() + '"']
cflags += ['-fPIC']
main_cflags = []
lib_cflags = []
lib_ldflags = []
deps = [
dependency('yaml-cpp', version: '>=0.5.0'),
cc.find_library('dl')
]
systemd_enabled = get_option('systemd-support')
if systemd_enabled
cflags += ['-DSYSTEMD_SUPPORT']
endif
abstract_enabled = get_option('abstract-support') \
and host_machine.system() == 'linux'
if abstract_enabled
cflags += ['-DABSTRACT_SUPPORT']
endif
if cc.has_header_symbol('sys/epoll.h', 'epoll_ctl')
cflags += ['-DHAS_EPOLL']
endif
lib_sources = []
main_sources = []
includes = []
subdir('src')
gen_extra_args = cc.cmd_array() + lib_cflags + cflags + ['--', '@INPUT@']
gen_sym_map = [python, script_gensyms, '--map']
sym_map = custom_target('symmap', input: lib_sources, output: 'symbols.map',
command: gen_sym_map + gen_extra_args, capture: true)
gen_ldscript = [python, script_gensyms, '--ldscript']
ldscript = custom_target('ldscript', input: lib_sources, output: 'ldscript',
command: gen_ldscript + gen_extra_args, capture: true)
lib_ldflags += [
'-Wl,--version-script,@0@'.format(sym_map.full_path()),
ldscript.full_path()
]
man_input = files('README.adoc')
adoc_attrs = [
'-a', 'manmanual=IP2Unix Manual',
'-a', 'mansource=IP2Unix',
'-a', 'revnumber=@0@'.format(meson.project_version()),
]
if not systemd_enabled
adoc_attrs += ['-a', 'without-systemd']
endif
if not abstract_enabled
adoc_attrs += ['-a', 'without-abstract']
endif
################################## MANPAGE ##################################
mandest = join_paths(get_option('prefix'), get_option('mandir'), 'man1')
build_manpage = false
a2x = find_program(['a2x', 'a2x.py'], required: false)
if a2x.found()
build_manpage = true
a2xcmd = [a2x, '-d', 'manpage', '-f', 'manpage', '-D', '@OUTDIR@']
docbook_xsl = 'http://docbook.sourceforge.net/release/xsl/current/'
docbook_xsl += 'manpages/docbook.xsl'
docbook_dtd = 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd'
xsltproc = find_program('xsltproc', required: false)
if xsltproc.found()
xslt_test = run_command([xsltproc, docbook_xsl], check: false)
if xslt_test.returncode() != 0
warning('No Docbook XSL stylesheet found, not generating manpage.')
build_manpage = false
endif
else
build_manpage = false
warning('No \'xsltproc\' found, not generating manpage.')
endif
xmllint = find_program('xmllint', required: false)
if xmllint.found()
lintcmd = [xmllint, '--nonet', '--dtdvalid', docbook_dtd, '--auto']
if run_command(lintcmd, check: false).returncode() != 3
a2xcmd += ['-L']
warning('No Docbook 4.5 DTD found, disabling validation.')
endif
else
a2xcmd += ['-L']
warning('No \'xmllint\' found, disabling validation of AsciiDoc output.')
endif
if build_manpage
custom_target('ip2unix-man',
command: a2xcmd + adoc_attrs + ['@INPUT@'],
input: man_input,
output: 'ip2unix.1',
install: true,
install_dir: mandest)
endif
endif
if not build_manpage
asciidoctor = find_program('asciidoctor', required: false)
if asciidoctor.found()
adcmd = [asciidoctor, '-b', 'manpage', '-d', 'manpage']
adoc_attrs += ['-a', 'reproducible']
custom_target('ip2unix-man',
command: adcmd + adoc_attrs + ['-o', '@OUTPUT0@', '@INPUT@'],
input: man_input,
output: 'ip2unix.1',
install: true,
install_dir: mandest)
build_manpage = true
endif
endif
if build_manpage
cflags += ['-DWITH_MANPAGE']
else
warning('Neither AsciiDoc nor Asciidoctor found, not generating manpage.')
endif
############################### BUILD TARGETS ###############################
libip2unix = shared_library('ip2unix', lib_sources, install: true,
dependencies: deps,
link_depends: [sym_map, ldscript],
cpp_args: lib_cflags + cflags,
link_args: lib_ldflags,
include_directories: includes)
ip2unix = executable('ip2unix', main_sources, install: true,
link_with: libip2unix,
dependencies: deps, include_directories: includes,
cpp_args: main_cflags + cflags)
subdir('tests')