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