Fix building tinc and running tests on Solaris
[tinc] / meson.build
1 project('tinc', 'c',
2   version: run_command('./src/git_tag.sh', check: true).stdout().strip(),
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_docs = get_option('docs')
16 opt_harden = get_option('hardening')
17 opt_jumbograms = get_option('jumbograms')
18 opt_lz4 = get_option('lz4')
19 opt_lzo = get_option('lzo')
20 opt_miniupnpc = get_option('miniupnpc')
21 opt_readline = get_option('readline')
22 opt_static = get_option('static')
23 opt_systemd = get_option('systemd')
24 opt_tests = get_option('tests')
25 opt_tunemu = get_option('tunemu')
26 opt_uml = get_option('uml')
27 opt_vde = get_option('vde')
28 opt_zlib = get_option('zlib')
29
30 meson_version = meson.version()
31
32 cc = meson.get_compiler('c')
33 os_name = host_machine.system()
34 cc_name = cc.get_id()
35
36 cc_defs = ['-D_GNU_SOURCE']
37 if os_name == 'sunos'
38   cc_defs += '-D__EXTENSIONS__'
39 endif
40
41 cc_flags = [cc_defs]
42 ld_flags = []
43
44 if opt_static.auto()
45   static = os_name == 'windows'
46 else
47   static = opt_static.enabled()
48 endif
49
50 if static
51   ld_flags += '-static'
52 endif
53
54 if opt_harden
55   cc_flags += [
56     '-D_FORTIFY_SOURCE=2',
57     '-fwrapv',
58     '-fno-strict-overflow',
59     '-Wreturn-type',
60     '-Wold-style-definition',
61     '-Wmissing-declarations',
62     '-Wmissing-prototypes',
63     '-Wstrict-prototypes',
64     '-Wredundant-decls',
65     '-Wbad-function-cast',
66     '-Wwrite-strings',
67     '-fdiagnostics-show-option',
68     '-fstrict-aliasing',
69     '-Wmissing-noreturn',
70   ]
71   if cc_name == 'clang'
72     cc_flags += '-Qunused-arguments'
73   endif
74   ld_flags += ['-Wl,-z,relro', '-Wl,-z,now']
75   if os_name == 'windows'
76     ld_flags += ['-Wl,--dynamicbase', '-Wl,--nxcompat']
77   endif
78 endif
79
80 cc_flags = cc.get_supported_arguments(cc_flags)
81 ld_flags = cc.get_supported_link_arguments(ld_flags)
82
83 add_project_arguments(cc_flags, language: 'c')
84 add_project_link_arguments(ld_flags, language: 'c')
85
86 build_root = meson.current_build_dir()
87 src_root = meson.current_source_dir()
88
89 prefix = get_option('prefix')
90 dir_bin = prefix / get_option('bindir')
91 dir_data = prefix / get_option('datadir')
92 dir_info = prefix / get_option('infodir')
93 dir_lib = prefix / get_option('libdir')
94 dir_local_state = prefix / get_option('localstatedir')
95 dir_locale = prefix / get_option('localedir')
96 dir_man = prefix / get_option('mandir')
97 dir_sbin = prefix / get_option('sbindir')
98 dir_sysconf = prefix / get_option('sysconfdir')
99
100 if dir_run_state == ''
101   dir_run_state = dir_local_state / 'run'
102 endif
103
104 if not opt_docs.disabled()
105   subdir('doc')
106 endif
107
108 subdir('src')
109
110 if not opt_tests.disabled()
111   subdir('test')
112 endif
113
114 subdir('bash_completion.d')
115
116 if os_name == 'linux' and not opt_systemd.disabled()
117   subdir('systemd')
118 endif
119
120 prog_reformat = find_program('astyle', native: true, required: false)
121 if prog_reformat.found()
122   run_target('reformat', command: [
123     prog_reformat,
124     '--options=@SOURCE_ROOT@/.astylerc',
125     '@SOURCE_ROOT@/*.c', '@SOURCE_ROOT@/*.h',
126   ])
127 endif
128