diff options
author | Emmanuel Vasilakis <mrzammler@mm.st> | 2022-04-04 14:49:41 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-04 14:49:41 +0300 |
commit | 22e5bb32ea6705c68e3760f43654dba2c4b06118 (patch) | |
tree | a25d02a8bde056fdc54b99f73f247d5bfc144bce /configure.ac | |
parent | 9c834eff9715d1347b33f9f1f8c3deaf5c162443 (diff) |
Check if libatomic can be linked (#12583)
* dont link with atomic on macos
* check if we can link with libatomic
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 9192753a6c..c488f06f54 100644 --- a/configure.ac +++ b/configure.ac @@ -1554,13 +1554,35 @@ if test "${enable_exporting_kinesis}" = "yes" -o \ enable_cxx_linker="yes" fi -# Unconditionally link with the libatomic since: -# - if atomics are not needed, the library will be unused -# - if atomics are needed, either atomics are fulfilled by the compiler builtins -# and the library is unused or the library is needed anyway. -OPTIONAL_ATOMIC_LIBS="-latomic" +# Try to unconditionally link with -latomic. If the compiler can satisfy +# all the atomic ops with builtins then, the library will be left unused. +# Otherwise, some ops will be covered by the compiler's intrinsics and some +# will be picked up by the linker from -latomic. In the later case, if +# -latomic is not available there will be a build failure, which would +# have happened either way before this change. +AC_LANG_PUSH([C++]) + +AC_MSG_CHECKING(whether we can use -latomic) +OLD_LIBS="${LIBS}" +LIBS="-latomic" +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + #include <atomic> + #include <cstdint> + std::atomic<std::int64_t> v; + int main() { + return v; + } +]])], CAN_USE_LIBATOMIC=yes, CAN_USE_LIBATOMIC=no) +LIBS="${OLD_LIBS}" +AC_MSG_RESULT($CAN_USE_LIBATOMIC) + +if test "x$CAN_USE_LIBATOMIC" = xyes; then + OPTIONAL_ATOMIC_LIBS="-latomic" +fi AC_SUBST([OPTIONAL_ATOMIC_LIBS]) +AC_LANG_POP([C++]) + AM_CONDITIONAL([ENABLE_CXX_LINKER], [test "${enable_cxx_linker}" = "yes"]) AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged]) |