Chandler Carruth | d51e0a0 | 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 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | # 'projects/compiler-rt' inside of an LLVM tree. |
| 5 | # Standalone build system for CompilerRT is not yet ready. |
Chandler Carruth | d51e0a0 | 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 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 10 | # Check if compiler-rt is built as a standalone project. |
| 11 | if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 12 | project(CompilerRT C CXX ASM) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | set(COMPILER_RT_STANDALONE_BUILD TRUE) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | endif() |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 15 | |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 16 | cmake_minimum_required(VERSION 3.4.3) |
| 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. |
| 26 | cmake_policy(SET CMP0056 OLD) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 27 | |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [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 | ) |
Chandler Carruth | a765ffc | 2012-06-25 08:40:10 +0000 | [diff] [blame] | 33 | |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 34 | include(base-config-ix) |
Alexey Samsonov | c349466 | 2013-10-01 12:52:15 +0000 | [diff] [blame] | 35 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 36 | option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) |
| 37 | mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) |
| 38 | option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) |
| 39 | mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) |
| 40 | |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 41 | if (COMPILER_RT_STANDALONE_BUILD) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 42 | if (NOT LLVM_CONFIG_PATH) |
| 43 | find_program(LLVM_CONFIG_PATH "llvm-config" |
| 44 | DOC "Path to llvm-config binary") |
| 45 | if (NOT LLVM_CONFIG_PATH) |
| 46 | message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") |
| 47 | endif() |
| 48 | endif() |
| 49 | execute_process( |
| 50 | COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" |
| 51 | RESULT_VARIABLE HAD_ERROR |
| 52 | OUTPUT_VARIABLE CONFIG_OUTPUT) |
| 53 | if (HAD_ERROR) |
| 54 | message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") |
| 55 | endif() |
| 56 | string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT}) |
| 57 | list(GET CONFIG_OUTPUT 0 LLVM_BINARY_DIR) |
| 58 | list(GET CONFIG_OUTPUT 1 LLVM_TOOLS_BINARY_DIR) |
| 59 | list(GET CONFIG_OUTPUT 2 LLVM_LIBRARY_DIR) |
| 60 | list(GET CONFIG_OUTPUT 3 LLVM_MAIN_SRC_DIR) |
| 61 | |
| 62 | # Make use of LLVM CMake modules. |
| 63 | file(TO_CMAKE_PATH ${LLVM_BINARY_DIR} LLVM_BINARY_DIR_CMAKE_STYLE) |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 64 | set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 65 | list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") |
| 66 | # Get some LLVM variables from LLVMConfig. |
| 67 | include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") |
| 68 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 69 | set(LLVM_LIBRARY_OUTPUT_INTDIR |
| 70 | ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 71 | |
| 72 | # Find Python interpreter. |
| 73 | set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5) |
| 74 | include(FindPythonInterp) |
| 75 | if(NOT PYTHONINTERP_FOUND) |
| 76 | message(FATAL_ERROR " |
| 77 | Unable to find Python interpreter required testing. Please install Python |
| 78 | or specify the PYTHON_EXECUTABLE CMake variable.") |
| 79 | endif() |
| 80 | |
| 81 | # Define default arguments to lit. |
| 82 | set(LIT_ARGS_DEFAULT "-sv") |
| 83 | if (MSVC OR XCODE) |
| 84 | set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") |
| 85 | endif() |
| 86 | set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") |
| 87 | endif() |
| 88 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 89 | set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${TARGET_TRIPLE} CACHE STRING |
| 90 | "Default triple for which compiler-rt runtimes will be built.") |
| 91 | if(DEFINED COMPILER_RT_TEST_TARGET_TRIPLE) |
| 92 | # Backwards compatibility: this variable used to be called |
| 93 | # COMPILER_RT_TEST_TARGET_TRIPLE. |
| 94 | set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${COMPILER_RT_TEST_TARGET_TRIPLE}) |
| 95 | endif() |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 96 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 97 | string(REPLACE "-" ";" TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE}) |
| 98 | list(GET TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH) |
| 99 | list(GET TARGET_TRIPLE_LIST 1 COMPILER_RT_DEFAULT_TARGET_OS) |
| 100 | list(GET TARGET_TRIPLE_LIST 2 COMPILER_RT_DEFAULT_TARGET_ABI) |
| 101 | # Determine if test target triple is specified explicitly, and doesn't match the |
| 102 | # default. |
| 103 | if(NOT COMPILER_RT_DEFAULT_TARGET_TRIPLE STREQUAL TARGET_TRIPLE) |
| 104 | set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE TRUE) |
| 105 | else() |
| 106 | set(COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE FALSE) |
| 107 | endif() |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 108 | if ("${COMPILER_RT_DEFAULT_TARGET_ABI}" STREQUAL "androideabi") |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 109 | set(ANDROID 1) |
| 110 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 111 | include(CompilerRTUtils) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 112 | |
| 113 | set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
Alexey Samsonov | dd6605e | 2013-06-06 12:35:48 +0000 | [diff] [blame] | 114 | set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 115 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 116 | # We support running instrumented tests when we're not cross compiling |
| 117 | # and target a UNIX-like system or Windows. |
| 118 | # We can run tests on Android even when we are cross-compiling. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 119 | if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 120 | OR COMPILER_RT_EMULATOR) |
Michael Gottesman | fd0a789 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 121 | option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON) |
Alexey Samsonov | d7d7b5f | 2012-12-27 13:19:23 +0000 | [diff] [blame] | 122 | else() |
Michael Gottesman | fd0a789 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 123 | option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF) |
Alexey Samsonov | d7d7b5f | 2012-12-27 13:19:23 +0000 | [diff] [blame] | 124 | endif() |
Michael Gottesman | fd0a789 | 2013-04-01 04:13:03 +0000 | [diff] [blame] | 125 | |
Peter Collingbourne | 7e8db74 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 126 | option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 127 | option(COMPILER_RT_EXTERNALIZE_DEBUGINFO |
| 128 | "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF) |
Peter Collingbourne | 7e8db74 | 2013-10-25 23:03:34 +0000 | [diff] [blame] | 129 | # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. |
| 130 | pythonize_bool(COMPILER_RT_DEBUG) |
| 131 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 132 | #================================ |
| 133 | # Setup Compiler Flags |
| 134 | #================================ |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 135 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 136 | include(config-ix) |
| 137 | |
| 138 | if(MSVC) |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 139 | # Override any existing /W flags with /W4. This is what LLVM does. Failing to |
| 140 | # remove other /W[0-4] flags will result in a warning about overriding a |
| 141 | # previous flag. |
| 142 | if (COMPILER_RT_HAS_W4_FLAG) |
| 143 | string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 144 | string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 145 | append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| 146 | endif() |
Alexey Samsonov | 275ca01 | 2012-11-08 14:49:28 +0000 | [diff] [blame] | 147 | else() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 148 | append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 149 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 150 | if(COMPILER_RT_ENABLE_WERROR) |
| 151 | append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| 152 | append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| 153 | endif() |
| 154 | |
| 155 | append_string_if(COMPILER_RT_HAS_STD_CXX11_FLAG -std=c++11 CMAKE_CXX_FLAGS) |
| 156 | |
| 157 | # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP. |
| 158 | if(NOT COMPILER_RT_HAS_FUNC_SYMBOL) |
| 159 | add_definitions(-D__func__=__FUNCTION__) |
| 160 | endif() |
| 161 | |
| 162 | # Provide some common commmandline flags for Sanitizer runtimes. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 163 | append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS) |
| 164 | append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS) |
| 165 | append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS) |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 166 | if(NOT COMPILER_RT_DEBUG) |
| 167 | append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS) |
| 168 | endif() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 169 | append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS) |
| 170 | append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 171 | append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 172 | append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 173 | append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 174 | append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections SANITIZER_COMMON_CFLAGS) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 175 | append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 176 | |
| 177 | if(MSVC) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 178 | # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG, |
| 179 | # which cause definition mismatches at link time. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 180 | # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 181 | if(COMPILER_RT_HAS_MT_FLAG) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 182 | foreach(flag_var |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 183 | CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE |
| 184 | CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 185 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 186 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 187 | string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}") |
| 188 | string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
| 189 | string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 190 | endforeach() |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 191 | endif() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 192 | append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS) |
| 193 | append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS) |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 194 | # VS 2015 (version 1900) added support for thread safe static initialization. |
| 195 | # However, ASan interceptors run before CRT initialization, which causes the |
| 196 | # new thread safe code to crash. Disable this feature for now. |
| 197 | if (MSVC_VERSION GREATER 1899) |
| 198 | list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-) |
| 199 | endif() |
Alexey Samsonov | 275ca01 | 2012-11-08 14:49:28 +0000 | [diff] [blame] | 200 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 201 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 202 | append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS) |
| 203 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 204 | # Build with optimization, unless we're in debug mode. If we're using MSVC, |
| 205 | # always respect the optimization flags set by CMAKE_BUILD_TYPE instead. |
| 206 | if(NOT COMPILER_RT_DEBUG AND NOT MSVC) |
| 207 | list(APPEND SANITIZER_COMMON_CFLAGS -O3) |
Chandler Carruth | 60ab090 | 2012-08-29 00:13:11 +0000 | [diff] [blame] | 208 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 209 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 210 | # Determine if we should restrict stack frame sizes. |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 211 | # Stack frames on PowerPC and Mips and in debug biuld can be much larger than |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 212 | # anticipated. |
| 213 | # FIXME: Fix all sanitizers and add -Wframe-larger-than to |
| 214 | # SANITIZER_COMMON_FLAGS |
| 215 | if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 216 | AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 217 | set(SANITIZER_LIMIT_FRAME_SIZE TRUE) |
| 218 | else() |
| 219 | set(SANITIZER_LIMIT_FRAME_SIZE FALSE) |
| 220 | endif() |
| 221 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 222 | # Build sanitizer runtimes with debug info. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 223 | if(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 224 | list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only) |
| 225 | elseif(COMPILER_RT_HAS_G_FLAG) |
| 226 | list(APPEND SANITIZER_COMMON_CFLAGS -g) |
| 227 | elseif(COMPILER_RT_HAS_Zi_FLAG) |
| 228 | list(APPEND SANITIZER_COMMON_CFLAGS /Zi) |
Chandler Carruth | 60ab090 | 2012-08-29 00:13:11 +0000 | [diff] [blame] | 229 | endif() |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 230 | |
| 231 | # Turn off several warnings. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 232 | append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS) |
| 233 | append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS) |
| 234 | append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS) |
| 235 | append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS) |
| 236 | append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS) |
| 237 | append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS) |
| 238 | append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS) |
| 239 | append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS) |
| 240 | append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 241 | |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 242 | # Warnings to turn off for all libraries, not just sanitizers. |
| 243 | append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS) |
| 244 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 245 | if(APPLE AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9") |
| 246 | # Mac OS X prior to 10.9 had problems with exporting symbols from |
| 247 | # libc++/libc++abi. |
| 248 | set(SANITIZER_CAN_USE_CXXABI FALSE) |
Pirama Arumuga Nainar | c58a436 | 2016-09-19 23:00:23 -0700 | [diff] [blame] | 249 | elseif(MSVC) |
| 250 | set(SANITIZER_CAN_USE_CXXABI FALSE) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 251 | else() |
| 252 | set(SANITIZER_CAN_USE_CXXABI TRUE) |
Alexey Samsonov | 0f7d4a4 | 2012-09-05 09:00:03 +0000 | [diff] [blame] | 253 | endif() |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 254 | pythonize_bool(SANITIZER_CAN_USE_CXXABI) |
Chandler Carruth | 60ab090 | 2012-08-29 00:13:11 +0000 | [diff] [blame] | 255 | |
Alexey Samsonov | 2a529ad | 2013-04-11 15:49:52 +0000 | [diff] [blame] | 256 | add_subdirectory(include) |
| 257 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 258 | set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx) |
| 259 | if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/) |
| 260 | set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE) |
| 261 | else() |
| 262 | set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE) |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 263 | endif() |
Chandler Carruth | d865fec | 2012-08-29 02:27:54 +0000 | [diff] [blame] | 264 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 265 | set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld) |
| 266 | if(EXISTS ${COMPILER_RT_LLD_PATH}/) |
| 267 | set(COMPILER_RT_HAS_LLD_SOURCES TRUE) |
| 268 | else() |
| 269 | set(COMPILER_RT_HAS_LLD_SOURCES FALSE) |
| 270 | endif() |
| 271 | pythonize_bool(COMPILER_RT_HAS_LLD_SOURCES) |
| 272 | |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 273 | add_subdirectory(lib) |
| 274 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 275 | if(COMPILER_RT_INCLUDE_TESTS) |
| 276 | add_subdirectory(unittests) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame] | 277 | add_subdirectory(test) |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 278 | endif() |