GitHub CI: update list of container images
[tinc] / meson.build
1 project('tinc', 'c',
2   version: '1.1pre18',
3   license: 'GPL-2.0-or-later',
4   meson_version: '>=0.51',
5   default_options: [
6     'c_std=c11',
7     'warning_level=3',
8     'buildtype=debugoptimized',
9   ],
10 )
11
12 dir_run_state = get_option('runstatedir')
13 opt_crypto = get_option('crypto')
14 opt_curses = get_option('curses')
15 opt_debug = get_option('debug')
16 opt_docs = get_option('docs')
17 opt_harden = get_option('hardening')
18 opt_jumbograms = get_option('jumbograms')
19 opt_lz4 = get_option('lz4')
20 opt_lzo = get_option('lzo')
21 opt_miniupnpc = get_option('miniupnpc')
22 opt_readline = get_option('readline')
23 opt_sandbox = get_option('sandbox')
24 opt_static = get_option('static')
25 opt_systemd = get_option('systemd')
26 opt_tests = get_option('tests')
27 opt_tunemu = get_option('tunemu')
28 opt_uml = get_option('uml')
29 opt_vde = get_option('vde')
30 opt_zlib = get_option('zlib')
31
32 meson_version = meson.version()
33
34 cc = meson.get_compiler('c')
35 os_name = host_machine.system()
36 cpu_family = host_machine.cpu_family()
37 cc_name = cc.get_id()
38
39 python = find_program('python3', required: false)
40 if python.found()
41   if meson_version.version_compare('>=0.55')
42     python_path = python.full_path()
43   else
44     python_path = python.path()
45   endif
46 else
47   python_path = ''
48 endif
49
50 cc_defs = ['-D_GNU_SOURCE']
51 if os_name == 'sunos'
52   cc_defs += '-D__EXTENSIONS__'
53 endif
54
55 cc_flags = [cc_defs]
56 ld_flags = []
57
58 if cc_name != 'msvc'
59   cc_flags += [
60     '-Wbad-function-cast',
61     '-Wduplicated-branches',
62     '-Wduplicated-cond',
63     '-Wformat-overflow=2',
64     '-Wformat-truncation=1', # 2 prints too much noise
65     '-Wformat=2',
66     '-Wlogical-op',
67     '-Wmissing-declarations',
68     '-Wmissing-noreturn',
69     '-Wmissing-prototypes',
70     '-Wno-embedded-directive',
71     '-Wold-style-definition',
72     '-Wredundant-decls',
73     '-Wreturn-type',
74     '-Wstrict-prototypes',
75     '-Wswitch-enum',
76     '-Wtrampolines', # may require executable stack which is disabled
77     '-Wvla', # VLAs are not supported by MSVC
78     '-Wwrite-strings',
79     '-fdiagnostics-show-option',
80     '-fno-strict-overflow',
81     '-fstrict-aliasing',
82   ]
83 endif
84
85 if opt_static.auto()
86   static = os_name == 'windows'
87 else
88   static = opt_static.enabled()
89 endif
90
91 if static and cc_name != 'msvc'
92   ld_flags += '-static'
93 endif
94
95 if opt_harden
96   if cc_name == 'msvc'
97     # Most of these flags are already ON by default in the latest version of MSVC.
98     # Add anyway in case someone is building using an old toolchain.
99     cc_flags += ['/guard:cf', '/GS']
100     ld_flags += [
101       '/guard:cf',
102       '/NXCOMPAT',
103       '/DYNAMICBASE',
104       cpu_family.endswith('64') ? '/HIGHENTROPYVA' : '/SAFESEH',
105     ]
106   else
107     cc_flags += [
108       '-D_FORTIFY_SOURCE=2',
109       '-fcf-protection=full',
110       '-fstack-protector-strong',
111     ]
112     ld_flags += ['-Wl,-z,relro', '-Wl,-z,now', '-Wl,-z,noexecstack']
113     if os_name == 'windows'
114       ld_flags += ['-Wl,--dynamicbase', '-Wl,--nxcompat']
115     else
116       # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458
117       cc_flags += '-fstack-clash-protection'
118     endif
119   endif
120 endif
121
122 cc_flags = cc.get_supported_arguments(cc_flags)
123 ld_flags = cc.get_supported_link_arguments(ld_flags)
124
125 add_project_arguments(cc_flags, language: 'c')
126 add_project_link_arguments(ld_flags, language: 'c')
127
128 build_root = meson.current_build_dir()
129 src_root = meson.current_source_dir()
130
131 prefix = get_option('prefix')
132 dir_bin = prefix / get_option('bindir')
133 dir_data = prefix / get_option('datadir')
134 dir_info = prefix / get_option('infodir')
135 dir_lib = prefix / get_option('libdir')
136 dir_local_state = prefix / get_option('localstatedir')
137 dir_locale = prefix / get_option('localedir')
138 dir_man = prefix / get_option('mandir')
139 dir_sbin = prefix / get_option('sbindir')
140 dir_sysconf = prefix / get_option('sysconfdir')
141
142 if dir_run_state == ''
143   dir_run_state = dir_local_state / 'run'
144 endif
145
146 if not opt_docs.disabled()
147   subdir('doc')
148 endif
149
150 subdir('src')
151
152 if not opt_tests.disabled()
153   subdir('test')
154 endif
155
156 subdir('bash_completion.d')
157
158 if os_name == 'linux' and not opt_systemd.disabled()
159   subdir('systemd')
160 endif
161
162 if python.found()
163   run_target('reformat', command: [
164     python,
165     '@SOURCE_ROOT@/lint.py',
166     '--fix',
167   ])
168
169   run_target('lint', command: [
170     python,
171     '@SOURCE_ROOT@/lint.py',
172   ])
173 endif
174
175 if meson_version.version_compare('>=0.53')
176   summary({
177     'prefix': prefix,
178     'sandbox': cdata.has('HAVE_SANDBOX'),
179     'watchdog': cdata.has('HAVE_WATCHDOG'),
180   }, bool_yn: true, section: 'System')
181 endif