]>
Commit | Line | Data |
---|---|---|
5c68e442 FM |
1 | project( |
2 | 'pdns', | |
3 | ['c', 'cpp'], | |
4 | # version: 4.7.0, # Rework this since it should call builder-support/gen-version | |
5 | # license_files: 'LICENSE', # Meson 1.1.0 | |
6 | meson_version: '>= 0.53', | |
7 | default_options: [ | |
8 | 'buildtype=debugoptimized', | |
9 | 'warning_level=2', # Move this to 3 at some point to enable -Wpedantic | |
10 | 'cpp_std=c++17', | |
11 | ], | |
12 | ) | |
13 | ||
14 | # Don't limit the number of errors when using clang. This is useful to not cut out the | |
15 | # error output when using an LSP server like clangd. | |
16 | if meson.get_compiler('cpp').get_id() == 'clang' | |
17 | add_global_arguments(['-ferror-limit=0'], language: ['c', 'cpp']) | |
18 | endif | |
19 | ||
20 | add_global_arguments(['-Wshadow', '-Wmissing-declarations', '-Wredundant-decls'], language: ['c', 'cpp']) | |
21 | ||
5ec75d25 FM |
22 | summary('Source Dir', meson.current_source_dir(), section: 'Build') |
23 | summary('Build Dir', meson.current_build_dir(), section: 'Build') | |
24 | ||
5c68e442 | 25 | cxx = meson.get_compiler('cpp') |
5ec75d25 FM |
26 | system = target_machine.system() |
27 | ||
28 | summary('System', system, section: 'System') | |
29 | summary('C++ Compiler', cxx.get_id(), section: 'System') | |
30 | summary('C++ Compiler Version', cxx.version(), section: 'System') | |
31 | summary('C++ Compiler Command', cxx.cmd_array(), section: 'System') | |
32 | summary('Linker', cxx.get_linker_id(), section: 'System') | |
33 | ||
34 | summary('Name', meson.project_name(), section: 'PowerDNS') | |
35 | summary('Version', meson.project_version(), section: 'PowerDNS') | |
36 | # summary('Source Root', meson.project_source_root(), section: 'PowerDNS') # Meson 0.56 | |
37 | # summary('Build Root', meson.project_build_root(), section: 'PowerDNS') # Meson 0.56 | |
5c68e442 FM |
38 | |
39 | # Create the configuration data object. | |
40 | conf = configuration_data() | |
41 | ||
42 | # Figure out the size of time_t ---------------------------------------------------------- | |
43 | timet_size = cxx.sizeof('time_t', prefix: '#include <sys/types.h>') | |
44 | if timet_size < 8 | |
45 | error('size of time_t is', timet_size, 'which is not large enough to fix the y2k38 bug') | |
46 | endif | |
47 | ||
5ec75d25 FM |
48 | summary('Size of time_t', timet_size, section: 'System') |
49 | ||
5c68e442 FM |
50 | # Figure out the sign of time_t ---------------------------------------------------------- |
51 | prog = ''' | |
52 | #include <sys/types.h> | |
53 | ||
54 | int main() { | |
55 | int foo[1 - 2 * !(((time_t) -1) < 0)]; | |
56 | (void)foo[0]; | |
57 | return 0; | |
58 | } | |
59 | ''' | |
60 | if cxx.compiles(prog, name: 'time_t is signed') == false | |
61 | error('time_t is unsigned, PowerDNS code relies on it being signed') | |
62 | endif | |
63 | ||
5ec75d25 FM |
64 | summary('Signed time_t', true, section: 'System', bool_yn: true) |
65 | ||
5c68e442 FM |
66 | # Find flex and bison -------------------------------------------------------------------- |
67 | flex = find_program('flex', required: true) | |
5ec75d25 FM |
68 | # summary('Flex', flex.full_path(), section: 'System') # Meson 0.55 |
69 | # summary('Flex Version', flex.version(), section: 'System') # Meson 0.62 | |
70 | ||
5c68e442 | 71 | bison = find_program('bison', required: true) |
5ec75d25 FM |
72 | # summary('Bison', bison.full_path(), section: 'System') # Meson 0.55 |
73 | # summary('Bison Version', bison.version(), section: 'System') # Meson 0.62 | |
5c68e442 FM |
74 | |
75 | # Platform stuff ------------------------------------------------------------------------- | |
5c68e442 FM |
76 | if system == 'sunos' |
77 | conf.set('NEED_POSIX_TYPEDEF', 1, description: 'POSIX typedefs need to be defined') | |
78 | conf.set('NEED_INET_NTOP_PROTO', 1, description: 'OS is so broken that it needs an additional prototype') | |
79 | deps += cxx.find_library('posix4', required: true) | |
80 | add_project_arguments(['-D_REENTRANT'], language: 'cpp') | |
81 | conf.set('HAVE_SOLARIS', 1, description: 'We are on Solaris/SunOS') | |
5ec75d25 | 82 | summary('SunOS defines', 'NEED_POSIX_TYPEDEF NEED_INET_NTOP_PROTO HAVE_SOLARIS _REENTRANT', section: 'System') |
5c68e442 FM |
83 | elif system == 'linux' |
84 | conf.set('HAVE_LINUX', 1, description: 'We are on Linux') | |
5ec75d25 | 85 | summary('Linux defines', 'HAVE_LINUX', section: 'System') |
5c68e442 FM |
86 | elif system == 'darwin' |
87 | add_project_arguments(['-D__APPLE_USE_RFC_3542', '-D_XOPEN_SOURCE', '-D_DARWIN_C_SOURCE'], language: 'cpp') | |
88 | conf.set('HAVE_DARWIN', 1, description: 'We are on Darwin/MacOS') | |
5ec75d25 | 89 | summary('Darwin/MacOS defines', '__APPLE_USE_RFC_3542 _XOPEN_SOURCE _DARWIN_C_SOURCE', section: 'System') |
5c68e442 FM |
90 | elif system == 'freebsd' |
91 | conf.set('HAVE_FREEBSD', 1, description: 'We are on FreeBSD') | |
5ec75d25 | 92 | summary('FreeBSD defines', 'HAVE_FREEBSD', section: 'System') |
5c68e442 FM |
93 | elif system == 'openbsd' |
94 | conf.set('HAVE_OPENBSD', 1, description: 'We are on OpenBSD') | |
5ec75d25 | 95 | summary('OpenBSD defines', 'HAVE_OPENBSD', section: 'System') |
5c68e442 FM |
96 | endif |
97 | ||
98 | # Atomics -------------------------------------------------------------------------------- | |
99 | dep_atomics = [] | |
100 | atomic_builtins_prog = ''' | |
101 | #include <stdint.h> | |
102 | ||
103 | int main() { | |
104 | uint64_t val = 0; | |
105 | __atomic_add_fetch(&val, 1, __ATOMIC_RELAXED); | |
106 | return 0; | |
107 | } | |
108 | ''' | |
5ec75d25 FM |
109 | need_latomic = false |
110 | if cxx.links(atomic_builtins_prog, name: '-latomic is not needed for using __atomic builtins') == false | |
5c68e442 FM |
111 | atomic = cxx.find_library('atomic', disabler: true, required: false) |
112 | if atomic.found() | |
5ec75d25 FM |
113 | if cxx.links(atomic_builtins_prog, name: '-latomic is needed for using __atomic builtins', dependencies: atomic) |
114 | need_latomic = true | |
115 | summary('Atomics Library', atomic, section: 'System') | |
5c68e442 FM |
116 | dep_atomics += atomic |
117 | else | |
118 | error('libatomic needed but could not be found') | |
119 | endif | |
120 | else | |
121 | error('libatomic needed and was found, but linking with it failed') | |
122 | endif | |
123 | endif | |
124 | ||
5ec75d25 FM |
125 | summary('Need -latomic', need_latomic, section: 'System') |
126 | ||
5c68e442 FM |
127 | # Threads -------------------------------------------------------------------------------- |
128 | dep_threads = dependency('threads') | |
5ec75d25 | 129 | summary('Threads', dep_threads.name(), section: 'System') |
5c68e442 FM |
130 | |
131 | cxx.check_header('pthread.h', dependencies: dep_threads, required: true) | |
132 | if cxx.check_header('pthread_np.h', dependencies: dep_threads, prefix: '#include <pthread.h>') | |
133 | conf.set('HAVE_PTHREAD_NP_H', 1, description: 'pthread_np.h is available') | |
5ec75d25 FM |
134 | else |
135 | summary('Have pthread_np.h', false, section: 'System') | |
5c68e442 FM |
136 | endif |
137 | ||
138 | # pthread_setname_np madness ------------------------------------------------------------- | |
139 | pthread_np_prefix = ''' | |
140 | #include <pthread.h> | |
141 | #if HAVE_PTHREAD_NP_H | |
142 | # include <pthread_np.h> | |
143 | #endif | |
144 | ''' | |
145 | ||
bf5bc43b FM |
146 | variants = [ |
147 | [ | |
148 | '2-arg pthread_setname_np', 'HAVE_PTHREAD_SETNAME_NP_2', 'pthread_setname_np takes 2 arguments (Linux/glibc, QNX, IBM)', | |
149 | '''int main() { pthread_setname_np(pthread_self(), "foo"); return 0; }''', | |
150 | ], | |
151 | [ | |
152 | '2-arg pthread_set_name_np', 'HAVE_PTHREAD_SET_NAME_NP_2', 'pthread_set_name_np takes 2 arguments and does not return void (FreeBSD, OpenBSD)', | |
153 | '''int main() { return pthread_set_name_np(pthread_self(), "foo"); }''', | |
154 | ], | |
155 | [ | |
156 | '2-arg void pthread_set_name_np', 'HAVE_PTHREAD_SET_NAME_NP_2_VOID', 'pthread_set_name_np takes 2 arguments and returns void (FreeBSD, OpenBSD)', | |
157 | '''int main() { pthread_set_name_np(pthread_self(), "foo"); return 0; }''', | |
158 | ], | |
159 | [ | |
160 | '1-arg pthread_setname_np', 'HAVE_PTHREAD_SETNAME_NP_1', 'pthread_setname_np takes 1 argument (Darwin, MacOS)', | |
161 | '''int main() { return pthread_setname_np("foo"); }''', | |
162 | ], | |
163 | [ | |
164 | '3-arg pthread_setname_np', 'HAVE_PTHREAD_SETNAME_NP_3', 'pthread_setname_np takes 3 arguments (NetBSD)', | |
165 | '''int main() { return pthread_setname_np(pthread_self(), "foo", NULL); }''', | |
166 | ], | |
167 | ] | |
168 | ||
169 | found_variant = false | |
170 | foreach variant: variants | |
171 | variant_name = variant[0] | |
172 | variant_define = variant[1] | |
173 | variant_description = variant[2] | |
174 | variant_program = variant[3] | |
175 | ||
176 | if cxx.links(pthread_np_prefix + variant_program, name: variant_name) | |
177 | found_variant = true | |
178 | conf.set(variant_define, 1, description: variant_description) | |
179 | summary('pthread_setname', variant_define + ' - ' + variant_description, section: 'System') | |
180 | break | |
181 | endif | |
182 | endforeach | |
183 | ||
184 | if not found_variant | |
5c68e442 FM |
185 | error('Could not find a suitable pthread_setname function') |
186 | endif | |
187 | ||
188 | # strerror_r ----------------------------------------------------------------------------- | |
189 | if cxx.has_header_symbol('string.h', 'strerror_r') == true | |
190 | conf.set('HAVE_DECL_STRERROR_R', 1, description: 'Whether strerror_r is declared') | |
191 | endif | |
192 | ||
5ec75d25 FM |
193 | have_strerror_r = false |
194 | strerror_r_returns_charp = false | |
195 | ||
5c68e442 | 196 | if cxx.has_function('strerror_r', prefix: '#include <string.h>') == true |
5ec75d25 | 197 | have_strerror_r = true |
5c68e442 FM |
198 | conf.set('HAVE_STRERROR_R', 1, description: 'Whether strerror_r is available') |
199 | ||
200 | if cxx.compiles(''' | |
201 | #include <string.h> | |
202 | int main () { | |
203 | char error_string[256]; | |
204 | char *ptr = strerror_r(-2, error_string, 256); | |
205 | char c = *strerror_r(-2, error_string, 256); | |
206 | return c != 0 && ptr != (void*) 0L; | |
207 | } | |
208 | ''', | |
209 | name: 'strerror_r() returns char *') | |
5ec75d25 | 210 | strerror_r_returns_charp = true |
5c68e442 FM |
211 | conf.set('STRERROR_R_CHAR_P', 1, description: 'Whether strerror_r returns char *') |
212 | endif | |
213 | endif | |
214 | ||
5ec75d25 FM |
215 | summary('Have strerror_r', have_strerror_r, section: 'System') |
216 | summary('strerror_r returns char *', strerror_r_returns_charp, section: 'System') | |
217 | ||
748b804d | 218 | # Lua ------------------------------------------------------------------------------------ |
19da4ff5 | 219 | opt_lua = get_option('lua') |
748b804d FM |
220 | dep_lua = dependency('', required: false) |
221 | ||
19da4ff5 FM |
222 | if opt_lua == 'auto' or opt_lua == 'luajit' |
223 | dep_lua = dependency('luajit', version: '>= 2.0.2', required: opt_lua == 'luajit', not_found_message: 'LuaJIT not found') | |
748b804d FM |
224 | endif |
225 | ||
19da4ff5 | 226 | if not dep_lua.found() and (opt_lua == 'auto' or opt_lua == 'lua') |
748b804d FM |
227 | variants = ['lua5.3', 'lua-5.3', 'lua53', 'lua5.2', 'lua-5.2', 'lua52', 'lua5.1', 'lua-5.1', 'lua51', 'lua'] |
228 | foreach variant: variants | |
229 | dep_lua = dependency(variant, version: '>= 5.1', required: false) | |
230 | if dep_lua.found() | |
231 | break | |
232 | endif | |
233 | endforeach | |
234 | endif | |
235 | ||
236 | if not dep_lua.found() | |
237 | error('No Lua implementation was found') | |
238 | endif | |
748b804d | 239 | conf.set('HAVE_LUA', 1, description: 'Whether we have Lua') |
5ec75d25 | 240 | summary('Lua implementation', dep_lua.name(), section: 'Configuration') |
748b804d | 241 | |
5ec75d25 | 242 | have_luahpp = false |
748b804d | 243 | if cxx.has_header('lua.hpp', dependencies: dep_lua) |
5ec75d25 | 244 | have_luahpp = true |
748b804d FM |
245 | conf.set('HAVE_LUA_HPP', 1, description: 'Whether we have lua.hpp') |
246 | endif | |
5ec75d25 | 247 | summary('Have lua.hpp', have_luahpp, bool_yn: true, section: 'Configuration') |
ff7c688a FM |
248 | |
249 | # Hardening ------------------------------------------------------------------------------ | |
250 | opt_hardening = get_option('hardening') | |
251 | ||
252 | if opt_hardening.enabled() or opt_hardening.auto() | |
253 | hardening_features = [] | |
254 | ||
255 | # PIE | |
256 | pie_prog = ''' | |
257 | #include <pthread.h> | |
258 | __thread unsigned int t_id; | |
259 | ||
260 | int main() { | |
261 | t_id = 1; | |
262 | return 0; | |
263 | } | |
264 | ''' | |
265 | ||
266 | found_variant = false | |
267 | if system == 'windows' and system == 'cygwin' | |
268 | # All code is position independent on Win32 targets. | |
269 | found_variant = true | |
270 | else | |
271 | pie_variants = [['-pie'], ['-Wl,-pie']] | |
272 | foreach variant: pie_variants | |
273 | if cxx.links(pie_prog, args: variant) | |
274 | add_global_arguments(['-fPIE'], language: ['c', 'cpp']) | |
275 | add_global_link_arguments(variant, language: ['c', 'cpp']) | |
276 | conf.set('PIE', 1, description: 'Whether we enable building a Position Independent Executable') | |
277 | found_variant = true | |
278 | break | |
279 | endif | |
280 | endforeach | |
281 | endif | |
282 | hardening_features += [[found_variant, 'Building Position Independent Executables']] | |
283 | summary('PIE', found_variant, bool_yn: true, section: 'Hardening') | |
284 | ||
285 | # Stack Protector | |
286 | support_stack_protector = false | |
287 | if cxx.has_argument('-fstack-protector') | |
288 | add_global_arguments(['-fstack-protector'], language: ['c', 'cpp']) | |
289 | support_stack_protector = true | |
290 | endif | |
291 | hardening_features += [[support_stack_protector, 'Stack Protector']] | |
292 | summary('Stack Protector', support_stack_protector, bool_yn: true, section: 'Hardening') | |
293 | ||
294 | # Stack-smashing Protection | |
295 | support_stack_smashing_protector = false | |
296 | if cxx.has_argument('--param=ssp-buffer-size=4') | |
297 | add_global_arguments(['--param=ssp-buffer-size=4'], language: ['c', 'cpp']) | |
298 | support_stack_smashing_protector = true | |
299 | endif | |
300 | hardening_features += [[support_stack_smashing_protector, 'Stack Smashing Protection']] | |
301 | summary('Stack Smashing Protection', support_stack_smashing_protector, bool_yn: true, section: 'Hardening') | |
302 | if support_stack_smashing_protector | |
303 | summary('SSP Buffer Size', 4, section: 'Hardening') | |
304 | endif | |
305 | ||
306 | # Fortify Source | |
307 | fortify_source_opt = get_option('fortify-source') | |
308 | if fortify_source_opt != 'disabled' | |
309 | fortify_source_level = 2 | |
310 | if fortify_source_opt == 'auto' | |
311 | fortify_source_level = 3 | |
312 | else | |
313 | fortify_source_level = fortify_source_opt.to_int() | |
314 | endif | |
315 | ||
316 | variants = [3, 2, 1] | |
317 | foreach variant: variants | |
318 | variant_str = variant.to_string() | |
319 | if fortify_source_level == variant | |
320 | if cxx.has_argument('-D_FORTIFY_SOURCE=' + variant_str) | |
321 | add_global_arguments(['-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=' + variant_str], language: ['c', 'cpp']) | |
322 | break | |
323 | else | |
324 | fortify_source_level = fortify_source_level - 1 | |
325 | endif | |
326 | endif | |
327 | endforeach | |
328 | ||
329 | if fortify_source_level == 0 | |
330 | fortify_source_level = 'no' | |
331 | endif | |
332 | hardening_features += [[fortify_source_level != 0, 'Source Fortification']] | |
333 | summary('Source Fortification Level', fortify_source_level, section: 'Hardening') | |
334 | endif | |
335 | ||
336 | # Read-only Global Offset Table | |
337 | ld_help = run_command(cxx, '-Wl,-help', '2>&1', check: true).stdout().strip() | |
338 | variants = ['relro', 'now'] | |
339 | found_variant = false | |
340 | foreach variant: variants | |
341 | if ld_help.contains('-z ' + variant) | |
342 | found_variant = true | |
343 | add_global_link_arguments(['-Wl,-z', '-Wl,' + variant], language: ['c', 'cpp']) | |
344 | endif | |
345 | endforeach | |
346 | hardening_features += [[found_variant, 'Read-only Global Offset Table']] | |
347 | summary('Read-only GOT', found_variant, bool_yn: true, section: 'Hardening') | |
348 | ||
349 | foreach feature: hardening_features | |
350 | available = feature[0] | |
351 | name = feature[1] | |
352 | if not available | |
353 | if opt_hardening.auto() | |
354 | warning(name + ' is not supported') | |
355 | else | |
356 | error('Failing because ' + name + ' is not supported but hardening was explicitly requested.') | |
357 | endif | |
358 | endif | |
359 | endforeach | |
360 | endif | |
361 | ||
46c1b66d FM |
362 | # Unsafe KISS RNG ------------------------------------------------------------------------ |
363 | opt_kiss_rng = get_option('kiss-rng') | |
364 | if opt_kiss_rng | |
365 | conf.set('HAVE_KISS_RNG', 1, 'Use the unsafe KISS RNG') | |
366 | endif | |
367 | summary('Unsafe KISS RNG', opt_kiss_rng, section: 'Configuration') | |
368 | ||
d84b3b57 FM |
369 | # Network Libraries ---------------------------------------------------------------------- |
370 | dep_net = [] | |
371 | variants = [ | |
372 | ['inet_aton', 'resolv'], | |
373 | ['gethostbyname', 'nsl'], | |
374 | ['socket', 'socket'], | |
375 | ['gethostent', 'nsl'], | |
376 | ] | |
377 | foreach variant: variants | |
378 | funcname = variant[0] | |
379 | libname = variant[1] | |
380 | if not cxx.has_function(funcname) | |
381 | lib = cxx.find_library(libname, required: true) | |
382 | if not cxx.has_function(funcname) | |
383 | error('Cannot find function ' + funcname) | |
384 | endif | |
385 | dep_net += lib | |
386 | summary(funcname, lib.name() + ' ' + lib.version(), bool_yn: true, section: 'Network Functions') | |
387 | else | |
388 | summary(funcname, true, bool_yn: true, section: 'Network Functions') | |
389 | endif | |
390 | endforeach | |
391 | ||
392 | variants = ['recvmmsg', 'sendmmsg', 'accept4'] | |
393 | foreach variant: variants | |
394 | define = false | |
395 | if cxx.has_function(variant) | |
396 | define = 'HAVE_' + variant.to_upper() | |
397 | conf.set(define, 1, description: 'Whether we have ' + variant) | |
398 | endif | |
399 | summary(variant, define, bool_yn: true, section: 'Network Functions') | |
400 | endforeach | |
401 | ||
402 | declared = false | |
403 | if cxx.has_header_symbol('ifaddrs.h', 'getifaddrs') | |
404 | declared = 'HAVE_GETIFADDRS' | |
405 | conf.set(declared, 1, description: 'Whether we have getifaddrs') | |
406 | endif | |
407 | summary('getifaddrs', declared, bool_yn: true, section: 'Network Functions') | |
408 | ||
3de1547c FM |
409 | # Check for the tm_gmtoff field in struct tm --------------------------------------------- |
410 | prefix = ''' | |
411 | #include <sys/types.h> | |
412 | #include <time.h> | |
413 | ''' | |
414 | has = cxx.has_member('struct tm', 'tm_gmtoff', prefix: prefix) | |
415 | if has | |
416 | conf.set('HAVE_TM_GMTOFF', 1, description: 'Whether tm_gmtoff is available') | |
417 | endif | |
418 | summary('tm_gmtoff', has, bool_yn: true, section: 'System') | |
419 | ||
2b15e7b6 FM |
420 | # Check for mmap ------------------------------------------------------------------------- |
421 | mman_h = false | |
422 | have_mmap = false | |
423 | if cxx.has_header('sys/mman.h', required: false) | |
424 | mman_h = true | |
425 | if cxx.has_function('mmap', prefix: '''#include <sys/mman.h>''') | |
426 | have_mmap = true | |
427 | conf.set('HAVE_MMAP', 1, description: 'Whether we have mmap') | |
428 | endif | |
429 | endif | |
430 | summary('sys/mman.h', mman_h, bool_yn: true, section: 'System') | |
431 | summary('Have mmap', have_mmap, bool_yn: true, section: 'System') | |
432 | ||
43c13768 FM |
433 | # libsodium signers ---------------------------------------------------------------------- |
434 | opt_libsodium = get_option('libsodium') | |
435 | dep_libsodium = dependency('libsodium', required: opt_libsodium, not_found_message: 'libsodium not found') | |
436 | if dep_libsodium.found() | |
437 | conf.set('HAVE_LIBSODIUM', 1, description: 'Whether we build libsodium-based signers') | |
438 | funcs = ['crypto_box_easy_afternm', 'crypto_box_curve25519xchacha20poly1305_easy', 'randombytes_stir', 'sodium_memcmp', 'crypto_shorthash'] | |
439 | foreach func: funcs | |
440 | define = false | |
441 | if cxx.has_function(func, dependencies: dep_libsodium) | |
442 | define = 'HAVE_' + func.to_upper() | |
443 | conf.set(define, 1, description: 'Whether we have ' + func) | |
444 | endif | |
445 | summary(func, define, bool_yn: true, section: 'Libsodium Functions') | |
446 | endforeach | |
447 | endif | |
448 | summary('libsodium', dep_libsodium.found(), bool_yn: true, section: 'Configuration') | |
449 | ||
c9ec95b6 FM |
450 | # libdecaf signers ----------------------------------------------------------------------- |
451 | opt_libdecaf = get_option('libdecaf') | |
452 | dep_libdecaf = [] | |
453 | if not opt_libdecaf.disabled() | |
454 | dep_libdecaf = dependency('libdecaf', required: false) | |
455 | if not dep_libdecaf.found() | |
456 | dep_libdecaf = cxx.find_library('decaf', dirs: ['/usr', '/usr/local'], required: opt_libdecaf) | |
457 | endif | |
458 | ||
459 | found_header = false | |
460 | if dep_libdecaf.found() | |
461 | include_dirs = ['/usr/include', '/usr/local/include'] | |
462 | headers = ['decaf.hxx', 'decaf/decaf.hxx'] | |
463 | do_break = false | |
464 | foreach dirname: include_dirs | |
465 | dir = include_directories(dirname, is_system: true) | |
466 | foreach header: headers | |
467 | message(dirname / header) | |
468 | if cxx.has_header(header, dependencies: dep_libdecaf, required: false, include_directories: dir) | |
469 | conf.set('HAVE_LIBDECAF', 1, description: 'Whether we build libdecaf-based signers') | |
470 | found_header = '-I' + dirname / header | |
471 | add_global_arguments([found_header], language: ['c', 'cpp']) | |
472 | do_break = true | |
473 | break | |
474 | endif | |
475 | endforeach | |
476 | ||
477 | if do_break | |
478 | break | |
479 | endif | |
480 | endforeach | |
481 | endif | |
482 | ||
483 | show_colors = dep_libdecaf.found() or not opt_libdecaf.auto() | |
484 | summary('libdecaf', dep_libdecaf.found(), bool_yn: show_colors, section: 'Configuration') | |
485 | summary('libdecaf headers', found_header, bool_yn: show_colors, section: 'Configuration') | |
486 | endif | |
487 | ||
e79e8538 FM |
488 | # libcrypto ------------------------------------------------------------------------------ |
489 | opt_libcrypto = get_option('libcrypto') | |
490 | dep_libcrypto = [] | |
491 | ssldirs = [] | |
492 | found = false | |
493 | if opt_libcrypto == '' | |
494 | error('Invalid value for libcrypto option, either use `auto` or a directory where the library can be found') | |
495 | endif | |
496 | if opt_libcrypto == 'auto' | |
497 | dep_libcrypto = dependency('libcrypto', required: false) | |
498 | found = dep_libcrypto.found() | |
499 | else | |
500 | ssldirs = [opt_libcrypto] | |
501 | endif | |
502 | ||
503 | libdir = '' | |
504 | if not found | |
505 | warning('Could not find the libcrypto dependency, going to try to find it manually') | |
506 | if ssldirs.length() == 0 | |
507 | ssldirs = ['/usr/local/ssl', '/usr/lib/ssl', '/usr/ssl', '/usr/pkg', '/usr/local', '/usr'] | |
508 | endif | |
509 | ||
510 | foreach dir: ssldirs | |
511 | if cxx.has_header(dir / 'include/openssl/crypto.h') | |
512 | libdir = dir | |
513 | found = true | |
514 | break | |
515 | endif | |
516 | endforeach | |
517 | endif | |
518 | ||
519 | if not found | |
520 | error('Cannot find libcrypto') | |
521 | endif | |
522 | ||
523 | args = [] | |
524 | deps = [] | |
525 | incs = [] | |
526 | if libdir == '' | |
527 | deps += dep_libcrypto | |
528 | else | |
529 | args = ['-L' + libdir / 'lib', '-lcrypto'] | |
530 | incs = include_directories(libdir / 'include', is_system: false) | |
531 | endif | |
532 | ||
533 | prog = ''' | |
534 | #include <openssl/bn.h> | |
535 | ||
536 | int main() { | |
537 | BN_new(); | |
538 | return 0; | |
539 | } | |
540 | ''' | |
541 | if not cxx.links(prog, name: 'libcrypto test program', args: args, dependencies: deps, include_directories: incs) | |
542 | error('Cannot link against libcrypto') | |
543 | endif | |
544 | ||
545 | funcs = ['RAND_bytes', 'RAND_pseudo_bytes', 'CRYPTO_memcmp', 'OPENSSL_init_crypto', 'EVP_MD_CTX_new', 'EVP_MD_CTX_free', 'RSA_get0_key'] | |
546 | foreach func: funcs | |
547 | if not cxx.has_function(func, args: args, dependencies: deps, include_directories: incs) | |
548 | error('libcrypto function ' + func + ' could not be found') | |
549 | endif | |
550 | endforeach | |
551 | ||
552 | prefix = ''' | |
553 | #include <stdarg.h> | |
554 | #include <stddef.h> | |
555 | ''' | |
556 | if cxx.has_header_symbol('openssl/kdf.h', 'EVP_PKEY_CTX_set1_scrypt_salt', args: args, dependencies: deps, include_directories: incs, prefix: prefix, required: true) | |
557 | conf.set('HAVE_EVP_PKEY_CTX_SET1_SCRYPT_SALT', 1, description: 'Whether we have EVP_PKEY_CTX_set1_scrypt_salt') | |
558 | endif | |
559 | ||
560 | if libdir != '' | |
561 | add_global_arguments(args + ['-I' + libdir / 'include']) | |
562 | endif | |
563 | ||
564 | conf.set('HAVE_LIBCRYPTO', 1, description: 'Whether we build libcrypto-based signers') | |
565 | summary('libcrypto', found, bool_yn: true, section: 'Configuration') | |
566 | ||
5c68e442 FM |
567 | # Generate config.h ---------------------------------------------------------------------- |
568 | config_h = configure_file(configuration: conf, output: 'config.h') | |
5ec75d25 | 569 | # summary('Defines', conf.keys(), section: 'Build Configuration') # Meson 0.57 |
5c68e442 FM |
570 | |
571 | # Create the dependencies list ----------------------------------------------------------- | |
d84b3b57 | 572 | deps = [] |
5c68e442 FM |
573 | deps += dep_atomics |
574 | deps += dep_threads | |
748b804d | 575 | deps += dep_lua |
d84b3b57 | 576 | deps += dep_net |
43c13768 | 577 | deps += dep_libsodium |
c9ec95b6 | 578 | deps += dep_libdecaf |
e79e8538 | 579 | deps += dep_libcrypto |
5c68e442 FM |
580 | |
581 | # TODO: Other source files | |
582 | auth = executable('pdns', config_h, dependencies: deps, export_dynamic: true) | |
583 | ||
584 | # # Generate bindlexer.c and bindparser.cc. | |
585 | # bindlexer_c = generator(flex, | |
586 | # bindparser_cc = generator(bison, |