175 lines · plain
1 2CHECK_CXX_SOURCE_COMPILES("3#ifdef _WIN324#include <intrin.h> /* Workaround for PR19898. */5#include <windows.h>6#endif7int main() {8#ifdef _WIN329 volatile LONG val = 1;10 MemoryBarrier();11 InterlockedCompareExchange(&val, 0, 1);12 InterlockedIncrement(&val);13 InterlockedDecrement(&val);14#else15 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#endif21 return 0;22 }23" COMPILER_RT_TARGET_HAS_ATOMICS)24 25CHECK_CXX_SOURCE_COMPILES("26#if defined(__linux__)27#include <unistd.h>28#endif29#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/file.h>43 44int fd;45int main() {46 flock(fd, LOCK_EX);47 return 0;48}49 50" COMPILER_RT_TARGET_HAS_FLOCK)51 52CHECK_CXX_SOURCE_COMPILES("53#include <sys/utsname.h>54int main() {55 return 0;56}57 58" COMPILER_RT_TARGET_HAS_UNAME)59 60add_compiler_rt_component(profile)61 62set(PROFILE_SOURCES63 GCDAProfiling.c64 InstrProfiling.c65 InstrProfilingInternal.c66 InstrProfilingValue.c67 InstrProfilingBuffer.c68 InstrProfilingFile.c69 InstrProfilingMerge.c70 InstrProfilingMergeFile.c71 InstrProfilingNameVar.c72 InstrProfilingVersionVar.c73 InstrProfilingWriter.c74 InstrProfilingPlatformAIX.c75 InstrProfilingPlatformDarwin.c76 InstrProfilingPlatformFuchsia.c77 InstrProfilingPlatformLinux.c78 InstrProfilingPlatformOther.c79 InstrProfilingPlatformWindows.c80 InstrProfilingRuntime.cpp81 InstrProfilingUtil.c82 )83 84set(PROFILE_HEADERS85 InstrProfiling.h86 InstrProfilingInternal.h87 InstrProfilingPort.h88 InstrProfilingUtil.h89 WindowsMMap.h90 )91 92if(WIN32)93 list(APPEND PROFILE_SOURCES94 WindowsMMap.c95 )96endif()97 98include_directories(..)99include_directories(../../include)100 101if(FUCHSIA OR UNIX)102 set(EXTRA_FLAGS103 -fPIC104 -Wno-pedantic)105endif()106 107if(CMAKE_SYSTEM_NAME STREQUAL "WASI")108 set(EXTRA_FLAGS109 ${EXTRA_FLAGS}110 -D_WASI_EMULATED_MMAN111 -D_WASI_EMULATED_GETPID)112endif()113 114if(COMPILER_RT_TARGET_HAS_ATOMICS)115 set(EXTRA_FLAGS116 ${EXTRA_FLAGS}117 -DCOMPILER_RT_HAS_ATOMICS=1)118endif()119 120if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)121 set(EXTRA_FLAGS122 ${EXTRA_FLAGS}123 -DCOMPILER_RT_HAS_FCNTL_LCK=1)124endif()125 126if(COMPILER_RT_TARGET_HAS_FLOCK)127 set(EXTRA_FLAGS128 ${EXTRA_FLAGS}129 -DCOMPILER_RT_HAS_FLOCK=1)130endif()131 132if(COMPILER_RT_TARGET_HAS_UNAME)133 set(EXTRA_FLAGS134 ${EXTRA_FLAGS}135 -DCOMPILER_RT_HAS_UNAME=1)136endif()137 138if(MSVC)139 # profile historically has only been supported with the static runtime140 # on windows141 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)142endif()143 144# We don't use the C++ Standard Library here, so avoid including it by mistake.145append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)146# XRay uses C++ standard library headers.147string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")148 149# This appears to be a C-only warning banning the use of locals in aggregate150# initializers. All other compilers accept this, though.151# nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable152append_list_if(COMPILER_RT_HAS_WD4221_FLAG /wd4221 EXTRA_FLAGS)153 154# Disable 'nonstandard extension used: translation unit is empty'.155append_list_if(COMPILER_RT_HAS_WD4206_FLAG /wd4206 EXTRA_FLAGS)156 157if(APPLE)158 add_compiler_rt_runtime(clang_rt.profile159 STATIC160 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)166else()167 add_compiler_rt_runtime(clang_rt.profile168 STATIC169 ARCHS ${PROFILE_SUPPORTED_ARCH}170 CFLAGS ${EXTRA_FLAGS}171 SOURCES ${PROFILE_SOURCES}172 ADDITIONAL_HEADERS ${PROFILE_HEADERS}173 PARENT_TARGET profile)174endif()175