| Chandler Carruth | 1f5d5c0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 1 | # CMake build for CompilerRT. | 
|  | 2 | # | 
|  | 3 | # This build assumes that CompilerRT is checked out into the | 
| Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 4 | # 'projects/compiler-rt' inside of an LLVM tree. | 
|  | 5 | # Standalone build system for CompilerRT is not yet ready. | 
| Chandler Carruth | 1f5d5c0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 6 | # | 
|  | 7 | # An important constraint of the build is that it only produces libraries | 
|  | 8 | # based on the ability of the host toolchain to target various platforms. | 
|  | 9 |  | 
| Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 10 | # Check if compiler-rt is built as a standalone project. | 
|  | 11 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | 
| Douglas Katzman | c4ffd48 | 2015-07-28 16:52:42 +0000 | [diff] [blame] | 12 | project(CompilerRT C CXX ASM) | 
| Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 13 | set(COMPILER_RT_STANDALONE_BUILD TRUE) | 
| Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 14 | endif() | 
|  | 15 |  | 
| Chris Bieneman | 5c3112c | 2016-05-31 20:21:42 +0000 | [diff] [blame] | 16 | cmake_minimum_required(VERSION 3.4.3) | 
| Xinliang David Li | 2baff11 | 2016-06-02 20:33:33 +0000 | [diff] [blame] | 17 | # FIXME: | 
|  | 18 | # The OLD behavior (pre 3.2) for this policy is to not set the value of the | 
|  | 19 | # CMAKE_EXE_LINKER_FLAGS variable in the generated test project. The NEW behavior | 
|  | 20 | # for this policy is to set the value of the CMAKE_EXE_LINKER_FLAGS variable | 
|  | 21 | # in the test project to the same as it is in the calling project. The new | 
|  | 22 | # behavior cause the compiler_rt test to fail during try_compile: see | 
|  | 23 | # projects/compiler-rt/cmake/Modules/CompilerRTUtils.cmake:121 such that | 
|  | 24 | # CAN_TARGET_${arch} is not set properly. This results in COMPILER_RT_SUPPORTED_ARCH | 
|  | 25 | # not being updated properly leading to poblems. | 
| Chris Bieneman | bae0eea | 2016-06-09 21:32:17 +0000 | [diff] [blame] | 26 | cmake_policy(SET CMP0056 OLD) | 
| NAKAMURA Takumi | 9cd9ad6 | 2014-02-26 06:45:11 +0000 | [diff] [blame] | 27 |  | 
| Chris Bieneman | c49e5e3 | 2016-05-09 21:45:52 +0000 | [diff] [blame] | 28 | # Add path for custom compiler-rt modules. | 
|  | 29 | list(INSERT CMAKE_MODULE_PATH 0 | 
|  | 30 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake" | 
|  | 31 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" | 
|  | 32 | ) | 
|  | 33 |  | 
|  | 34 | include(base-config-ix) | 
| Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame^] | 35 | include(CompilerRTUtils) | 
| Alexey Samsonov | 20abdf6 | 2013-10-01 12:52:15 +0000 | [diff] [blame] | 36 |  | 
| Chris Bieneman | 679ab85 | 2015-09-14 19:59:24 +0000 | [diff] [blame] | 37 | option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) | 
|  | 38 | mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) | 
|  | 39 | option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) | 
|  | 40 | mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) | 
| Dean Michael Berris | 7094aa4 | 2016-07-27 08:10:04 +0000 | [diff] [blame] | 41 |  | 
|  | 42 | # TODO: Flip this to default ON when build bots recognize this new option. | 
|  | 43 | option(COMPILER_RT_BUILD_XRAY "Build xray" OFF) | 
| Dean Michael Berris | 938c503 | 2016-07-21 07:39:55 +0000 | [diff] [blame] | 44 | mark_as_advanced(COMPILER_RT_BUILD_XRAY) | 
| Chris Bieneman | 679ab85 | 2015-09-14 19:59:24 +0000 | [diff] [blame] | 45 |  | 
| Chris Bieneman | c49e5e3 | 2016-05-09 21:45:52 +0000 | [diff] [blame] | 46 | if (COMPILER_RT_STANDALONE_BUILD) | 
| Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame^] | 47 | load_llvm_config() | 
| Alexey Samsonov | aa980c7 | 2014-02-19 10:04:29 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | # Find Python interpreter. | 
|  | 50 | set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5) | 
|  | 51 | include(FindPythonInterp) | 
|  | 52 | if(NOT PYTHONINTERP_FOUND) | 
|  | 53 | message(FATAL_ERROR " | 
|  | 54 | Unable to find Python interpreter required testing. Please install Python | 
|  | 55 | or specify the PYTHON_EXECUTABLE CMake variable.") | 
|  | 56 | endif() | 
|  | 57 |  | 
|  | 58 | # Define default arguments to lit. | 
|  | 59 | set(LIT_ARGS_DEFAULT "-sv") | 
|  | 60 | if (MSVC OR XCODE) | 
|  | 61 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") | 
|  | 62 | endif() | 
|  | 63 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") | 
| Alexey Samsonov | de4ef2a | 2014-02-19 07:49:16 +0000 | [diff] [blame] | 64 | endif() | 
|  | 65 |  | 
| Jonas Hahnfeld | 9b2c3ab | 2016-08-02 05:51:05 +0000 | [diff] [blame^] | 66 | construct_compiler_rt_default_triple() | 
| Chris Bieneman | 990ff38 | 2016-06-27 22:52:05 +0000 | [diff] [blame] | 67 | if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi") | 
|  | 68 | set(ANDROID 1) | 
|  | 69 | endif() | 
| Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 70 |  | 
|  | 71 | set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | 
| Alexey Samsonov | 6a65b18 | 2013-06-06 12:35:48 +0000 | [diff] [blame] | 72 | set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) | 
| Alexey Samsonov | ca7fcf2 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 73 |  | 
| Timur Iskhodzhanov | b9bd76b | 2014-05-13 14:25:49 +0000 | [diff] [blame] | 74 | # We support running instrumented tests when we're not cross compiling | 
|  | 75 | # and target a UNIX-like system or Windows. | 
|  | 76 | # We can run tests on Android even when we are cross-compiling. | 
| Reid Kleckner | fbfed86 | 2015-07-17 16:23:05 +0000 | [diff] [blame] | 77 | if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID | 
| Greg Fitzgerald | 07c88a1 | 2014-05-14 00:36:15 +0000 | [diff] [blame] | 78 | OR COMPILER_RT_EMULATOR) | 
| Michael Gottesman | 4ddc215 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 79 | option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON) | 
| Alexey Samsonov | c20f5d2 | 2012-12-27 13:19:23 +0000 | [diff] [blame] | 80 | else() | 
| Michael Gottesman | 4ddc215 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 81 | option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF) | 
| Alexey Samsonov | c20f5d2 | 2012-12-27 13:19:23 +0000 | [diff] [blame] | 82 | endif() | 
| Michael Gottesman | 4ddc215 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 83 |  | 
| Peter Collingbourne | cbdea32 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 84 | option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF) | 
| Chris Bieneman | 69a372d | 2015-12-03 20:08:22 +0000 | [diff] [blame] | 85 | option(COMPILER_RT_EXTERNALIZE_DEBUGINFO | 
|  | 86 | "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) | 
| Peter Collingbourne | cbdea32 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 87 | # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. | 
|  | 88 | pythonize_bool(COMPILER_RT_DEBUG) | 
|  | 89 |  | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 90 | #================================ | 
|  | 91 | # Setup Compiler Flags | 
|  | 92 | #================================ | 
| Saleem Abdulrasool | a7452e4 | 2015-01-14 15:55:17 +0000 | [diff] [blame] | 93 |  | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 94 | include(config-ix) | 
|  | 95 |  | 
| Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame] | 96 | if(MSVC) | 
| Reid Kleckner | d0680ad | 2016-06-17 17:48:52 +0000 | [diff] [blame] | 97 | # Override any existing /W flags with /W4. This is what LLVM does.  Failing to | 
|  | 98 | # remove other /W[0-4] flags will result in a warning about overriding a | 
|  | 99 | # previous flag. | 
|  | 100 | if (COMPILER_RT_HAS_W4_FLAG) | 
|  | 101 | string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | 
|  | 102 | string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") | 
|  | 103 | append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS) | 
|  | 104 | endif() | 
| Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame] | 105 | else() | 
|  | 106 | append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS) | 
|  | 107 | endif() | 
| Alexey Samsonov | 2f27f0b | 2014-02-24 11:22:39 +0000 | [diff] [blame] | 108 | if(COMPILER_RT_ENABLE_WERROR) | 
| Alexey Samsonov | fe7e28c | 2014-03-13 11:31:10 +0000 | [diff] [blame] | 109 | append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS) | 
|  | 110 | append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS) | 
| Alexey Samsonov | 2f27f0b | 2014-02-24 11:22:39 +0000 | [diff] [blame] | 111 | endif() | 
|  | 112 |  | 
| Alexey Samsonov | bcce197 | 2014-03-18 12:49:22 +0000 | [diff] [blame] | 113 | append_string_if(COMPILER_RT_HAS_STD_CXX11_FLAG -std=c++11 CMAKE_CXX_FLAGS) | 
|  | 114 |  | 
| Reid Kleckner | 0140ce4 | 2014-02-26 21:54:39 +0000 | [diff] [blame] | 115 | # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP. | 
| Alexey Samsonov | e3e2a11 | 2014-02-27 06:52:41 +0000 | [diff] [blame] | 116 | if(NOT COMPILER_RT_HAS_FUNC_SYMBOL) | 
| Alexey Samsonov | 8c4c097 | 2014-02-27 07:03:32 +0000 | [diff] [blame] | 117 | add_definitions(-D__func__=__FUNCTION__) | 
| Reid Kleckner | 0140ce4 | 2014-02-26 21:54:39 +0000 | [diff] [blame] | 118 | endif() | 
|  | 119 |  | 
| Chandler Carruth | c1c9d58 | 2012-08-29 00:13:11 +0000 | [diff] [blame] | 120 | # Provide some common commmandline flags for Sanitizer runtimes. | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 121 | append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS) | 
|  | 122 | append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS) | 
|  | 123 | append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS) | 
| Kuba Brecka | 83460cf | 2016-05-22 19:59:06 +0000 | [diff] [blame] | 124 | if(NOT COMPILER_RT_DEBUG) | 
|  | 125 | append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS) | 
|  | 126 | endif() | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 127 | append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS) | 
|  | 128 | append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS) | 
| Peter Collingbourne | b64d0b1 | 2015-06-15 21:08:47 +0000 | [diff] [blame] | 129 | append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS) | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 130 | append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS) | 
| Chris Bieneman | 9586a38 | 2015-11-30 19:16:42 +0000 | [diff] [blame] | 131 | append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS) | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 132 | append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections SANITIZER_COMMON_CFLAGS) | 
| Evgeniy Stepanov | 8c9a070 | 2015-01-15 16:31:22 +0000 | [diff] [blame] | 133 | append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS) | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 134 |  | 
| Alexey Samsonov | 6c282b4 | 2014-02-28 08:04:30 +0000 | [diff] [blame] | 135 | if(MSVC) | 
| Peter Collingbourne | 702548d | 2015-07-08 22:10:34 +0000 | [diff] [blame] | 136 | # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG, | 
|  | 137 | # which cause definition mismatches at link time. | 
| Timur Iskhodzhanov | de1718d | 2014-08-12 09:44:56 +0000 | [diff] [blame] | 138 | # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214. | 
| Alexey Samsonov | 6c282b4 | 2014-02-28 08:04:30 +0000 | [diff] [blame] | 139 | if(COMPILER_RT_HAS_MT_FLAG) | 
| Aaron Ballman | 7c7be2f | 2014-10-23 20:24:00 +0000 | [diff] [blame] | 140 | foreach(flag_var | 
| Andrey Turetskiy | bc0122b | 2016-02-20 12:56:04 +0000 | [diff] [blame] | 141 | CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE | 
|  | 142 | CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO | 
| Aaron Ballman | 7c7be2f | 2014-10-23 20:24:00 +0000 | [diff] [blame] | 143 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE | 
|  | 144 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) | 
| Peter Collingbourne | 702548d | 2015-07-08 22:10:34 +0000 | [diff] [blame] | 145 | string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}") | 
|  | 146 | string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") | 
|  | 147 | string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}") | 
| Aaron Ballman | 7c7be2f | 2014-10-23 20:24:00 +0000 | [diff] [blame] | 148 | endforeach() | 
| Alexey Samsonov | 6c282b4 | 2014-02-28 08:04:30 +0000 | [diff] [blame] | 149 | endif() | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 150 | append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS) | 
|  | 151 | append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS) | 
| Reid Kleckner | 21aca48 | 2016-03-21 20:08:59 +0000 | [diff] [blame] | 152 | # VS 2015 (version 1900) added support for thread safe static initialization. | 
|  | 153 | # However, ASan interceptors run before CRT initialization, which causes the | 
|  | 154 | # new thread safe code to crash. Disable this feature for now. | 
| Reid Kleckner | f6d5475 | 2016-07-21 20:03:37 +0000 | [diff] [blame] | 155 | if (MSVC_VERSION GREATER 1899 OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") | 
| Reid Kleckner | 21aca48 | 2016-03-21 20:08:59 +0000 | [diff] [blame] | 156 | list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-) | 
|  | 157 | endif() | 
| Alexey Samsonov | 6c282b4 | 2014-02-28 08:04:30 +0000 | [diff] [blame] | 158 | endif() | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 159 |  | 
| Alexey Samsonov | ea04032 | 2015-01-06 20:25:34 +0000 | [diff] [blame] | 160 | append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS) | 
| Alexey Samsonov | df3aeb8 | 2015-01-03 04:29:12 +0000 | [diff] [blame] | 161 |  | 
| Alexey Samsonov | cbc6852 | 2014-03-13 13:37:07 +0000 | [diff] [blame] | 162 | # Build with optimization, unless we're in debug mode. If we're using MSVC, | 
|  | 163 | # always respect the optimization flags set by CMAKE_BUILD_TYPE instead. | 
|  | 164 | if(NOT COMPILER_RT_DEBUG AND NOT MSVC) | 
|  | 165 | list(APPEND SANITIZER_COMMON_CFLAGS -O3) | 
| Hans Wennborg | 67c6e50 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 166 | endif() | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 167 |  | 
| Alexey Samsonov | df3aeb8 | 2015-01-03 04:29:12 +0000 | [diff] [blame] | 168 | # Determine if we should restrict stack frame sizes. | 
| Dmitry Vyukov | 4bf0894 | 2015-04-10 09:45:22 +0000 | [diff] [blame] | 169 | # Stack frames on PowerPC and Mips and in debug biuld can be much larger than | 
| Alexey Samsonov | df3aeb8 | 2015-01-03 04:29:12 +0000 | [diff] [blame] | 170 | # anticipated. | 
|  | 171 | # FIXME: Fix all sanitizers and add -Wframe-larger-than to | 
|  | 172 | # SANITIZER_COMMON_FLAGS | 
|  | 173 | if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG | 
| Alexey Samsonov | 63eaeca | 2015-09-08 23:13:47 +0000 | [diff] [blame] | 174 | AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips") | 
| Alexey Samsonov | df3aeb8 | 2015-01-03 04:29:12 +0000 | [diff] [blame] | 175 | set(SANITIZER_LIMIT_FRAME_SIZE TRUE) | 
|  | 176 | else() | 
|  | 177 | set(SANITIZER_LIMIT_FRAME_SIZE FALSE) | 
|  | 178 | endif() | 
|  | 179 |  | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 180 | # Build sanitizer runtimes with debug info. | 
| Kuba Brecka | 5238deb | 2014-12-23 01:52:53 +0000 | [diff] [blame] | 181 | if(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG) | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 182 | list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only) | 
|  | 183 | elseif(COMPILER_RT_HAS_G_FLAG) | 
|  | 184 | list(APPEND SANITIZER_COMMON_CFLAGS -g) | 
| Reid Kleckner | 1734b97 | 2016-08-02 01:02:46 +0000 | [diff] [blame] | 185 | elseif(MSVC) | 
|  | 186 | # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099 | 
|  | 187 | # warning from the MS linker complaining that it can't find the 'vc140.pdb' | 
|  | 188 | # file used by our object library compilations. | 
|  | 189 | list(APPEND SANITIZER_COMMON_CFLAGS /Z7) | 
|  | 190 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS "/Z[i7I]" "/Z7") | 
|  | 191 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS_DEBUG "/Z[i7I]" "/Z7") | 
|  | 192 | llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Z[i7I]" "/Z7") | 
| Alexey Samsonov | 75fb677 | 2012-11-08 14:49:28 +0000 | [diff] [blame] | 193 | endif() | 
| Alexey Samsonov | 9a1ffce | 2014-02-18 07:26:58 +0000 | [diff] [blame] | 194 |  | 
|  | 195 | # Turn off several warnings. | 
| Alexey Samsonov | 829da45 | 2014-11-13 21:19:53 +0000 | [diff] [blame] | 196 | append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS) | 
|  | 197 | append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS) | 
|  | 198 | append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS) | 
|  | 199 | append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS) | 
| Aaron Ballman | 1d1f232 | 2014-10-23 20:39:58 +0000 | [diff] [blame] | 200 | append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS) | 
|  | 201 | append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS) | 
| Kuba Brecka | 14c0c59 | 2014-10-15 22:47:54 +0000 | [diff] [blame] | 202 | append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS) | 
|  | 203 | append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS) | 
| Aaron Ballman | 1d1f232 | 2014-10-23 20:39:58 +0000 | [diff] [blame] | 204 | append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) | 
| Chandler Carruth | c1c9d58 | 2012-08-29 00:13:11 +0000 | [diff] [blame] | 205 |  | 
| Reid Kleckner | 44e6e36 | 2016-06-17 18:30:37 +0000 | [diff] [blame] | 206 | # Warnings to turn off for all libraries, not just sanitizers. | 
|  | 207 | append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS) | 
|  | 208 |  | 
| Alexey Samsonov | 3fa03e3 | 2015-06-25 00:57:42 +0000 | [diff] [blame] | 209 | if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9") | 
|  | 210 | # Mac OS X prior to 10.9 had problems with exporting symbols from | 
|  | 211 | # libc++/libc++abi. | 
|  | 212 | set(SANITIZER_CAN_USE_CXXABI FALSE) | 
| Reid Kleckner | b3e847e | 2016-02-01 19:13:28 +0000 | [diff] [blame] | 213 | elseif(MSVC) | 
|  | 214 | set(SANITIZER_CAN_USE_CXXABI FALSE) | 
| Alexey Samsonov | 3fa03e3 | 2015-06-25 00:57:42 +0000 | [diff] [blame] | 215 | else() | 
|  | 216 | set(SANITIZER_CAN_USE_CXXABI TRUE) | 
|  | 217 | endif() | 
|  | 218 | pythonize_bool(SANITIZER_CAN_USE_CXXABI) | 
|  | 219 |  | 
| Alexey Samsonov | 9f3938e | 2013-04-11 15:49:52 +0000 | [diff] [blame] | 220 | add_subdirectory(include) | 
|  | 221 |  | 
| Reid Kleckner | b509318 | 2015-08-11 17:22:06 +0000 | [diff] [blame] | 222 | set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx) | 
| Alexey Samsonov | 8434e60 | 2014-02-14 13:02:58 +0000 | [diff] [blame] | 223 | if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/) | 
|  | 224 | set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE) | 
|  | 225 | else() | 
|  | 226 | set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE) | 
|  | 227 | endif() | 
|  | 228 |  | 
| Reid Kleckner | c1cd8dd | 2015-08-11 18:43:13 +0000 | [diff] [blame] | 229 | set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld) | 
| Reid Kleckner | 45ebaf1 | 2015-08-11 00:33:07 +0000 | [diff] [blame] | 230 | if(EXISTS ${COMPILER_RT_LLD_PATH}/) | 
|  | 231 | set(COMPILER_RT_HAS_LLD_SOURCES TRUE) | 
|  | 232 | else() | 
|  | 233 | set(COMPILER_RT_HAS_LLD_SOURCES FALSE) | 
|  | 234 | endif() | 
|  | 235 | pythonize_bool(COMPILER_RT_HAS_LLD_SOURCES) | 
|  | 236 |  | 
| Chandler Carruth | 1f5d5c0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 237 | add_subdirectory(lib) | 
|  | 238 |  | 
| Alexey Samsonov | cd8535a | 2014-02-19 11:18:47 +0000 | [diff] [blame] | 239 | if(COMPILER_RT_INCLUDE_TESTS) | 
| Alexey Samsonov | 81a2b46 | 2014-02-14 11:00:07 +0000 | [diff] [blame] | 240 | add_subdirectory(unittests) | 
| Chris Bieneman | fb92d9a | 2015-09-14 19:54:12 +0000 | [diff] [blame] | 241 | add_subdirectory(test) | 
| Chandler Carruth | 1f5d5c0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 242 | endif() |