Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 1 | include(CMakePushCheckState) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 2 | include(CheckCXXCompilerFlag) |
Alexey Samsonov | d964e7c | 2014-03-04 13:28:21 +0000 | [diff] [blame] | 3 | include(CheckLibraryExists) |
Alexey Samsonov | e3e2a11 | 2014-02-27 06:52:41 +0000 | [diff] [blame] | 4 | include(CheckSymbolExists) |
Alexey Samsonov | 54a0e40 | 2015-02-10 01:42:44 +0000 | [diff] [blame] | 5 | include(TestBigEndian) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 6 | |
Evgeniy Stepanov | 9196090 | 2015-05-05 20:13:39 +0000 | [diff] [blame] | 7 | function(check_linker_flag flag out_var) |
| 8 | cmake_push_check_state() |
| 9 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") |
| 10 | check_cxx_compiler_flag("" ${out_var}) |
| 11 | cmake_pop_check_state() |
| 12 | endfunction() |
| 13 | |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 14 | # CodeGen options. |
| 15 | check_cxx_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) |
Alexey Samsonov | 878a9a5 | 2014-02-18 08:07:09 +0000 | [diff] [blame] | 16 | check_cxx_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 17 | check_cxx_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG) |
| 18 | check_cxx_compiler_flag(-fno-exceptions COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG) |
| 19 | check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG) |
| 20 | check_cxx_compiler_flag(-funwind-tables COMPILER_RT_HAS_FUNWIND_TABLES_FLAG) |
| 21 | check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG) |
Peter Collingbourne | b64d0b1 | 2015-06-15 21:08:47 +0000 | [diff] [blame] | 22 | check_cxx_compiler_flag(-fno-sanitize=safe-stack COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 23 | check_cxx_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG) |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 24 | check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG) |
Alexey Samsonov | 878a9a5 | 2014-02-18 08:07:09 +0000 | [diff] [blame] | 25 | check_cxx_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 26 | check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG) |
Alexey Samsonov | bcce197 | 2014-03-18 12:49:22 +0000 | [diff] [blame] | 27 | check_cxx_compiler_flag(-std=c++11 COMPILER_RT_HAS_STD_CXX11_FLAG) |
Alexey Samsonov | 56b6ee9 | 2014-04-01 13:16:30 +0000 | [diff] [blame] | 28 | check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC) |
Rafael Espindola | 0dfd240 | 2014-12-31 18:20:52 +0000 | [diff] [blame] | 29 | check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) |
Alexey Samsonov | c91ffd2 | 2015-02-02 20:37:25 +0000 | [diff] [blame] | 30 | check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 31 | |
Alexey Samsonov | b73db72 | 2014-02-18 07:52:40 +0000 | [diff] [blame] | 32 | check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 33 | check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG) |
| 34 | check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG) |
| 35 | check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG) |
| 36 | |
| 37 | # Debug info flags. |
| 38 | check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG) |
| 39 | check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG) |
| 40 | check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG) |
Alexey Samsonov | c91ffd2 | 2015-02-02 20:37:25 +0000 | [diff] [blame] | 41 | |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 42 | # Warnings. |
Alexey Samsonov | 4a7e96e | 2014-03-06 12:25:02 +0000 | [diff] [blame] | 43 | check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG) |
Alexey Samsonov | a2fee5d | 2014-02-24 11:32:49 +0000 | [diff] [blame] | 44 | check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 45 | check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG) |
| 46 | check_cxx_compiler_flag("-Werror -Wglobal-constructors" COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG) |
Alexey Samsonov | 829da45 | 2014-11-13 21:19:53 +0000 | [diff] [blame] | 47 | check_cxx_compiler_flag("-Werror -Wc99-extensions" COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG) |
| 48 | check_cxx_compiler_flag("-Werror -Wgnu" COMPILER_RT_HAS_WGNU_FLAG) |
| 49 | check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG) |
| 50 | check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 51 | |
Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame] | 52 | check_cxx_compiler_flag(/W3 COMPILER_RT_HAS_W3_FLAG) |
Alexey Samsonov | a2fee5d | 2014-02-24 11:32:49 +0000 | [diff] [blame] | 53 | check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG) |
Aaron Ballman | 1d1f232 | 2014-10-23 20:39:58 +0000 | [diff] [blame] | 54 | check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG) |
| 55 | check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG) |
Timur Iskhodzhanov | 4703047 | 2014-08-26 12:33:00 +0000 | [diff] [blame] | 56 | check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG) |
Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 57 | check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG) |
Aaron Ballman | 1d1f232 | 2014-10-23 20:39:58 +0000 | [diff] [blame] | 58 | check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG) |
Alexey Samsonov | e3e2a11 | 2014-02-27 06:52:41 +0000 | [diff] [blame] | 59 | |
| 60 | # Symbols. |
| 61 | check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) |
Alexey Samsonov | d964e7c | 2014-03-04 13:28:21 +0000 | [diff] [blame] | 62 | |
| 63 | # Libraries. |
Timur Iskhodzhanov | f2d2447 | 2014-08-22 12:26:34 +0000 | [diff] [blame] | 64 | check_library_exists(c printf "" COMPILER_RT_HAS_LIBC) |
Alexey Samsonov | d964e7c | 2014-03-04 13:28:21 +0000 | [diff] [blame] | 65 | check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL) |
Evgeniy Stepanov | 8e9c70b | 2015-05-29 22:31:28 +0000 | [diff] [blame] | 66 | check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT) |
Timur Iskhodzhanov | f2d2447 | 2014-08-22 12:26:34 +0000 | [diff] [blame] | 67 | check_library_exists(m pow "" COMPILER_RT_HAS_LIBM) |
Alexey Samsonov | d964e7c | 2014-03-04 13:28:21 +0000 | [diff] [blame] | 68 | check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD) |
Timur Iskhodzhanov | f2d2447 | 2014-08-22 12:26:34 +0000 | [diff] [blame] | 69 | check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 70 | |
Evgeniy Stepanov | 9196090 | 2015-05-05 20:13:39 +0000 | [diff] [blame] | 71 | # Linker flags. |
| 72 | if(ANDROID) |
| 73 | check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) |
Evgeniy Stepanov | 7fb865e | 2015-07-24 19:00:16 +0000 | [diff] [blame] | 74 | check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG) |
Evgeniy Stepanov | 9196090 | 2015-05-05 20:13:39 +0000 | [diff] [blame] | 75 | endif() |
| 76 | |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 77 | # Architectures. |
| 78 | |
| 79 | # List of all architectures we can target. |
| 80 | set(COMPILER_RT_SUPPORTED_ARCH) |
| 81 | |
| 82 | # Try to compile a very simple source file to ensure we can target the given |
| 83 | # platform. We use the results of these tests to build only the various target |
| 84 | # runtime libraries supported by our current compilers cross-compiling |
| 85 | # abilities. |
| 86 | set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc) |
| 87 | file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n") |
| 88 | |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 89 | function(check_compile_definition def argstring out_var) |
| 90 | if("${def}" STREQUAL "") |
| 91 | set(${out_var} TRUE PARENT_SCOPE) |
| 92 | return() |
| 93 | endif() |
| 94 | cmake_push_check_state() |
| 95 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}") |
| 96 | check_symbol_exists(${def} "" ${out_var}) |
| 97 | cmake_pop_check_state() |
| 98 | endfunction() |
| 99 | |
| 100 | # test_target_arch(<arch> <def> <target flags...>) |
| 101 | # Checks if architecture is supported: runs host compiler with provided |
| 102 | # flags to verify that: |
| 103 | # 1) <def> is defined (if non-empty) |
| 104 | # 2) simple file can be successfully built. |
| 105 | # If successful, saves target flags for this architecture. |
| 106 | macro(test_target_arch arch def) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 107 | set(TARGET_${arch}_CFLAGS ${ARGN}) |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 108 | set(argstring "") |
Alexey Samsonov | 6d2022b | 2014-08-20 17:12:58 +0000 | [diff] [blame] | 109 | foreach(arg ${ARGN}) |
| 110 | set(argstring "${argstring} ${arg}") |
| 111 | endforeach() |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 112 | check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF) |
| 113 | if(NOT HAS_${arch}_DEF) |
| 114 | set(CAN_TARGET_${arch} FALSE) |
| 115 | else() |
| 116 | set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}") |
| 117 | try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE} |
| 118 | COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}" |
| 119 | OUTPUT_VARIABLE TARGET_${arch}_OUTPUT |
| 120 | CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}") |
| 121 | endif() |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 122 | if(${CAN_TARGET_${arch}}) |
| 123 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
Alexey Samsonov | 0d0200d | 2015-09-08 22:48:35 +0000 | [diff] [blame] | 124 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND |
| 125 | COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 126 | # Bail out if we cannot target the architecture we plan to test. |
| 127 | message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") |
| 128 | endif() |
| 129 | endmacro() |
| 130 | |
Evgeniy Stepanov | 9e922e7 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 131 | # Add $arch as supported with no additional flags. |
| 132 | macro(add_default_target_arch arch) |
| 133 | set(TARGET_${arch}_CFLAGS "") |
| 134 | set(CAN_TARGET_${arch} 1) |
| 135 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 136 | endmacro() |
| 137 | |
| 138 | macro(detect_target_arch) |
| 139 | check_symbol_exists(__arm__ "" __ARM) |
| 140 | check_symbol_exists(__aarch64__ "" __AARCH64) |
| 141 | check_symbol_exists(__x86_64__ "" __X86_64) |
Evgeniy Stepanov | 0f7ab59 | 2014-10-01 12:55:06 +0000 | [diff] [blame] | 142 | check_symbol_exists(__i686__ "" __I686) |
Evgeniy Stepanov | 9e922e7 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 143 | check_symbol_exists(__i386__ "" __I386) |
| 144 | check_symbol_exists(__mips__ "" __MIPS) |
| 145 | check_symbol_exists(__mips64__ "" __MIPS64) |
| 146 | if(__ARM) |
| 147 | add_default_target_arch(arm) |
| 148 | elseif(__AARCH64) |
| 149 | add_default_target_arch(aarch64) |
| 150 | elseif(__X86_64) |
| 151 | add_default_target_arch(x86_64) |
Evgeniy Stepanov | 0f7ab59 | 2014-10-01 12:55:06 +0000 | [diff] [blame] | 152 | elseif(__I686) |
| 153 | add_default_target_arch(i686) |
Evgeniy Stepanov | 9e922e7 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 154 | elseif(__I386) |
| 155 | add_default_target_arch(i386) |
| 156 | elseif(__MIPS64) # must be checked before __MIPS |
| 157 | add_default_target_arch(mips64) |
| 158 | elseif(__MIPS) |
| 159 | add_default_target_arch(mips) |
| 160 | endif() |
| 161 | endmacro() |
| 162 | |
Alexey Samsonov | 807f1b5 | 2015-01-29 21:32:34 +0000 | [diff] [blame] | 163 | # Detect whether the current target platform is 32-bit or 64-bit, and setup |
| 164 | # the correct commandline flags needed to attempt to target 32-bit and 64-bit. |
| 165 | if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND |
| 166 | NOT CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 167 | message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.") |
| 168 | endif() |
| 169 | |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 170 | # Generate the COMPILER_RT_SUPPORTED_ARCH list. |
| 171 | if(ANDROID) |
Alexey Samsonov | 0d0200d | 2015-09-08 22:48:35 +0000 | [diff] [blame] | 172 | # Examine compiler output to determine target architecture. |
Evgeniy Stepanov | 9e922e7 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 173 | detect_target_arch() |
| 174 | set(COMPILER_RT_OS_SUFFIX "-android") |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 175 | elseif(NOT APPLE) # Supported archs for Apple platforms are generated later |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 176 | if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64") |
Alexey Samsonov | 807f1b5 | 2015-01-29 21:32:34 +0000 | [diff] [blame] | 177 | if(NOT MSVC) |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 178 | test_target_arch(x86_64 "" "-m64") |
Alexey Samsonov | 655bd02 | 2015-02-27 00:07:04 +0000 | [diff] [blame] | 179 | # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may |
| 180 | # target different variant than "$CMAKE_C_COMPILER -m32". This part should |
| 181 | # be gone after we resolve PR14109. |
Nico Weber | e099213 | 2015-07-30 03:41:05 +0000 | [diff] [blame] | 182 | test_target_arch(i686 __i686__ "-m32") |
Alexey Samsonov | 655bd02 | 2015-02-27 00:07:04 +0000 | [diff] [blame] | 183 | test_target_arch(i386 __i386__ "-m32") |
Alexey Samsonov | 807f1b5 | 2015-01-29 21:32:34 +0000 | [diff] [blame] | 184 | else() |
Peter Collingbourne | d3b9917 | 2015-07-02 01:44:34 +0000 | [diff] [blame] | 185 | if (CMAKE_SIZEOF_VOID_P EQUAL 4) |
| 186 | test_target_arch(i386 "" "") |
| 187 | else() |
| 188 | test_target_arch(x86_64 "" "") |
| 189 | endif() |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 190 | endif() |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 191 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc") |
Alexey Samsonov | 54a0e40 | 2015-02-10 01:42:44 +0000 | [diff] [blame] | 192 | TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN) |
| 193 | if(HOST_IS_BIG_ENDIAN) |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 194 | test_target_arch(powerpc64 "" "-m64") |
Alexey Samsonov | 54a0e40 | 2015-02-10 01:42:44 +0000 | [diff] [blame] | 195 | else() |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 196 | test_target_arch(powerpc64le "" "-m64") |
Alexey Samsonov | 54a0e40 | 2015-02-10 01:42:44 +0000 | [diff] [blame] | 197 | endif() |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 198 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el") |
Daniel Sanders | ffa272e | 2015-04-20 12:44:01 +0000 | [diff] [blame] | 199 | # Gcc doesn't accept -m32/-m64 so we do the next best thing and use |
| 200 | # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match |
| 201 | # clang's default CPU's. In the 64-bit case, we must also specify the ABI |
| 202 | # since the default ABI differs between gcc and clang. |
| 203 | # FIXME: Ideally, we would build the N32 library too. |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 204 | test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu") |
Vasileios Kalintiris | 0943a95 | 2015-10-06 09:02:38 +0000 | [diff] [blame] | 205 | test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64") |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 206 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips") |
| 207 | test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu") |
Vasileios Kalintiris | 0943a95 | 2015-10-06 09:02:38 +0000 | [diff] [blame] | 208 | test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64") |
Alexey Samsonov | 0d0200d | 2015-09-08 22:48:35 +0000 | [diff] [blame] | 209 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm") |
Saleem Abdulrasool | f88e4fa | 2015-09-26 04:40:45 +0000 | [diff] [blame] | 210 | test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft") |
| 211 | test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard") |
Alexey Samsonov | 0d0200d | 2015-09-08 22:48:35 +0000 | [diff] [blame] | 212 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32") |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 213 | test_target_arch(aarch32 "" "-march=armv8-a") |
Alexey Samsonov | 0d0200d | 2015-09-08 22:48:35 +0000 | [diff] [blame] | 214 | elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64") |
Alexey Samsonov | 819045c | 2015-02-25 23:07:32 +0000 | [diff] [blame] | 215 | test_target_arch(aarch64 "" "-march=armv8-a") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 216 | endif() |
Evgeniy Stepanov | 9e922e7 | 2014-09-29 13:18:55 +0000 | [diff] [blame] | 217 | set(COMPILER_RT_OS_SUFFIX "") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 218 | endif() |
| 219 | |
| 220 | # Takes ${ARGN} and puts only supported architectures in @out_var list. |
| 221 | function(filter_available_targets out_var) |
Evgeniy Stepanov | abb966d | 2015-07-22 23:31:50 +0000 | [diff] [blame] | 222 | set(archs ${${out_var}}) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 223 | foreach(arch ${ARGN}) |
| 224 | list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) |
| 225 | if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch}) |
| 226 | list(APPEND archs ${arch}) |
| 227 | endif() |
| 228 | endforeach() |
| 229 | set(${out_var} ${archs} PARENT_SCOPE) |
| 230 | endfunction() |
| 231 | |
Sagar Thakur | 3ee5bd9 | 2015-05-19 09:07:37 +0000 | [diff] [blame] | 232 | # Returns a list of architecture specific target cflags in @out_var list. |
Alexey Samsonov | 807f1b5 | 2015-01-29 21:32:34 +0000 | [diff] [blame] | 233 | function(get_target_flags_for_arch arch out_var) |
| 234 | list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) |
| 235 | if(ARCH_INDEX EQUAL -1) |
| 236 | message(FATAL_ERROR "Unsupported architecture: ${arch}") |
| 237 | else() |
Chris Bieneman | 5eae197 | 2015-08-20 17:32:06 +0000 | [diff] [blame] | 238 | if (NOT APPLE) |
| 239 | set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE) |
| 240 | else() |
| 241 | # This is only called in constructing cflags for tests executing on the |
| 242 | # host. This will need to all be cleaned up to support building tests |
| 243 | # for cross-targeted hardware (i.e. iOS). |
| 244 | set(${out_var} -arch ${arch} PARENT_SCOPE) |
| 245 | endif() |
Alexey Samsonov | 807f1b5 | 2015-01-29 21:32:34 +0000 | [diff] [blame] | 246 | endif() |
| 247 | endfunction() |
| 248 | |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 249 | set(ARM64 aarch64) |
Saleem Abdulrasool | 96c5023 | 2015-09-26 03:26:01 +0000 | [diff] [blame] | 250 | set(ARM32 arm armhf) |
Vasileios Kalintiris | 22db068 | 2015-09-24 16:45:58 +0000 | [diff] [blame] | 251 | set(X86 i386 i686) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 252 | set(X86_64 x86_64) |
Vasileios Kalintiris | 22db068 | 2015-09-24 16:45:58 +0000 | [diff] [blame] | 253 | set(MIPS32 mips mipsel) |
| 254 | set(MIPS64 mips64 mips64el) |
| 255 | set(PPC64 powerpc64 powerpc64le) |
| 256 | |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 257 | if(APPLE) |
| 258 | set(ARM64 arm64) |
| 259 | set(ARM32 armv7 armv7s) |
| 260 | set(X86_64 x86_64 x86_64h) |
| 261 | endif() |
| 262 | |
Vasileios Kalintiris | 0943a95 | 2015-10-06 09:02:38 +0000 | [diff] [blame] | 263 | set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} |
| 264 | ${MIPS32} ${MIPS64}) |
Vasileios Kalintiris | 22db068 | 2015-09-24 16:45:58 +0000 | [diff] [blame] | 265 | set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} |
| 266 | ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}) |
| 267 | set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} |
| 268 | ${MIPS32} ${MIPS64} ${PPC64}) |
| 269 | set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) |
Evgeniy Stepanov | 4376156 | 2015-10-08 20:08:30 +0000 | [diff] [blame] | 270 | set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64}) |
Vasileios Kalintiris | 22db068 | 2015-09-24 16:45:58 +0000 | [diff] [blame] | 271 | set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) |
| 272 | set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64} |
| 273 | ${MIPS32} ${MIPS64}) |
| 274 | set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) |
| 275 | set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} |
| 276 | ${MIPS32} ${MIPS64} ${PPC64}) |
| 277 | set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 278 | |
| 279 | if(APPLE) |
| 280 | include(CompilerRTDarwinUtils) |
| 281 | |
| 282 | option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off) |
| 283 | |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 284 | find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx) |
| 285 | find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator) |
| 286 | find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 287 | |
| 288 | # Note: In order to target x86_64h on OS X the minimum deployment target must |
| 289 | # be 10.8 or higher. |
| 290 | set(SANITIZER_COMMON_SUPPORTED_OS osx) |
Chris Bieneman | 9e6af15 | 2015-08-31 22:26:02 +0000 | [diff] [blame] | 291 | set(BUILTIN_SUPPORTED_OS osx) |
Chris Bieneman | b1ff6e4 | 2015-09-30 21:23:22 +0000 | [diff] [blame] | 292 | set(PROFILE_SUPPORTED_OS osx) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 293 | if(NOT SANITIZER_MIN_OSX_VERSION) |
| 294 | string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)" |
| 295 | MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") |
| 296 | if(MACOSX_VERSION_MIN_FLAG) |
| 297 | set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}") |
| 298 | elseif(CMAKE_OSX_DEPLOYMENT_TARGET) |
| 299 | set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) |
| 300 | else() |
| 301 | set(SANITIZER_MIN_OSX_VERSION 10.9) |
| 302 | endif() |
| 303 | if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") |
| 304 | message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}") |
| 305 | endif() |
| 306 | endif() |
| 307 | |
| 308 | # We're setting the flag manually for each target OS |
| 309 | set(CMAKE_OSX_DEPLOYMENT_TARGET "") |
| 310 | |
| 311 | set(DARWIN_COMMON_CFLAGS -stdlib=libc++) |
| 312 | set(DARWIN_COMMON_LINKFLAGS |
| 313 | -stdlib=libc++ |
| 314 | -lc++ |
| 315 | -lc++abi) |
| 316 | |
| 317 | set(DARWIN_osx_CFLAGS |
| 318 | ${DARWIN_COMMON_CFLAGS} |
| 319 | -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) |
| 320 | set(DARWIN_osx_LINKFLAGS |
| 321 | ${DARWIN_COMMON_LINKFLAGS} |
| 322 | -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION}) |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 323 | set(DARWIN_osx_BUILTIN_MIN_VER 10.5) |
| 324 | set(DARWIN_osx_BUILTIN_MIN_VER_FLAG |
| 325 | -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 326 | |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 327 | if(DARWIN_osx_SYSROOT) |
| 328 | list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT}) |
| 329 | list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${DARWIN_osx_SYSROOT}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 330 | endif() |
| 331 | |
| 332 | # Figure out which arches to use for each OS |
| 333 | darwin_get_toolchain_supported_archs(toolchain_arches) |
| 334 | message(STATUS "Toolchain supported arches: ${toolchain_arches}") |
| 335 | |
| 336 | if(NOT MACOSX_VERSION_MIN_FLAG) |
| 337 | darwin_test_archs(osx |
| 338 | DARWIN_osx_ARCHS |
| 339 | ${toolchain_arches}) |
| 340 | message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}") |
| 341 | foreach(arch ${DARWIN_osx_ARCHS}) |
| 342 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 343 | set(CAN_TARGET_${arch} 1) |
| 344 | endforeach() |
| 345 | |
Chris Bieneman | af01508 | 2015-09-30 20:26:14 +0000 | [diff] [blame] | 346 | # Need to build a 10.4 compatible libclang_rt |
| 347 | set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT}) |
| 348 | set(DARWIN_10.4_BUILTIN_MIN_VER 10.4) |
| 349 | set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG |
| 350 | -mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER}) |
| 351 | set(DARWIN_10.4_SKIP_CC_KEXT On) |
Chris Bieneman | af01508 | 2015-09-30 20:26:14 +0000 | [diff] [blame] | 352 | darwin_test_archs(10.4 |
| 353 | DARWIN_10.4_ARCHS |
| 354 | ${toolchain_arches}) |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 355 | message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}") |
Chris Bieneman | 3a1ad39 | 2015-10-09 16:47:43 +0000 | [diff] [blame] | 356 | if(DARWIN_10.4_ARCHS) |
Chris Bieneman | 4ebd157 | 2015-10-09 18:32:34 +0000 | [diff] [blame^] | 357 | # don't include the Haswell slice in the 10.4 compatibility library |
| 358 | list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h) |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 359 | list(APPEND BUILTIN_SUPPORTED_OS 10.4) |
| 360 | endif() |
Chris Bieneman | af01508 | 2015-09-30 20:26:14 +0000 | [diff] [blame] | 361 | |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 362 | if(DARWIN_iossim_SYSROOT) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 363 | set(DARWIN_iossim_CFLAGS |
| 364 | ${DARWIN_COMMON_CFLAGS} |
| 365 | -mios-simulator-version-min=7.0 |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 366 | -isysroot ${DARWIN_iossim_SYSROOT}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 367 | set(DARWIN_iossim_LINKFLAGS |
| 368 | ${DARWIN_COMMON_LINKFLAGS} |
| 369 | -mios-simulator-version-min=7.0 |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 370 | -isysroot ${DARWIN_iossim_SYSROOT}) |
| 371 | set(DARWIN_iossim_BUILTIN_MIN_VER 6.0) |
| 372 | set(DARWIN_iossim_BUILTIN_MIN_VER_FLAG |
| 373 | -mios-simulator-version-min=${DARWIN_iossim_BUILTIN_MIN_VER}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 374 | |
Chris Bieneman | d823302 | 2015-09-30 20:25:10 +0000 | [diff] [blame] | 375 | set(DARWIN_iossim_SKIP_CC_KEXT On) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 376 | darwin_test_archs(iossim |
| 377 | DARWIN_iossim_ARCHS |
| 378 | ${toolchain_arches}) |
| 379 | message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}") |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 380 | if(DARWIN_iossim_ARCHS) |
| 381 | list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim) |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 382 | endif() |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 383 | foreach(arch ${DARWIN_iossim_ARCHS}) |
| 384 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 385 | set(CAN_TARGET_${arch} 1) |
| 386 | endforeach() |
| 387 | endif() |
| 388 | |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 389 | if(DARWIN_ios_SYSROOT AND COMPILER_RT_ENABLE_IOS) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 390 | set(DARWIN_ios_CFLAGS |
| 391 | ${DARWIN_COMMON_CFLAGS} |
| 392 | -miphoneos-version-min=7.0 |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 393 | -isysroot ${DARWIN_ios_SYSROOT}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 394 | set(DARWIN_ios_LINKFLAGS |
| 395 | ${DARWIN_COMMON_LINKFLAGS} |
| 396 | -miphoneos-version-min=7.0 |
Chris Bieneman | 0d42798 | 2015-09-23 15:18:17 +0000 | [diff] [blame] | 397 | -isysroot ${DARWIN_ios_SYSROOT}) |
| 398 | set(DARWIN_ios_BUILTIN_MIN_VER 6.0) |
| 399 | set(DARWIN_ios_BUILTIN_MIN_VER_FLAG |
| 400 | -miphoneos-version-min=${DARWIN_ios_BUILTIN_MIN_VER}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 401 | |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 402 | darwin_test_archs(ios |
| 403 | DARWIN_ios_ARCHS |
| 404 | ${toolchain_arches}) |
| 405 | message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}") |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 406 | if(DARWIN_ios_ARCHS) |
| 407 | list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios) |
| 408 | list(APPEND BUILTIN_SUPPORTED_OS ios) |
| 409 | list(APPEND PROFILE_SUPPORTED_OS ios) |
Chris Bieneman | adfe26f | 2015-10-01 19:26:26 +0000 | [diff] [blame] | 410 | list(APPEND BUILTIN_SUPPORTED_OS iossim) |
Chris Bieneman | 2917233 | 2015-10-01 18:58:59 +0000 | [diff] [blame] | 411 | endif() |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 412 | foreach(arch ${DARWIN_ios_ARCHS}) |
| 413 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 414 | set(CAN_TARGET_${arch} 1) |
| 415 | endforeach() |
| 416 | endif() |
| 417 | endif() |
| 418 | |
| 419 | # for list_union |
| 420 | include(CompilerRTUtils) |
| 421 | |
Chris Bieneman | b38affa | 2015-08-31 21:24:50 +0000 | [diff] [blame] | 422 | list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches) |
| 423 | |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 424 | list_union(SANITIZER_COMMON_SUPPORTED_ARCH |
| 425 | ALL_SANITIZER_COMMON_SUPPORTED_ARCH |
| 426 | COMPILER_RT_SUPPORTED_ARCH |
| 427 | ) |
| 428 | set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
| 429 | set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
| 430 | list_union(ASAN_SUPPORTED_ARCH |
| 431 | ALL_ASAN_SUPPORTED_ARCH |
| 432 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 433 | list_union(DFSAN_SUPPORTED_ARCH |
| 434 | ALL_DFSAN_SUPPORTED_ARCH |
| 435 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 436 | list_union(LSAN_SUPPORTED_ARCH |
| 437 | ALL_LSAN_SUPPORTED_ARCH |
| 438 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 439 | list_union(MSAN_SUPPORTED_ARCH |
| 440 | ALL_MSAN_SUPPORTED_ARCH |
| 441 | SANITIZER_COMMON_SUPPORTED_ARCH) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 442 | list_union(PROFILE_SUPPORTED_ARCH |
| 443 | ALL_PROFILE_SUPPORTED_ARCH |
Chris Bieneman | b1ff6e4 | 2015-09-30 21:23:22 +0000 | [diff] [blame] | 444 | SANITIZER_COMMON_SUPPORTED_ARCH) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 445 | list_union(TSAN_SUPPORTED_ARCH |
| 446 | ALL_TSAN_SUPPORTED_ARCH |
| 447 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 448 | list_union(UBSAN_SUPPORTED_ARCH |
| 449 | ALL_UBSAN_SUPPORTED_ARCH |
| 450 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 451 | list_union(SAFESTACK_SUPPORTED_ARCH |
| 452 | ALL_SAFESTACK_SUPPORTED_ARCH |
| 453 | SANITIZER_COMMON_SUPPORTED_ARCH) |
| 454 | else() |
| 455 | # Architectures supported by compiler-rt libraries. |
Chris Bieneman | b38affa | 2015-08-31 21:24:50 +0000 | [diff] [blame] | 456 | filter_available_targets(BUILTIN_SUPPORTED_ARCH |
| 457 | ${ALL_BUILTIN_SUPPORTED_ARCH}) |
Chris Bieneman | 361231e | 2015-08-13 20:38:16 +0000 | [diff] [blame] | 458 | filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH |
| 459 | ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) |
| 460 | # LSan and UBSan common files should be available on all architectures |
| 461 | # supported by other sanitizers (even if they build into dummy object files). |
| 462 | filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH |
| 463 | ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
| 464 | filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH |
| 465 | ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
| 466 | filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH}) |
| 467 | filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH}) |
| 468 | filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH}) |
| 469 | filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH}) |
| 470 | filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH}) |
| 471 | filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH}) |
| 472 | filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH}) |
| 473 | filter_available_targets(SAFESTACK_SUPPORTED_ARCH |
| 474 | ${ALL_SAFESTACK_SUPPORTED_ARCH}) |
| 475 | endif() |
| 476 | |
| 477 | message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 478 | |
| 479 | if(ANDROID) |
| 480 | set(OS_NAME "Android") |
| 481 | else() |
| 482 | set(OS_NAME "${CMAKE_SYSTEM_NAME}") |
| 483 | endif() |
| 484 | |
| 485 | if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND |
| 486 | (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR |
Peter Collingbourne | d3b9917 | 2015-07-02 01:44:34 +0000 | [diff] [blame] | 487 | (OS_NAME MATCHES "Windows" AND MSVC))) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 488 | set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE) |
| 489 | else() |
| 490 | set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE) |
| 491 | endif() |
| 492 | |
Peter Collingbourne | d3b9917 | 2015-07-02 01:44:34 +0000 | [diff] [blame] | 493 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND |
| 494 | (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4)) |
| 495 | set(COMPILER_RT_HAS_INTERCEPTION TRUE) |
| 496 | else() |
| 497 | set(COMPILER_RT_HAS_INTERCEPTION FALSE) |
| 498 | endif() |
| 499 | |
| 500 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND |
| 501 | (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4)) |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 502 | set(COMPILER_RT_HAS_ASAN TRUE) |
| 503 | else() |
| 504 | set(COMPILER_RT_HAS_ASAN FALSE) |
| 505 | endif() |
| 506 | |
Alexey Samsonov | 9cea2c1 | 2015-02-03 18:40:34 +0000 | [diff] [blame] | 507 | if (OS_NAME MATCHES "Linux|FreeBSD|Windows") |
Alexey Samsonov | 969902b | 2014-12-17 23:14:01 +0000 | [diff] [blame] | 508 | set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE) |
| 509 | else() |
| 510 | set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE) |
| 511 | endif() |
| 512 | |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 513 | # TODO: Add builtins support. |
| 514 | |
| 515 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND |
| 516 | OS_NAME MATCHES "Linux") |
| 517 | set(COMPILER_RT_HAS_DFSAN TRUE) |
| 518 | else() |
| 519 | set(COMPILER_RT_HAS_DFSAN FALSE) |
| 520 | endif() |
| 521 | |
| 522 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND |
Alexey Samsonov | 2a56783 | 2015-06-19 01:34:06 +0000 | [diff] [blame] | 523 | OS_NAME MATCHES "Linux|FreeBSD") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 524 | set(COMPILER_RT_HAS_LSAN TRUE) |
| 525 | else() |
| 526 | set(COMPILER_RT_HAS_LSAN FALSE) |
| 527 | endif() |
| 528 | |
| 529 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND |
| 530 | OS_NAME MATCHES "Linux") |
| 531 | set(COMPILER_RT_HAS_MSAN TRUE) |
| 532 | else() |
| 533 | set(COMPILER_RT_HAS_MSAN FALSE) |
| 534 | endif() |
| 535 | |
| 536 | if (PROFILE_SUPPORTED_ARCH AND |
| 537 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 538 | set(COMPILER_RT_HAS_PROFILE TRUE) |
| 539 | else() |
| 540 | set(COMPILER_RT_HAS_PROFILE FALSE) |
| 541 | endif() |
| 542 | |
| 543 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND |
Viktor Kutuzov | c8f3435 | 2014-10-27 11:28:53 +0000 | [diff] [blame] | 544 | OS_NAME MATCHES "Linux|FreeBSD") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 545 | set(COMPILER_RT_HAS_TSAN TRUE) |
| 546 | else() |
| 547 | set(COMPILER_RT_HAS_TSAN FALSE) |
| 548 | endif() |
| 549 | |
| 550 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND |
Peter Collingbourne | d3b9917 | 2015-07-02 01:44:34 +0000 | [diff] [blame] | 551 | OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows") |
Alexey Samsonov | 68b9e74 | 2014-08-08 22:01:20 +0000 | [diff] [blame] | 552 | set(COMPILER_RT_HAS_UBSAN TRUE) |
| 553 | else() |
| 554 | set(COMPILER_RT_HAS_UBSAN FALSE) |
| 555 | endif() |
| 556 | |
Dmitry Vyukov | 4bf0894 | 2015-04-10 09:45:22 +0000 | [diff] [blame] | 557 | # -msse3 flag is not valid for Mips therefore clang gives a warning |
| 558 | # message with -msse3. But check_c_compiler_flags() checks only for |
| 559 | # compiler error messages. Therefore COMPILER_RT_HAS_MSSE3_FLAG turns out to be |
Sagar Thakur | bcc495a | 2015-04-17 10:14:16 +0000 | [diff] [blame] | 560 | # true on Mips, so we make it false here. |
Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 561 | if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips") |
Dmitry Vyukov | 4bf0894 | 2015-04-10 09:45:22 +0000 | [diff] [blame] | 562 | set(COMPILER_RT_HAS_MSSE3_FLAG FALSE) |
| 563 | endif() |
Peter Collingbourne | b64d0b1 | 2015-06-15 21:08:47 +0000 | [diff] [blame] | 564 | |
Peter Collingbourne | 8727100 | 2015-06-16 18:52:28 +0000 | [diff] [blame] | 565 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND |
Peter Collingbourne | b64d0b1 | 2015-06-15 21:08:47 +0000 | [diff] [blame] | 566 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 567 | set(COMPILER_RT_HAS_SAFESTACK TRUE) |
| 568 | else() |
| 569 | set(COMPILER_RT_HAS_SAFESTACK FALSE) |
| 570 | endif() |