llvm.org GIT mirror llvm / 7c2609a
[LLVM][MIPS] Introduce 64 bit atomic check in CheckAtomic.cmake Patch by Nitesh Jain. Summary: On some target like MIPS32 we need to explicitly link atomic library for 64 bit atomic operations. This module then can be used in LLDB (http://reviews.llvm.org/D20464) or Libcxx (http://reviews.llvm.org/D16613) for explicitly link to atomic library. Reviewers: chandlerc, beanz Differential: reviews.llvm.org/D20896 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273534 91177308-0d34-0410-b5e6-96231b3b80d8 Sagar Thakur 4 years ago
1 changed file(s) with 37 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1717 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
1818 endfunction(check_working_cxx_atomics)
1919
20 function(check_working_cxx_atomics64 varname)
21 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
22 set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
23 CHECK_CXX_SOURCE_COMPILES("
24 #include
25 #include
26 std::atomic x (0);
27 int main() {
28 uint64_t i = x.load(std::memory_order_relaxed);
29 return 0;
30 }
31 " ${varname})
32 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
33 endfunction(check_working_cxx_atomics64)
34
35
2036 # This isn't necessary on MSVC, so avoid command-line switch annoyance
2137 # by only running on GCC-like hosts.
2238 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
3450 else()
3551 message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
3652 endif()
53 endif()
54 endif()
55
56 # Check for 64 bit atomic operations.
57 if(MSVC)
58 set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
59 else()
60 check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
61 endif()
62
63 # If not, check if the library exists, and atomics work with it.
64 if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
65 check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
66 if(HAVE_CXX_LIBATOMICS64)
67 list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
68 check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
69 if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
70 message(FATAL_ERROR "Host compiler must support std::atomic!")
71 endif()
72 else()
73 message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
3774 endif()
3875 endif()
3976