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