llvm.org GIT mirror llvm / cc73f10
Repair cmake libatomic check. The cmake check for whether libatomic could be used had been unconditionally setting the result to false. Which was somewhat fortunate, because the prerequisite check for whether it was *needed* was always claiming it was, even if it was not. However, this made platforms where libatomic is actually necessary fail to link. Differential Revision: http://reviews.llvm.org/D10453 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239819 91177308-0d34-0410-b5e6-96231b3b80d8 James Y Knight 4 years ago
1 changed file(s) with 36 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
11
22 INCLUDE(CheckCXXSourceCompiles)
33
4 check_function_exists(__atomic_fetch_add_4 HAVE___ATOMIC_FETCH_ADD_4)
5 if( NOT HAVE___ATOMIC_FETCH_ADD_4 )
6 check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
7 set(HAVE_LIBATOMIC False)
8 if( HAVE_LIBATOMIC )
9 list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
4 # Sometimes linking against libatomic is required for atomic ops, if
5 # the platform doesn't support lock-free atomics.
6
7 function(check_working_cxx_atomics varname)
8 set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
9 set(CMAKE_REQUIRED_FLAGS "-std=c++11")
10 CHECK_CXX_SOURCE_COMPILES("
11 #include
12 std::atomic x;
13 int main() {
14 return x;
15 }
16 " ${varname})
17 set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
18 endfunction(check_working_cxx_atomics)
19
20 # This isn't necessary on MSVC, so avoid command-line switch annoyance
21 # by only running on GCC-like hosts.
22 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
23 # First check if atomics work without the library.
24 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
25 # If not, check if the library exists, and atomics work with it.
26 if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
27 check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
28 if( HAVE_LIBATOMIC )
29 list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
30 check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
31 if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
32 message(FATAL_ERROR "Host compiler must support std::atomic!")
33 endif()
34 else()
35 message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
36 endif()
1037 endif()
1138 endif()
1239
40 ## TODO: This define is only used for the legacy atomic operations in
41 ## llvm's Atomic.h, which should be replaced. Other code simply
42 ## assumes C++11 works.
1343 CHECK_CXX_SOURCE_COMPILES("
1444 #ifdef _MSC_VER
1545 #include /* Workaround for PR19898. */