|
| 1 | +include(CheckCXXSourceCompiles) |
| 2 | + |
| 3 | +function(check_working_cxx_atomics64 varname) |
| 4 | + set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
| 5 | + if (EMBEDDED_CFG) |
| 6 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -m32 -march=i486") |
| 7 | + elseif(MSVC OR MSVC_VERSION) |
| 8 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -arch:IA32 -std:c++14") |
| 9 | + else() |
| 10 | + # CMAKE_CXX_STANDARD does not propagate to cmake compile tests |
| 11 | + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++14") |
| 12 | + endif() |
| 13 | + check_cxx_source_compiles(" |
| 14 | +#include <atomic> |
| 15 | +#include <cstdint> |
| 16 | +std::atomic<uint64_t> x (0); |
| 17 | +int main() { |
| 18 | + uint64_t i = x.load(std::memory_order_relaxed); |
| 19 | + return 0; |
| 20 | +} |
| 21 | +" ${varname}) |
| 22 | + set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
| 23 | +endfunction() |
| 24 | + |
| 25 | +check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB) |
| 26 | + |
| 27 | +if(HAVE_CXX_ATOMICS64_WITHOUT_LIB) |
| 28 | + message(STATUS "Have working 64bit atomics") |
| 29 | + return() |
| 30 | +endif() |
| 31 | + |
| 32 | +if (NOT MSVC AND NOT MSVC_VERSION) |
| 33 | + check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64) |
| 34 | + if (HAVE_CXX_LIBATOMICS64) |
| 35 | + message(STATUS "Have 64bit atomics via library") |
| 36 | + list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") |
| 37 | + check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB) |
| 38 | + if (HAVE_CXX_ATOMICS64_WITH_LIB) |
| 39 | + message(STATUS "Can link with libatomic") |
| 40 | + link_libraries(-latomic) |
| 41 | + return() |
| 42 | + endif() |
| 43 | + endif() |
| 44 | +endif() |
| 45 | +if (MSVC OR MSVC_VERSION) |
| 46 | + message(FATAL_ERROR "Host compiler must support 64-bit std::atomic! (What does MSVC do to inline atomics?)") |
| 47 | +else() |
| 48 | + message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") |
| 49 | +endif() |
0 commit comments