meson: link against libatomic if required

Some platforms like 32-Bit PowerPC need linking against libatomic.
Try to compile and link a very simple snippet of code which uses atomics
and make libatomic required if it fails.

Change-Id: I6a6a696471e1d352fb161c537ba9023b97c2d31e
(cherry picked from commit 95448347ea)
This commit is contained in:
Marie Ramlow
2025-09-13 21:32:01 +02:00
parent b6d5670bcf
commit b7c2f17e91
3 changed files with 23 additions and 0 deletions
+2
View File
@@ -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
)
+1
View File
@@ -177,6 +177,7 @@ nix = executable(
boehm,
nlohmann_json,
kj,
libatomic,
],
cpp_pch : cpp_pch,
install : true,
+20
View File
@@ -378,6 +378,26 @@ if is_freebsd
libprocstat = declare_dependency(link_args : [ '-lprocstat' ])
endif
libatomic_test_program = '''
#include <atomic>
int main() {
std::atomic<uint8_t> w1;
std::atomic<uint16_t> w2;
std::atomic<uint32_t> w4;
std::atomic<uint64_t> 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
#