2 CHECK_CXX_SOURCE_COMPILES("
4 #include <intrin.h> /* Workaround for PR19898. */
11 InterlockedCompareExchange(&val, 0, 1);
12 InterlockedIncrement(&val);
13 InterlockedDecrement(&val);
15 volatile unsigned long val = 1;
17 __sync_val_compare_and_swap(&val, 1, 0);
18 __sync_add_and_fetch(&val, 1);
19 __sync_sub_and_fetch(&val, 1);
23 " COMPILER_RT_TARGET_HAS_ATOMICS)
25 CHECK_CXX_SOURCE_COMPILES("
26 #if defined(__linux__)
34 s_flock.l_type = F_WRLCK;
35 fcntl(fd, F_SETLKW, &s_flock);
39 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
41 CHECK_CXX_SOURCE_COMPILES("
50 " COMPILER_RT_TARGET_HAS_FLOCK)
52 CHECK_CXX_SOURCE_COMPILES("
53 #include <sys/utsname.h>
58 " COMPILER_RT_TARGET_HAS_UNAME)
60 add_compiler_rt_component(profile)
65 InstrProfilingInternal.c
67 InstrProfilingBuffer.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
86 InstrProfilingInternal.h
93 list(APPEND PROFILE_SOURCES
98 include_directories(..)
99 include_directories(../../include)
107 if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
110 -D_WASI_EMULATED_MMAN
111 -D_WASI_EMULATED_GETPID)
114 if(COMPILER_RT_TARGET_HAS_ATOMICS)
117 -DCOMPILER_RT_HAS_ATOMICS=1)
120 if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
123 -DCOMPILER_RT_HAS_FCNTL_LCK=1)
126 if(COMPILER_RT_TARGET_HAS_FLOCK)
129 -DCOMPILER_RT_HAS_FLOCK=1)
132 if(COMPILER_RT_TARGET_HAS_UNAME)
135 -DCOMPILER_RT_HAS_UNAME=1)
139 # profile historically has only been supported with the static runtime
141 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
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)
158 add_compiler_rt_runtime(clang_rt.profile
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
168 add_compiler_rt_runtime(clang_rt.profile
170 ARCHS ${PROFILE_SUPPORTED_ARCH}
171 CFLAGS ${EXTRA_FLAGS}
172 SOURCES ${PROFILE_SOURCES}
173 ADDITIONAL_HEADERS ${PROFILE_HEADERS}
174 PARENT_TARGET profile