]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/lib/profile/CMakeLists.txt
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / profile / CMakeLists.txt
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 InstrProfilingPlatformLinux.c
63 InstrProfilingPlatformOther.c
64 InstrProfilingRuntime.cc
65 InstrProfilingUtil.c)
66
67 if(WIN32)
68 list(APPEND PROFILE_SOURCES WindowsMMap.c)
69 endif()
70
71 if(UNIX)
72 set(EXTRA_FLAGS
73 -fPIC
74 -Wno-pedantic)
75 endif()
76
77 if(COMPILER_RT_TARGET_HAS_ATOMICS)
78 set(EXTRA_FLAGS
79 ${EXTRA_FLAGS}
80 -DCOMPILER_RT_HAS_ATOMICS=1)
81 endif()
82
83 if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
84 set(EXTRA_FLAGS
85 ${EXTRA_FLAGS}
86 -DCOMPILER_RT_HAS_FCNTL_LCK=1)
87 endif()
88
89 if(COMPILER_RT_TARGET_HAS_UNAME)
90 set(EXTRA_FLAGS
91 ${EXTRA_FLAGS}
92 -DCOMPILER_RT_HAS_UNAME=1)
93 endif()
94
95 # This appears to be a C-only warning banning the use of locals in aggregate
96 # initializers. All other compilers accept this, though.
97 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
98 append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)
99
100 if(APPLE)
101 add_compiler_rt_runtime(clang_rt.profile
102 STATIC
103 OS ${PROFILE_SUPPORTED_OS}
104 ARCHS ${PROFILE_SUPPORTED_ARCH}
105 CFLAGS ${EXTRA_FLAGS}
106 SOURCES ${PROFILE_SOURCES}
107 PARENT_TARGET profile)
108 else()
109 add_compiler_rt_runtime(clang_rt.profile
110 STATIC
111 ARCHS ${PROFILE_SUPPORTED_ARCH}
112 CFLAGS ${EXTRA_FLAGS}
113 SOURCES ${PROFILE_SOURCES}
114 PARENT_TARGET profile)
115 endif()