]>
Commit | Line | Data |
---|---|---|
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 | ||
4 | include(CheckCXXSourceCompiles) | |
5 | include(CMakePushCheckState) | |
6 | ||
7 | ||
8 | function(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> | |
13 | int 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}) | |
27 | endfunction(check_cxx_atomics) | |
28 | ||
29 | cmake_push_check_state() | |
30 | check_cxx_atomics(HAVE_CXX11_ATOMIC) | |
31 | cmake_pop_check_state() | |
32 | ||
33 | if(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() | |
44 | endif() |