Skip to content

Commit

Permalink
BLD: Bring in the atomic_dep from SciPy
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Oct 15, 2023
1 parent a42c598 commit 94f53c5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,45 @@ threads_dep = dependency('threads',
required: true)
_deps += threads_dep

# Determine whether it is necessary to link libatomic. This could be the case
# e.g. on 32-bit platforms when atomic operations are used on 64-bit types.
# The check is copied from SciPy which in turn came from
# Mesa <https://www.mesa3d.org/>.
null_dep = dependency('', required : false)
atomic_dep = null_dep
code_non_lockfree = '''
#include <stdint.h>
int main() {
struct {
uint64_t *v;
} x;
return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
(int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
}
'''
if cc.get_id() != 'msvc'
if not cc.links(
code_non_lockfree,
name : 'Check atomic builtins without -latomic'
)
atomic_dep = cc.find_library('atomic', required: false)
if atomic_dep.found()
# From SciPy
# We're not sure that with `-latomic` things will work for all compilers,
# so verify and only keep libatomic as a dependency if this works.
if not cc.links(
code_non_lockfree,
dependencies: atomic_dep,
name : 'Check atomic builtins with -latomic'
)
atomic_dep = null_dep
endif
endif
endif
endif

_deps += atomic_dep

# Optional
zlib_dep = dependency('zlib',
required: get_option('use_zlib'))
Expand Down

0 comments on commit 94f53c5

Please sign in to comment.