1 2 CHECK_CXX_SOURCE_COMPILES(" 3 #ifdef _MSC_VER 4 #include <Intrin.h> /* Workaround for PR19898. */ 5 #include <windows.h> 6 #endif 7 int main() { 8 #ifdef _MSC_VER 9 volatile LONG val = 1; 10 MemoryBarrier(); 11 InterlockedCompareExchange(&val, 0, 1); 12 InterlockedIncrement(&val); 13 InterlockedDecrement(&val); 14 #else 15 volatile unsigned long val = 1; 16 __sync_synchronize(); 17 __sync_val_compare_and_swap(&val, 1, 0); 18 __sync_add_and_fetch(&val, 1); 19 __sync_sub_and_fetch(&val, 1); 20 #endif 21 return 0; 22 } 23 " COMPILER_RT_TARGET_HAS_ATOMICS) 24 25 add_custom_target(profile) 26 27 set(PROFILE_SOURCES 28 GCDAProfiling.c 29 InstrProfiling.c 30 InstrProfilingValue.c 31 InstrProfilingBuffer.c 32 InstrProfilingFile.c 33 InstrProfilingWriter.c 34 InstrProfilingPlatformDarwin.c 35 InstrProfilingPlatformLinux.c 36 InstrProfilingPlatformOther.c 37 InstrProfilingRuntime.cc 38 InstrProfilingUtil.c) 39 40 if(UNIX) 41 set(EXTRA_FLAGS 42 -fPIC 43 -Wno-pedantic) 44 else() 45 set(EXTRA_FLAGS 46 -fPIC) 47 endif() 48 49 if(COMPILER_RT_TARGET_HAS_ATOMICS) 50 set(EXTRA_FLAGS 51 ${EXTRA_FLAGS} 52 -DCOMPILER_RT_HAS_ATOMICS=1) 53 endif() 54 55 if(APPLE) 56 add_compiler_rt_runtime(clang_rt.profile 57 STATIC 58 OS ${PROFILE_SUPPORTED_OS} 59 ARCHS ${PROFILE_SUPPORTED_ARCH} 60 SOURCES ${PROFILE_SOURCES} 61 PARENT_TARGET profile) 62 else() 63 add_compiler_rt_runtime(clang_rt.profile 64 STATIC 65 ARCHS ${PROFILE_SUPPORTED_ARCH} 66 CFLAGS ${EXTRA_FLAGS} 67 SOURCES ${PROFILE_SOURCES} 68 PARENT_TARGET profile) 69 endif() 70 71 add_dependencies(compiler-rt profile) 72