# some platforms do not offer support for atomic primitive for all integer # types, in that case we need to link against libatomic include(CheckCXXSourceCompiles) include(CMakePushCheckState) function(check_cxx_atomics var) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") check_cxx_source_compiles(" #include #include int main() { std::atomic w1; std::atomic w2; std::atomic w4; std::atomic w8; return w1 + w2 + w4 + w8; } " ${var}) endfunction(check_cxx_atomics) cmake_push_check_state() check_cxx_atomics(HAVE_CXX11_ATOMIC) cmake_pop_check_state() if(NOT HAVE_CXX11_ATOMIC) cmake_push_check_state() set(CMAKE_REQUIRED_LIBRARIES "atomic") check_cxx_atomics(HAVE_LIBATOMIC) cmake_pop_check_state() if(HAVE_LIBATOMIC) set(LIBATOMIC_LINK_FLAGS "-Wl,--as-needed -latomic") else() message(FATAL_ERROR "Host compiler ${CMAKE_CXX_COMPILER} requires libatomic, but it is not found") endif() endif()