[flang][cuda] Adapt ExternalNameConversion to work in gpu module (#117039)
[llvm-project.git] / compiler-rt / lib / profile / CMakeLists.txt
blobac1451c8ceed18081b9a9800a3d40928ab954a8c
2 CHECK_CXX_SOURCE_COMPILES("
3 #ifdef _WIN32
4 #include <intrin.h> /* Workaround for PR19898. */
5 #include <windows.h>
6 #endif
7 int 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)
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;
34  s_flock.l_type = F_WRLCK;
35  fcntl(fd, F_SETLKW, &s_flock);
36  return 0;
39 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
41 CHECK_CXX_SOURCE_COMPILES("
42 #include <sys/file.h>
44 int fd;
45 int main() {
46   flock(fd, LOCK_EX);
47   return 0;
50 " COMPILER_RT_TARGET_HAS_FLOCK)
52 CHECK_CXX_SOURCE_COMPILES("
53 #include <sys/utsname.h>
54 int main() {
55  return 0;
58 " COMPILER_RT_TARGET_HAS_UNAME)
60 add_compiler_rt_component(profile)
62 set(PROFILE_SOURCES
63   GCDAProfiling.c
64   InstrProfiling.c
65   InstrProfilingInternal.c
66   InstrProfilingValue.c
67   InstrProfilingBuffer.c
68   InstrProfilingFile.c
69   InstrProfilingMerge.c
70   InstrProfilingMergeFile.c
71   InstrProfilingNameVar.c
72   InstrProfilingVersionVar.c
73   InstrProfilingWriter.c
74   InstrProfilingPlatformAIX.c
75   InstrProfilingPlatformDarwin.c
76   InstrProfilingPlatformFuchsia.c
77   InstrProfilingPlatformLinux.c
78   InstrProfilingPlatformOther.c
79   InstrProfilingPlatformWindows.c
80   InstrProfilingRuntime.cpp
81   InstrProfilingUtil.c
82   )
84 set(PROFILE_HEADERS
85   InstrProfiling.h
86   InstrProfilingInternal.h
87   InstrProfilingPort.h
88   InstrProfilingUtil.h
89   WindowsMMap.h
90   )
92 if(WIN32)
93   list(APPEND PROFILE_SOURCES
94     WindowsMMap.c
95   )
96 endif()
98 include_directories(..)
99 include_directories(../../include)
101 if(FUCHSIA OR UNIX)
102  set(EXTRA_FLAGS
103      -fPIC
104      -Wno-pedantic)
105 endif()
107 if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
108   set(EXTRA_FLAGS
109       ${EXTRA_FLAGS}
110       -D_WASI_EMULATED_MMAN
111       -D_WASI_EMULATED_GETPID)
112 endif()
114 if(COMPILER_RT_TARGET_HAS_ATOMICS)
115  set(EXTRA_FLAGS
116      ${EXTRA_FLAGS}
117      -DCOMPILER_RT_HAS_ATOMICS=1)
118 endif()
120 if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
121  set(EXTRA_FLAGS
122      ${EXTRA_FLAGS}
123      -DCOMPILER_RT_HAS_FCNTL_LCK=1)
124 endif()
126 if(COMPILER_RT_TARGET_HAS_FLOCK)
127   set(EXTRA_FLAGS
128       ${EXTRA_FLAGS}
129       -DCOMPILER_RT_HAS_FLOCK=1)
130 endif()
132 if(COMPILER_RT_TARGET_HAS_UNAME)
133  set(EXTRA_FLAGS
134      ${EXTRA_FLAGS}
135      -DCOMPILER_RT_HAS_UNAME=1)
136 endif()
138 if(MSVC)
139   # profile historically has only been supported with the static runtime
140   # on windows
141   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
142 endif()
144 # We don't use the C++ Standard Library here, so avoid including it by mistake.
145 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)
146 # XRay uses C++ standard library headers.
147 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
149 # This appears to be a C-only warning banning the use of locals in aggregate
150 # initializers. All other compilers accept this, though.
151 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
152 append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)
154 # Disable 'nonstandard extension used: translation unit is empty'.
155 append_list_if(COMPILER_RT_HAS_WD4206_FLAG /wd4206 EXTRA_FLAGS)
157 if(APPLE)
158   add_compiler_rt_runtime(clang_rt.profile
159     STATIC
160     OS ${PROFILE_SUPPORTED_OS}
161     ARCHS ${PROFILE_SUPPORTED_ARCH}
162     CFLAGS ${EXTRA_FLAGS}
163     SOURCES ${PROFILE_SOURCES}
164     ADDITIONAL_HEADERS ${PROFILE_HEADERS}
165     PARENT_TARGET profile
166     EXTENSIONS ON)
167 else()
168   add_compiler_rt_runtime(clang_rt.profile
169     STATIC
170     ARCHS ${PROFILE_SUPPORTED_ARCH}
171     CFLAGS ${EXTRA_FLAGS}
172     SOURCES ${PROFILE_SOURCES}
173     ADDITIONAL_HEADERS ${PROFILE_HEADERS}
174     PARENT_TARGET profile
175     EXTENSIONS ON)
176 endif()