|
| 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 | +CHECK_CXX_SOURCE_COMPILES(" |
| 26 | +#if defined(__linux__) |
| 27 | +#include <unistd.h> |
| 28 | +#endif |
| 29 | +#include <fcntl.h> |
| 30 | +int fd; |
| 31 | +int 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 | + |
| 41 | +CHECK_CXX_SOURCE_COMPILES(" |
| 42 | +#include <sys/utsname.h> |
| 43 | +int main() { |
| 44 | + return 0; |
| 45 | +} |
| 46 | +
|
| 47 | +" COMPILER_RT_TARGET_HAS_UNAME) |
| 48 | + |
| 49 | +add_compiler_rt_component(profile) |
| 50 | + |
| 51 | +set(PROFILE_SOURCES |
| 52 | + GCDAProfiling.c |
| 53 | + InstrProfiling.c |
| 54 | + InstrProfilingValue.c |
| 55 | + InstrProfilingBuffer.c |
| 56 | + InstrProfilingFile.c |
| 57 | + InstrProfilingMerge.c |
| 58 | + InstrProfilingMergeFile.c |
| 59 | + InstrProfilingNameVar.c |
| 60 | + InstrProfilingWriter.c |
| 61 | + InstrProfilingPlatformDarwin.c |
| 62 | + InstrProfilingPlatformFuchsia.c |
| 63 | + InstrProfilingPlatformLinux.c |
| 64 | + InstrProfilingPlatformOther.c |
| 65 | + InstrProfilingPlatformWindows.c |
| 66 | + InstrProfilingRuntime.cc |
| 67 | + InstrProfilingUtil.c) |
| 68 | + |
| 69 | +set(PROFILE_HEADERS |
| 70 | + InstrProfData.inc |
| 71 | + InstrProfiling.h |
| 72 | + InstrProfilingInternal.h |
| 73 | + InstrProfilingPort.h |
| 74 | + InstrProfilingUtil.h |
| 75 | + WindowsMMap.h) |
| 76 | + |
| 77 | +if(WIN32) |
| 78 | + list(APPEND PROFILE_SOURCES WindowsMMap.c) |
| 79 | +endif() |
| 80 | + |
| 81 | +if(FUCHSIA OR UNIX) |
| 82 | + set(EXTRA_FLAGS |
| 83 | + -fPIC |
| 84 | + -Wno-pedantic) |
| 85 | +endif() |
| 86 | + |
| 87 | +if(COMPILER_RT_TARGET_HAS_ATOMICS) |
| 88 | + set(EXTRA_FLAGS |
| 89 | + ${EXTRA_FLAGS} |
| 90 | + -DCOMPILER_RT_HAS_ATOMICS=1) |
| 91 | +endif() |
| 92 | + |
| 93 | +if(COMPILER_RT_TARGET_HAS_FCNTL_LCK) |
| 94 | + set(EXTRA_FLAGS |
| 95 | + ${EXTRA_FLAGS} |
| 96 | + -DCOMPILER_RT_HAS_FCNTL_LCK=1) |
| 97 | +endif() |
| 98 | + |
| 99 | +if(COMPILER_RT_TARGET_HAS_UNAME) |
| 100 | + set(EXTRA_FLAGS |
| 101 | + ${EXTRA_FLAGS} |
| 102 | + -DCOMPILER_RT_HAS_UNAME=1) |
| 103 | +endif() |
| 104 | + |
| 105 | +# This appears to be a C-only warning banning the use of locals in aggregate |
| 106 | +# initializers. All other compilers accept this, though. |
| 107 | +# nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable |
| 108 | +append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS) |
| 109 | + |
| 110 | +if(APPLE) |
| 111 | + add_compiler_rt_runtime(clang_rt.profile |
| 112 | + STATIC |
| 113 | + OS ${PROFILE_SUPPORTED_OS} |
| 114 | + ARCHS ${PROFILE_SUPPORTED_ARCH} |
| 115 | + CFLAGS ${EXTRA_FLAGS} |
| 116 | + SOURCES ${PROFILE_SOURCES} |
| 117 | + ADDITIONAL_HEADERS ${PROFILE_HEADERS} |
| 118 | + PARENT_TARGET profile) |
| 119 | +else() |
| 120 | + add_compiler_rt_runtime(clang_rt.profile |
| 121 | + STATIC |
| 122 | + ARCHS ${PROFILE_SUPPORTED_ARCH} |
| 123 | + CFLAGS ${EXTRA_FLAGS} |
| 124 | + SOURCES ${PROFILE_SOURCES} |
| 125 | + ADDITIONAL_HEADERS ${PROFILE_HEADERS} |
| 126 | + PARENT_TARGET profile) |
| 127 | +endif() |
0 commit comments