diff --git a/lix/libutil/meson.build b/lix/libutil/meson.build index e09e471a5..433bb40db 100644 --- a/lix/libutil/meson.build +++ b/lix/libutil/meson.build @@ -306,6 +306,7 @@ libutil = library( openssl, nlohmann_json, kj, + libatomic, ], include_directories : [ '../..' ], cpp_pch : cpp_pch, @@ -343,6 +344,7 @@ liblixutil = declare_dependency( # lix-base pkg-config externally) kj, libarchive, + libatomic, ], link_with : libutil ) diff --git a/lix/nix/meson.build b/lix/nix/meson.build index 2d5d15669..ac634912b 100644 --- a/lix/nix/meson.build +++ b/lix/nix/meson.build @@ -177,6 +177,7 @@ nix = executable( boehm, nlohmann_json, kj, + libatomic, ], cpp_pch : cpp_pch, install : true, diff --git a/meson.build b/meson.build index 3265d5abc..52aa60725 100644 --- a/meson.build +++ b/meson.build @@ -378,6 +378,26 @@ if is_freebsd libprocstat = declare_dependency(link_args : [ '-lprocstat' ]) endif +libatomic_test_program = ''' +#include +int main() { + std::atomic w1; + std::atomic w2; + std::atomic w4; + std::atomic w8; + return ++w1 + ++w2 + ++w4 + ++w8; +} +''' + +libatomic = cxx.find_library('atomic', required : false) + +# Some platforms like 32-Bit PowerPC need libatomic because they're lacking 64-Bit hardware atomic instructions +# and compilers don't handle this automatically (yet). +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358 and https://clang.llvm.org/docs/Toolchain.html#atomics-library +if not cxx.links(libatomic_test_program, name : 'test if simple atomic program links') + libatomic = cxx.find_library('atomic', required : true) +endif + # # Build-time tools #