[gjs/libatomic] build: Link with libatomic if necessary




commit fd7614fa337be45f1d96bb651182300fd9103706
Author: Simon McVittie <smcv debian org>
Date:   Fri Oct 8 11:42:49 2021 +0100

    build: Link with libatomic if necessary
    
    The implementation of atomic operations in gcc uses atomic opcodes if
    supported, but falls back to a library implementation if necessary.
    Link that library on architectures where 64-bit atomic operations need it,
    such as Debian armel (ARMv5 EABI softfloat), mipsel and powerpc.
    
    Resolves: https://gitlab.gnome.org/GNOME/gjs/-/issues/442
    Signed-off-by: Simon McVittie <smcv debian org>

 meson.build | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index e28c4bf9..e46774cf 100644
--- a/meson.build
+++ b/meson.build
@@ -109,6 +109,8 @@ endif
 
 ### Check for required libraries ###############################################
 
+null_dep = dependency('', required : false)
+
 # Note: Notify GNOME release team when adding or updating dependencies
 glib_required_version = '>= 2.66.0'
 glib = dependency('glib-2.0', version: glib_required_version,
@@ -180,6 +182,20 @@ features.''')
     endif
 endif
 
+if cxx.links('''
+#include <atomic>
+
+int main(void)
+{
+  std::atomic_int64_t value = ATOMIC_VAR_INIT(0)
+  return value.load();
+}
+''', name: '64-bit atomics built-in')
+    libatomic = null_dep
+else
+    libatomic = cc.find_library('atomic', required: false)
+endif
+
 build_profiler = sysprof_capture.found() and not get_option('profiler').disabled()
 profiler_deps = [sysprof_capture]
 if build_profiler and not cxx.has_function('timer_settime')
@@ -458,7 +474,7 @@ module_resource_srcs = gnome.compile_resources('js-resources',
     c_name: 'js_resources')
 
 libgjs_dependencies = [glib, gobject, gthread, gio, gi, ffi, spidermonkey,
-    readline]
+    readline, libatomic]
 pkg_dependencies = [glib, gobject, gthread, gio, gi, ffi, spidermonkey]
 libraries_private = []
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]