meson: Support execinfo.h on FreeBSD by using -lexecinfo
authorTing-Wei Lan <lantw@src.gnome.org>
Mon, 14 Nov 2016 19:03:22 +0000 (03:03 +0800)
committerTim-Philipp Müller <tim@centricular.com>
Fri, 25 Nov 2016 19:28:04 +0000 (19:28 +0000)
FreeBSD supports execinfo.h and backtrace* functions, but
using them requires linking with -lexecinfo.

Requires sufficiently-new meson with #1053 fixed (post-0.36).

https://bugzilla.gnome.org/show_bug.cgi?id=774424

meson.build

index 57182c5..70576a8 100644 (file)
@@ -257,6 +257,12 @@ if cc.has_function('strsignal', prefix : '#include <string.h>')
   cdata.set('HAVE_DECL_STRSIGNAL', 1)
 endif
 
+# Platform deps; only ws2_32 and execinfo for now
+platform_deps = []
+if host_machine.system() == 'windows'
+  platform_deps = [cc.find_library('ws2_32')]
+endif
+
 unwind_dep = dependency('libunwind', required : false)
 dw_dep = dependency('libdw', required: false)
 if unwind_dep.found()
@@ -274,8 +280,16 @@ else
   endif
 endif
 
-if cc.has_header('execinfo.h') and cc.has_function('backtrace', prefix : '#include <execinfo.h>')
-  cdata.set('HAVE_BACKTRACE', 1)
+if cc.has_header('execinfo.h')
+  if cc.has_function('backtrace', prefix : '#include <execinfo.h>')
+    cdata.set('HAVE_BACKTRACE', 1)
+  else
+    execinfo_dep = cc.find_library('execinfo', required : false)
+    if execinfo_dep.found() and cc.has_function('backtrace', prefix : '#include <execinfo.h>', dependencies : execinfo_dep)
+      cdata.set('HAVE_BACKTRACE', 1)
+      platform_deps += execinfo_dep
+    endif
+  endif
 endif
 
 configure_file(input : 'config.h.meson',
@@ -300,12 +314,6 @@ endif
 mathlib = cc.find_library('m', required : false)
 rt_lib = cc.find_library('rt', required : false) # clock_gettime
 
-# Platform deps; only ws2_32 for now
-platform_deps = []
-if host_machine.system() == 'windows'
-  platform_deps = [cc.find_library('ws2_32')]
-endif
-
 gir = find_program('g-ir-scanner', required : false)
 gnome = import('gnome')