Skip to content

Commit 231ab94

Browse files
authored
Merge 484f5bb into ae5d0a6
2 parents ae5d0a6 + 484f5bb commit 231ab94

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

docs/markdown/Dependencies.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,16 @@ dep = dependency('appleframeworks', modules : 'foundation')
315315

316316
These dependencies can never be found for non-OSX hosts.
317317

318+
## atomic (stdatomic)
319+
320+
*(added 1.1.0)*
321+
322+
Provides access to the atomic operations library. On systems where
323+
this is not provided by compiler-rt (i.e. gcc), this tries to find
324+
an external library instead.
325+
326+
`method` may be `auto`, `builtin` or `system`.
327+
318328
## Blocks
319329

320330
Enable support for Clang's blocks extension.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## New custom dependency for atomic
2+
3+
```
4+
dependency('atomic')
5+
```
6+
7+
checks for the availability of the atomic operation library. First, it checks
8+
if stdatomic is provided by compiler-rt (e.g. when using clang). If not, it
9+
looks for the atomic library specifically.

mesonbuild/dependencies/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
BlocksDependency, OpenMPDependency, cups_factory, curses_factory, gpgme_factory,
3737
libgcrypt_factory, libwmf_factory, netcdf_factory, pcap_factory,
3838
shaderc_factory, threads_factory, ThreadDependency, iconv_factory, intl_factory,
39-
dl_factory, openssl_factory, libcrypto_factory, libssl_factory,
39+
atomic_factory, dl_factory, openssl_factory, libcrypto_factory, libssl_factory,
4040
)
4141
from .platform import AppleFrameworks
4242
from .python import python_factory as python3_factory
@@ -260,6 +260,7 @@ def __init__(self, name: str, environment: 'Environment', kwargs: T.Dict[str, T.
260260
'shaderc': shaderc_factory,
261261
'iconv': iconv_factory,
262262
'intl': intl_factory,
263+
'atomic': atomic_factory,
263264
'dl': dl_factory,
264265
'openssl': openssl_factory,
265266
'libcrypto': libcrypto_factory,

mesonbuild/dependencies/misc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ def netcdf_factory(env: 'Environment',
5858
return candidates
5959

6060

61+
class AtomicBuiltinDependency(BuiltinDependency):
62+
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
63+
super().__init__(name, env, kwargs)
64+
self.feature_since = ('1.1.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
65+
66+
if self.clib_compiler.has_function('atomic_flag_clear', '#include <stdatomic.h>', env)[0]:
67+
self.is_found = True
68+
69+
70+
class AtomicSystemDependency(SystemDependency):
71+
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
72+
super().__init__(name, env, kwargs)
73+
self.feature_since = ('1.1.0', "consider checking for `atomic_flag_clear` with and without `find_library('atomic')`")
74+
75+
h = self.clib_compiler.has_header('stdatomic.h', '', env)
76+
self.link_args = self.clib_compiler.find_library('atomic', env, [], self.libtype)
77+
78+
if h[0] and self.link_args:
79+
self.is_found = True
80+
81+
6182
class DlBuiltinDependency(BuiltinDependency):
6283
def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
6384
super().__init__(name, env, kwargs)
@@ -526,6 +547,13 @@ def shaderc_factory(env: 'Environment',
526547
return candidates
527548

528549

550+
atomic_factory = DependencyFactory(
551+
'atomic',
552+
[DependencyMethods.BUILTIN, DependencyMethods.SYSTEM],
553+
builtin_class=AtomicBuiltinDependency,
554+
system_class=AtomicSystemDependency,
555+
)
556+
529557
cups_factory = DependencyFactory(
530558
'cups',
531559
[DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.EXTRAFRAMEWORK, DependencyMethods.CMAKE],

0 commit comments

Comments
 (0)