1 2CHECK_CXX_SOURCE_COMPILES(" 3#ifdef _WIN32 4#include <intrin.h> /* Workaround for PR19898. */ 5#include <windows.h> 6#endif 7int main() { 8#ifdef _WIN32 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 41CHECK_CXX_SOURCE_COMPILES(" 42#include <sys/utsname.h> 43int main() { 44 return 0; 45} 46 47" COMPILER_RT_TARGET_HAS_UNAME) 48 49add_compiler_rt_component(profile) 50 51set(PROFILE_SOURCES 52 GCDAProfiling.c 53 InstrProfiling.c 54 InstrProfilingInternal.c 55 InstrProfilingValue.c 56 InstrProfilingBuffer.c 57 InstrProfilingFile.c 58 InstrProfilingMerge.c 59 InstrProfilingMergeFile.c 60 InstrProfilingNameVar.c 61 InstrProfilingVersionVar.c 62 InstrProfilingWriter.c 63 InstrProfilingPlatformDarwin.c 64 InstrProfilingPlatformFuchsia.c 65 InstrProfilingPlatformLinux.c 66 InstrProfilingPlatformOther.c 67 InstrProfilingPlatformWindows.c 68 InstrProfilingRuntime.cpp 69 InstrProfilingUtil.c 70 ) 71 72set(PROFILE_HEADERS 73 InstrProfiling.h 74 InstrProfilingInternal.h 75 InstrProfilingPort.h 76 InstrProfilingUtil.h 77 WindowsMMap.h 78 ) 79 80if(WIN32) 81 list(APPEND PROFILE_SOURCES 82 WindowsMMap.c 83 ) 84endif() 85 86include_directories(..) 87include_directories(../../include) 88 89if(FUCHSIA OR UNIX) 90 set(EXTRA_FLAGS 91 -fPIC 92 -Wno-pedantic) 93endif() 94 95if(COMPILER_RT_TARGET_HAS_ATOMICS) 96 set(EXTRA_FLAGS 97 ${EXTRA_FLAGS} 98 -DCOMPILER_RT_HAS_ATOMICS=1) 99endif() 100 101if(COMPILER_RT_TARGET_HAS_FCNTL_LCK) 102 set(EXTRA_FLAGS 103 ${EXTRA_FLAGS} 104 -DCOMPILER_RT_HAS_FCNTL_LCK=1) 105endif() 106 107if(COMPILER_RT_TARGET_HAS_UNAME) 108 set(EXTRA_FLAGS 109 ${EXTRA_FLAGS} 110 -DCOMPILER_RT_HAS_UNAME=1) 111endif() 112 113# We don't use the C++ Standard Library here, so avoid including it by mistake. 114append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS) 115# XRay uses C++ standard library headers. 116string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 117 118# This appears to be a C-only warning banning the use of locals in aggregate 119# initializers. All other compilers accept this, though. 120# nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable 121append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS) 122 123# Disable 'nonstandard extension used: translation unit is empty'. 124append_list_if(COMPILER_RT_HAS_WD4206_FLAG /wd4206 EXTRA_FLAGS) 125 126if(APPLE) 127 add_compiler_rt_runtime(clang_rt.profile 128 STATIC 129 OS ${PROFILE_SUPPORTED_OS} 130 ARCHS ${PROFILE_SUPPORTED_ARCH} 131 CFLAGS ${EXTRA_FLAGS} 132 SOURCES ${PROFILE_SOURCES} 133 ADDITIONAL_HEADERS ${PROFILE_HEADERS} 134 PARENT_TARGET profile) 135else() 136 add_compiler_rt_runtime(clang_rt.profile 137 STATIC 138 ARCHS ${PROFILE_SUPPORTED_ARCH} 139 CFLAGS ${EXTRA_FLAGS} 140 SOURCES ${PROFILE_SOURCES} 141 ADDITIONAL_HEADERS ${PROFILE_HEADERS} 142 PARENT_TARGET profile) 143endif() 144