1 2CHECK_CXX_SOURCE_COMPILES(" 3#ifdef _MSC_VER 4#include <Intrin.h> /* Workaround for PR19898. */ 5#include <windows.h> 6#endif 7int 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 25CHECK_CXX_SOURCE_COMPILES(" 26#if defined(__linux__) 27#include <unistd.h> 28#endif 29#include <fcntl.h> 30int fd; 31int main() { 32 struct flock s_flock; 33 34 s_flock.l_type = F_WRLCK; 35 fcntl(fd, F_SETLKW, &s_flock); 36 return 0; 37} 38 39" COMPILER_RT_TARGET_HAS_FCNTL_LCK) 40 41add_custom_target(profile) 42set_target_properties(profile PROPERTIES FOLDER "Compiler-RT Misc") 43 44set(PROFILE_SOURCES 45 GCDAProfiling.c 46 InstrProfiling.c 47 InstrProfilingValue.c 48 InstrProfilingBuffer.c 49 InstrProfilingFile.c 50 InstrProfilingMerge.c 51 InstrProfilingMergeFile.c 52 InstrProfilingWriter.c 53 InstrProfilingPlatformDarwin.c 54 InstrProfilingPlatformLinux.c 55 InstrProfilingPlatformOther.c 56 InstrProfilingRuntime.cc 57 InstrProfilingUtil.c) 58 59if(WIN32) 60 list(APPEND PROFILE_SOURCES WindowsMMap.c) 61endif() 62 63if(UNIX) 64 set(EXTRA_FLAGS 65 -fPIC 66 -Wno-pedantic) 67endif() 68 69if(COMPILER_RT_TARGET_HAS_ATOMICS) 70 set(EXTRA_FLAGS 71 ${EXTRA_FLAGS} 72 -DCOMPILER_RT_HAS_ATOMICS=1) 73endif() 74 75if(COMPILER_RT_TARGET_HAS_FCNTL_LCK) 76 set(EXTRA_FLAGS 77 ${EXTRA_FLAGS} 78 -DCOMPILER_RT_HAS_FCNTL_LCK=1) 79endif() 80 81# This appears to be a C-only warning banning the use of locals in aggregate 82# initializers. All other compilers accept this, though. 83# nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable 84append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS) 85 86if(APPLE) 87 add_compiler_rt_runtime(clang_rt.profile 88 STATIC 89 OS ${PROFILE_SUPPORTED_OS} 90 ARCHS ${PROFILE_SUPPORTED_ARCH} 91 CFLAGS ${EXTRA_FLAGS} 92 SOURCES ${PROFILE_SOURCES} 93 PARENT_TARGET profile) 94else() 95 add_compiler_rt_runtime(clang_rt.profile 96 STATIC 97 ARCHS ${PROFILE_SUPPORTED_ARCH} 98 CFLAGS ${EXTRA_FLAGS} 99 SOURCES ${PROFILE_SOURCES} 100 PARENT_TARGET profile) 101endif() 102 103add_dependencies(compiler-rt profile) 104