1# atomic builtins are required for threading support. 2 3INCLUDE(CheckCXXSourceCompiles) 4 5check_function_exists(__atomic_fetch_add_4 HAVE___ATOMIC_FETCH_ADD_4) 6if( NOT HAVE___ATOMIC_FETCH_ADD_4 ) 7 check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC) 8 set(HAVE_LIBATOMIC False) 9 if( HAVE_LIBATOMIC ) 10 list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") 11 endif() 12endif() 13 14CHECK_CXX_SOURCE_COMPILES(" 15#ifdef _MSC_VER 16#include <Intrin.h> /* Workaround for PR19898. */ 17#include <windows.h> 18#endif 19int main() { 20#ifdef _MSC_VER 21 volatile LONG val = 1; 22 MemoryBarrier(); 23 InterlockedCompareExchange(&val, 0, 1); 24 InterlockedIncrement(&val); 25 InterlockedDecrement(&val); 26#else 27 volatile unsigned long val = 1; 28 __sync_synchronize(); 29 __sync_val_compare_and_swap(&val, 1, 0); 30 __sync_add_and_fetch(&val, 1); 31 __sync_sub_and_fetch(&val, 1); 32#endif 33 return 0; 34 } 35" LLVM_HAS_ATOMICS) 36 37if( NOT LLVM_HAS_ATOMICS ) 38 message(STATUS "Warning: LLVM will be built thread-unsafe because atomic builtins are missing") 39endif() 40