1# Some versions of gcc/libstdc++ require linking with -latomic if
2# using the C++ atomic library.
3
4# Copyright (c) 2015-2016 Tim Kosse <tim.kosse@filezilla-project.org>
5
6# Copying and distribution of this file, with or without modification, are
7# permitted in any medium without royalty provided the copyright notice
8# and this notice are preserved. This file is offered as-is, without any
9# warranty.
10
11m4_define([_CHECK_ATOMIC_testbody], [[
12  #include <atomic>
13  #include <cstdint>
14
15  int main() {
16    std::atomic<int64_t> a{};
17
18    int64_t v = 5;
19    int64_t r = a.fetch_add(v);
20    return static_cast<int>(r);
21  }
22]])
23
24AC_DEFUN([CHECK_ATOMIC], [
25
26  AC_LANG_PUSH(C++)
27
28  AC_MSG_CHECKING([whether std::atomic can be used without link library])
29
30  AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
31      AC_MSG_RESULT([yes])
32    ],[
33      AC_MSG_RESULT([no])
34      LIBS="$LIBS -latomic"
35      AC_MSG_CHECKING([whether std::atomic needs -latomic])
36      AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
37          AC_MSG_RESULT([yes])
38        ],[
39          AC_MSG_RESULT([no])
40          AC_MSG_FAILURE([cannot figure out how to use std::atomic])
41        ])
42    ])
43
44  AC_LANG_POP
45])
46