]> git.proxmox.com Git - ceph.git/blame - ceph/cmake/modules/CheckCxxAtomic.cmake
import ceph 14.2.5
[ceph.git] / ceph / cmake / modules / CheckCxxAtomic.cmake
CommitLineData
11fdf7f2
TL
1# some platforms do not offer support for atomic primitive for all integer
2# types, in that case we need to link against libatomic
3
4include(CheckCXXSourceCompiles)
5include(CMakePushCheckState)
6
7
8function(check_cxx_atomics var)
9 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
10 check_cxx_source_compiles("
11#include <atomic>
12#include <cstdint>
13int main() {
14 std::atomic<uint8_t> w1;
15 std::atomic<uint16_t> w2;
16 std::atomic<uint32_t> w4;
17 std::atomic<uint64_t> w8;
eafe8130
TL
18#ifdef __s390x__
19 // Boost needs 16-byte atomics for tagged pointers.
20 std::atomic<unsigned __int128> w16;
21#else
22 #define w16 0
23#endif
24 return w1 + w2 + w4 + w8 + w16;
11fdf7f2
TL
25}
26" ${var})
27endfunction(check_cxx_atomics)
28
29cmake_push_check_state()
30check_cxx_atomics(HAVE_CXX11_ATOMIC)
31cmake_pop_check_state()
32
33if(NOT HAVE_CXX11_ATOMIC)
34 cmake_push_check_state()
35 set(CMAKE_REQUIRED_LIBRARIES "atomic")
36 check_cxx_atomics(HAVE_LIBATOMIC)
37 cmake_pop_check_state()
38 if(HAVE_LIBATOMIC)
39 set(LIBATOMIC_LINK_FLAGS "-Wl,--as-needed -latomic")
40 else()
41 message(FATAL_ERROR
42 "Host compiler ${CMAKE_CXX_COMPILER} requires libatomic, but it is not found")
43 endif()
44endif()