David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.11) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2 | |
David Benjamin | 6979c7e | 2017-12-04 17:19:49 -0500 | [diff] [blame] | 3 | # Report AppleClang separately from Clang. Their version numbers are different. |
| 4 | # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html |
| 5 | if(POLICY CMP0025) |
| 6 | cmake_policy(SET CMP0025 NEW) |
| 7 | endif() |
| 8 | |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 9 | # Defer enabling C and CXX languages. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 10 | project(BoringSSL NONE) |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 11 | |
| 12 | if(WIN32) |
| 13 | # On Windows, prefer cl over gcc if both are available. By default most of |
| 14 | # the CMake generators prefer gcc, even on Windows. |
| 15 | set(CMAKE_GENERATOR_CC cl) |
| 16 | endif() |
| 17 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 18 | include(sources.cmake) |
| 19 | |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 20 | enable_language(C) |
| 21 | enable_language(CXX) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 22 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 23 | # This is a dummy target which all other targets depend on (manually - see other |
| 24 | # CMakeLists.txt files). This gives us a hook to add any targets which need to |
| 25 | # run before all other targets. |
| 26 | add_custom_target(global_target) |
| 27 | |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 28 | if(ANDROID) |
| 29 | # Android-NDK CMake files reconfigure the path and so Go and Perl won't be |
| 30 | # found. However, ninja will still find them in $PATH if we just name them. |
Tamas Berghammer | 5693e42 | 2016-05-19 14:28:14 +0100 | [diff] [blame] | 31 | if(NOT PERL_EXECUTABLE) |
| 32 | set(PERL_EXECUTABLE "perl") |
| 33 | endif() |
| 34 | if(NOT GO_EXECUTABLE) |
| 35 | set(GO_EXECUTABLE "go") |
| 36 | endif() |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 37 | else() |
| 38 | find_package(Perl REQUIRED) |
| 39 | find_program(GO_EXECUTABLE go) |
| 40 | endif() |
David Benjamin | 3ce3c36 | 2015-02-23 13:06:19 -0500 | [diff] [blame] | 41 | |
David Benjamin | 17d553d | 2018-12-21 17:58:36 -0600 | [diff] [blame] | 42 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
Adam Langley | 9dfaf25 | 2019-01-04 07:53:25 -0800 | [diff] [blame^] | 43 | find_package(PkgConfig QUIET) |
| 44 | if (PkgConfig_FOUND) |
| 45 | pkg_check_modules(LIBUNWIND libunwind-generic) |
| 46 | if(LIBUNWIND_FOUND) |
| 47 | add_definitions(-DBORINGSSL_HAVE_LIBUNWIND) |
| 48 | else() |
| 49 | message("libunwind not found. Disabling unwind tests.") |
| 50 | endif() |
David Benjamin | 17d553d | 2018-12-21 17:58:36 -0600 | [diff] [blame] | 51 | else() |
Adam Langley | 9dfaf25 | 2019-01-04 07:53:25 -0800 | [diff] [blame^] | 52 | message("pkgconfig not found. Disabling unwind tests.") |
David Benjamin | 17d553d | 2018-12-21 17:58:36 -0600 | [diff] [blame] | 53 | endif() |
| 54 | endif() |
| 55 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 56 | if(NOT GO_EXECUTABLE) |
David Benjamin | d27eda0 | 2015-03-05 01:19:27 -0500 | [diff] [blame] | 57 | message(FATAL_ERROR "Could not find Go") |
| 58 | endif() |
| 59 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 60 | if(USE_CUSTOM_LIBCXX) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 61 | set(BORINGSSL_ALLOW_CXX_RUNTIME 1) |
| 62 | endif() |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 63 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 64 | if(BORINGSSL_ALLOW_CXX_RUNTIME) |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 65 | add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) |
| 66 | endif() |
| 67 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 68 | if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS) |
| 69 | add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}) |
David Benjamin | 8c23d3a | 2018-11-25 15:58:02 -0600 | [diff] [blame] | 70 | # CMake automatically connects include_directories to the NASM command-line, |
| 71 | # but not add_definitions. |
| 72 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}") |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 73 | |
| 74 | # Use "symbol_prefix_include" to store generated header files |
| 75 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include) |
| 76 | add_custom_command( |
| 77 | OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h |
| 78 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 79 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc |
| 80 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include |
| 81 | COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS} |
| 82 | DEPENDS util/make_prefix_headers.go |
| 83 | ${CMAKE_BINARY_DIR}/${BORINGSSL_PREFIX_SYMBOLS}) |
| 84 | |
| 85 | # add_dependencies needs a target, not a file, so we add an intermediate |
| 86 | # target. |
| 87 | add_custom_target( |
| 88 | boringssl_prefix_symbols |
| 89 | DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h |
| 90 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 91 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc) |
| 92 | add_dependencies(global_target boringssl_prefix_symbols) |
| 93 | elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS) |
| 94 | message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS") |
| 95 | endif() |
| 96 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 97 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 98 | set(CLANG 1) |
| 99 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 100 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 101 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 102 | # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 103 | # primarily on our normal Clang one. |
| 104 | set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 105 | if(MSVC) |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 106 | # clang-cl sets different default warnings than clang. It also treats -Wall |
| 107 | # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. |
| 108 | # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 |
| 109 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 110 | # googletest suppresses warning C4996 via a pragma, but clang-cl does not |
| 111 | # honor it. Suppress it here to compensate. See https://crbug.com/772117. |
| 112 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations") |
| 113 | else() |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 114 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 115 | endif() |
| 116 | |
| 117 | if(CLANG) |
David Benjamin | 9fb6fea | 2017-07-31 14:03:38 -0400 | [diff] [blame] | 118 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics") |
Adam Langley | 5c38c05 | 2017-04-28 14:47:06 -0700 | [diff] [blame] | 119 | else() |
| 120 | # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls |
| 121 | # and declare that the code is trying to free a stack pointer. |
| 122 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") |
David Benjamin | 9b7d836 | 2016-08-29 14:59:31 -0400 | [diff] [blame] | 123 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 124 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 125 | if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION) |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 126 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough") |
| 127 | endif() |
| 128 | |
Adam Langley | 0186787 | 2016-06-30 14:16:59 -0700 | [diff] [blame] | 129 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 130 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations") |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 131 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 132 | if(NOT MSVC) |
| 133 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Daniel Wagner-Hall | 3b358b2 | 2017-10-16 20:58:08 +0100 | [diff] [blame] | 134 | if(APPLE) |
| 135 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 136 | endif() |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 137 | if(NOT BORINGSSL_ALLOW_CXX_RUNTIME) |
| 138 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
| 139 | endif() |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 140 | endif() |
| 141 | |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 142 | # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes |
| 143 | # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the |
| 144 | # spelling for both and -Wmissing-declarations is some other warning. |
| 145 | # |
| 146 | # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options |
| 147 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes |
| 148 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 149 | if(CLANG) |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 150 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 151 | endif() |
Daniel Wagner-Hall | 1015432 | 2017-10-09 20:09:43 +0100 | [diff] [blame] | 152 | |
| 153 | if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION) |
| 154 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds") |
| 155 | endif() |
| 156 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 157 | elseif(MSVC) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 158 | set(MSVC_DISABLED_WARNINGS_LIST |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 159 | "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not |
| 160 | # explicitly handled by a case label |
| 161 | # Disable this because it flags even when there is a default. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 162 | "C4100" # 'exarg' : unreferenced formal parameter |
| 163 | "C4127" # conditional expression is constant |
| 164 | "C4200" # nonstandard extension used : zero-sized array in |
| 165 | # struct/union. |
David Benjamin | ffb1107 | 2016-11-13 10:32:10 +0900 | [diff] [blame] | 166 | "C4204" # nonstandard extension used: non-constant aggregate initializer |
| 167 | "C4221" # nonstandard extension used : 'identifier' : cannot be |
| 168 | # initialized using address of automatic variable |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 169 | "C4242" # 'function' : conversion from 'int' to 'uint8_t', |
| 170 | # possible loss of data |
| 171 | "C4244" # 'function' : conversion from 'int' to 'uint8_t', |
| 172 | # possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 173 | "C4267" # conversion from 'size_t' to 'int', possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 174 | "C4371" # layout of class may have changed from a previous version of the |
| 175 | # compiler due to better packing of member '...' |
| 176 | "C4388" # signed/unsigned mismatch |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 177 | "C4296" # '>=' : expression is always true |
| 178 | "C4350" # behavior change: 'std::_Wrap_alloc...' |
| 179 | "C4365" # '=' : conversion from 'size_t' to 'int', |
| 180 | # signed/unsigned mismatch |
| 181 | "C4389" # '!=' : signed/unsigned mismatch |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 182 | "C4464" # relative include path contains '..' |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 183 | "C4510" # 'argument' : default constructor could not be generated |
| 184 | "C4512" # 'argument' : assignment operator could not be generated |
| 185 | "C4514" # 'function': unreferenced inline function has been removed |
| 186 | "C4548" # expression before comma has no effect; expected expression with |
| 187 | # side-effect" caused by FD_* macros. |
| 188 | "C4610" # struct 'argument' can never be instantiated - user defined |
| 189 | # constructor required. |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 190 | "C4623" # default constructor was implicitly defined as deleted |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 191 | "C4625" # copy constructor could not be generated because a base class |
| 192 | # copy constructor is inaccessible or deleted |
| 193 | "C4626" # assignment operator could not be generated because a base class |
| 194 | # assignment operator is inaccessible or deleted |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 195 | "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with |
| 196 | # '0' for 'directives' |
| 197 | # Disable this because GTest uses it everywhere. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 198 | "C4706" # assignment within conditional expression |
| 199 | "C4710" # 'function': function not inlined |
| 200 | "C4711" # function 'function' selected for inline expansion |
| 201 | "C4800" # 'int' : forcing value to bool 'true' or 'false' |
| 202 | # (performance warning) |
| 203 | "C4820" # 'bytes' bytes padding added after construct 'member_name' |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 204 | "C5026" # move constructor was implicitly defined as deleted |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 205 | "C5027" # move assignment operator was implicitly defined as deleted |
Adam Vartanian | 189270c | 2018-05-22 13:50:44 +0100 | [diff] [blame] | 206 | "C5045" # Compiler will insert Spectre mitigation for memory load if |
| 207 | # /Qspectre switch specified |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 208 | ) |
| 209 | set(MSVC_LEVEL4_WARNINGS_LIST |
| 210 | # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header |
| 211 | "C4265" # class has virtual functions, but destructor is not virtual |
| 212 | ) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 213 | string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR |
| 214 | ${MSVC_DISABLED_WARNINGS_LIST}) |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 215 | string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR |
| 216 | ${MSVC_LEVEL4_WARNINGS_LIST}) |
sphawk | 3ab1a69 | 2018-03-11 19:20:51 +0900 | [diff] [blame] | 217 | set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
| 218 | set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
David Benjamin | e2568c4 | 2017-08-16 15:25:27 -0400 | [diff] [blame] | 219 | endif() |
| 220 | |
| 221 | if(WIN32) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 222 | add_definitions(-D_HAS_EXCEPTIONS=0) |
Brian Smith | a87de9b | 2015-01-28 20:34:47 -0800 | [diff] [blame] | 223 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
David Benjamin | 0e434b9 | 2015-04-02 13:20:01 -0400 | [diff] [blame] | 224 | add_definitions(-DNOMINMAX) |
David Benjamin | 9b6ff44 | 2017-06-15 20:44:30 -0400 | [diff] [blame] | 225 | # Allow use of fopen. |
| 226 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Guillaume Egles | 791f282 | 2018-06-29 10:44:36 -0700 | [diff] [blame] | 227 | # VS 2017 and higher supports STL-only warning suppressions. Manually add to |
| 228 | # C++ only to work around a CMake quoting bug when using NASM with the Visual |
David Benjamin | e7b2b13 | 2018-07-06 14:46:30 -0400 | [diff] [blame] | 229 | # Studio generator. This will be fixed in CMake 3.13.0. See |
| 230 | # https://gitlab.kitware.com/cmake/cmake/merge_requests/2179 |
Guillaume Egles | 791f282 | 2018-06-29 10:44:36 -0700 | [diff] [blame] | 231 | add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_STL_EXTRA_DISABLED_WARNINGS=4774\ 4987>) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 232 | endif() |
| 233 | |
David Benjamin | b826c0d | 2015-02-28 00:00:44 -0500 | [diff] [blame] | 234 | if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 235 | CLANG) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 236 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
| 237 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") |
Adam Langley | 07100c6 | 2015-01-16 15:20:54 -0800 | [diff] [blame] | 238 | endif() |
| 239 | |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 240 | if(CMAKE_COMPILER_IS_GNUCXX) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 241 | if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG) |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 242 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") |
| 243 | else() |
| 244 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") |
| 245 | endif() |
| 246 | endif() |
| 247 | |
| 248 | # pthread_rwlock_t requires a feature flag. |
| 249 | if(NOT WIN32) |
| 250 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
Adam Langley | 6f2e733 | 2015-05-15 12:01:29 -0700 | [diff] [blame] | 251 | endif() |
| 252 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 253 | if(FUZZ) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 254 | if(NOT CLANG) |
Alessandro Ghedini | b6f6927 | 2016-09-28 22:14:01 +0100 | [diff] [blame] | 255 | message(FATAL_ERROR "You need to build with Clang for fuzzing to work") |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 256 | endif() |
| 257 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 258 | if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0") |
| 259 | message(FATAL_ERROR "You need Clang ≥ 6.0.0") |
| 260 | endif() |
| 261 | |
David Benjamin | ec978dd | 2016-11-04 18:59:33 -0400 | [diff] [blame] | 262 | add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 263 | set(RUNNER_ARGS "-deterministic") |
| 264 | |
| 265 | if(NOT NO_FUZZER_MODE) |
| 266 | add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE) |
| 267 | set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json") |
| 268 | endif() |
David Benjamin | bc5b2a2 | 2016-03-01 22:57:32 -0500 | [diff] [blame] | 269 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 270 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
| 271 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 272 | endif() |
| 273 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 274 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 275 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 276 | if(BUILD_SHARED_LIBS) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 277 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 278 | # Enable position-independent code globally. This is needed because |
| 279 | # some library targets are OBJECT libraries. |
| 280 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
David Benjamin | 507c1ee | 2015-01-28 00:50:21 -0500 | [diff] [blame] | 281 | endif() |
| 282 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 283 | if(MSAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 284 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 285 | message(FATAL_ERROR "Cannot enable MSAN unless using Clang") |
| 286 | endif() |
| 287 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 288 | if(ASAN) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 289 | message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") |
| 290 | endif() |
| 291 | |
| 292 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 293 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Adam Langley | e77c27d | 2018-09-07 11:20:23 -0700 | [diff] [blame] | 294 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 295 | endif() |
| 296 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 297 | if(ASAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 298 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 299 | message(FATAL_ERROR "Cannot enable ASAN unless using Clang") |
| 300 | endif() |
| 301 | |
David Benjamin | 0d3c963 | 2017-02-28 14:58:00 -0500 | [diff] [blame] | 302 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
| 303 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 304 | endif() |
| 305 | |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 306 | if(CFI) |
| 307 | if(NOT CLANG) |
| 308 | message(FATAL_ERROR "Cannot enable CFI unless using Clang") |
| 309 | endif() |
| 310 | |
David Benjamin | 6650898 | 2018-09-22 16:19:15 -0500 | [diff] [blame] | 311 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
| 312 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 313 | # We use Chromium's copy of clang, which requires -fuse-ld=lld if building |
| 314 | # with -flto. That, in turn, can't handle -ggdb. |
| 315 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 316 | string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 317 | string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 318 | # -flto causes object files to contain LLVM bitcode. Mixing those with |
| 319 | # assembly output in the same static library breaks the linker. |
| 320 | set(OPENSSL_NO_ASM "1") |
| 321 | endif() |
| 322 | |
David Benjamin | 5852cfc | 2018-07-19 17:50:45 -0400 | [diff] [blame] | 323 | if(TSAN) |
| 324 | if(NOT CLANG) |
| 325 | message(FATAL_ERROR "Cannot enable TSAN unless using Clang") |
| 326 | endif() |
| 327 | |
| 328 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") |
| 329 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") |
| 330 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") |
| 331 | endif() |
| 332 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 333 | if(GCOV) |
David Benjamin | d035ab3 | 2016-12-27 12:15:56 -0500 | [diff] [blame] | 334 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 335 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") |
| 336 | endif() |
| 337 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 338 | if(FIPS) |
| 339 | add_definitions(-DBORINGSSL_FIPS) |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 340 | if(FIPS_BREAK_TEST) |
| 341 | add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1") |
| 342 | endif() |
| 343 | # Delocate does not work for ASan and MSan builds. |
| 344 | if(NOT ASAN AND NOT MSAN) |
| 345 | set(FIPS_DELOCATE "1") |
| 346 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 347 | endif() |
| 348 | |
David Benjamin | 6291af4 | 2018-03-23 13:49:27 -0400 | [diff] [blame] | 349 | if(OPENSSL_SMALL) |
| 350 | add_definitions(-DOPENSSL_SMALL) |
| 351 | endif() |
| 352 | |
Adam Langley | a6a049a | 2018-12-06 17:15:58 -0800 | [diff] [blame] | 353 | if(CONSTANT_TIME_VALIDATION) |
| 354 | add_definitions(-DBORINGSSL_CONSTANT_TIME_VALIDATION) |
| 355 | # Asserts will often test secret data. |
| 356 | add_definitions(-DNDEBUG) |
| 357 | endif() |
| 358 | |
David Benjamin | 5baee45 | 2018-09-13 16:37:28 -0500 | [diff] [blame] | 359 | function(go_executable dest package) |
| 360 | set(godeps "${CMAKE_SOURCE_DIR}/util/godeps.go") |
| 361 | if(${CMAKE_VERSION} VERSION_LESS "3.7" OR |
| 362 | NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") |
| 363 | # The DEPFILE parameter to add_custom_command is new as of CMake 3.7 and |
| 364 | # only works with Ninja. Query the sources at configure time. Additionally, |
| 365 | # everything depends on go.mod. That affects what external packages to use. |
| 366 | execute_process(COMMAND ${GO_EXECUTABLE} run ${godeps} -format cmake |
| 367 | -pkg ${package} |
| 368 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 369 | OUTPUT_VARIABLE sources |
| 370 | RESULT_VARIABLE godeps_result) |
| 371 | add_custom_command(OUTPUT ${dest} |
| 372 | COMMAND ${GO_EXECUTABLE} build |
| 373 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 374 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 375 | DEPENDS ${sources} ${CMAKE_SOURCE_DIR}/go.mod) |
| 376 | else() |
| 377 | # Ninja expects the target in the depfile to match the output. This is a |
| 378 | # relative path from the build directory. |
| 379 | string(LENGTH "${CMAKE_BINARY_DIR}" root_dir_length) |
| 380 | math(EXPR root_dir_length "${root_dir_length} + 1") |
| 381 | string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}" ${root_dir_length} -1 target) |
| 382 | set(target "${target}/${dest}") |
| 383 | |
| 384 | set(depfile "${CMAKE_CURRENT_BINARY_DIR}/${dest}.d") |
| 385 | add_custom_command(OUTPUT ${dest} |
| 386 | COMMAND ${GO_EXECUTABLE} build |
| 387 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 388 | COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile |
| 389 | -target ${target} -pkg ${package} -out ${depfile} |
| 390 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 391 | DEPENDS ${godeps} ${CMAKE_SOURCE_DIR}/go.mod |
| 392 | DEPFILE ${depfile}) |
| 393 | endif() |
| 394 | endfunction() |
| 395 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 396 | # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an |
| 397 | # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR |
| 398 | # alone, and expects all architecture-specific logic to be conditioned within |
| 399 | # the source files rather than the build. This does not work for our assembly |
| 400 | # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture |
| 401 | # builds. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 402 | if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 403 | list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 404 | if(NOT ${NUM_ARCHES} EQUAL 1) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 405 | message(FATAL_ERROR "Universal binaries not supported.") |
| 406 | endif() |
| 407 | list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) |
| 408 | endif() |
| 409 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 410 | if(OPENSSL_NO_ASM) |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 411 | add_definitions(-DOPENSSL_NO_ASM) |
| 412 | set(ARCH "generic") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 413 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 414 | set(ARCH "x86_64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 415 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 416 | set(ARCH "x86_64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 417 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 418 | # cmake reports AMD64 on Windows, but we might be building for 32-bit. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 419 | if(CMAKE_CL_64) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 420 | set(ARCH "x86_64") |
| 421 | else() |
| 422 | set(ARCH "x86") |
| 423 | endif() |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 424 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 425 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 426 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 427 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 428 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 429 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 430 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 431 | set(ARCH "aarch64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 432 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 433 | set(ARCH "aarch64") |
Junghoon Jang | e8ba1e3 | 2018-11-15 10:20:42 +0900 | [diff] [blame] | 434 | # Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture. |
| 435 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64e") |
| 436 | set(ARCH "aarch64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 437 | elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 438 | set(ARCH "arm") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 439 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 440 | # Just to avoid the “unknown processor” error. |
| 441 | set(ARCH "generic") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 442 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 443 | set(ARCH "ppc64le") |
| 444 | else() |
| 445 | message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 446 | endif() |
| 447 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 448 | if(ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm") |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 449 | # The third-party Android-NDK CMake files somehow fail to set the -march flag |
| 450 | # for assembly files. Without this flag, the compiler believes that it's |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 451 | # building for ARMv5. |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 452 | set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 453 | endif() |
| 454 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 455 | if(${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 456 | # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X, |
| 457 | # but clang defaults to 64-bit builds on OS X unless otherwise told. |
| 458 | # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3. |
| 459 | set(ARCH "x86_64") |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 460 | endif() |
| 461 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 462 | if(USE_CUSTOM_LIBCXX) |
| 463 | if(NOT CLANG) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 464 | message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") |
| 465 | endif() |
| 466 | |
| 467 | # CMAKE_CXX_FLAGS ends up in the linker flags as well, so use |
| 468 | # add_compile_options. There does not appear to be a way to set |
| 469 | # language-specific compile-only flags. |
| 470 | add_compile_options("-nostdinc++") |
| 471 | set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++") |
| 472 | include_directories( |
| 473 | SYSTEM |
| 474 | util/bot/libcxx/include |
| 475 | util/bot/libcxxabi/include |
| 476 | ) |
| 477 | |
| 478 | # This is patterned after buildtools/third_party/libc++/BUILD.gn and |
| 479 | # buildtools/third_party/libc++abi/BUILD.gn in Chromium. |
| 480 | |
| 481 | file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp") |
| 482 | file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp") |
| 483 | |
| 484 | # This file is meant for exception-less builds. |
| 485 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp") |
| 486 | # libc++ also defines new and delete. |
| 487 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 488 | if(TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 489 | # ThreadSanitizer tries to intercept these symbols. Skip them to avoid |
| 490 | # symbol conflicts. |
| 491 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp") |
| 492 | endif() |
| 493 | |
| 494 | add_library(libcxxabi ${LIBCXXABI_SOURCES}) |
| 495 | target_compile_definitions( |
| 496 | libcxxabi PRIVATE |
| 497 | -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS |
| 498 | ) |
| 499 | set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough") |
| 500 | |
| 501 | add_library(libcxx ${LIBCXX_SOURCES}) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 502 | if(ASAN OR MSAN OR TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 503 | # Sanitizers try to intercept new and delete. |
| 504 | target_compile_definitions( |
| 505 | libcxx PRIVATE |
| 506 | -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS |
| 507 | ) |
| 508 | endif() |
| 509 | target_compile_definitions( |
| 510 | libcxx PRIVATE |
| 511 | -D_LIBCPP_BUILDING_LIBRARY |
| 512 | -DLIBCXX_BUILDING_LIBCXXABI |
| 513 | ) |
| 514 | target_link_libraries(libcxx libcxxabi) |
| 515 | endif() |
| 516 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 517 | # Add minimal googletest targets. The provided one has many side-effects, and |
| 518 | # googletest has a very straightforward build. |
Marek Gilbert | 11850d5 | 2018-01-03 23:07:58 -0800 | [diff] [blame] | 519 | add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc) |
| 520 | target_include_directories(boringssl_gtest PRIVATE third_party/googletest) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 521 | |
| 522 | include_directories(third_party/googletest/include) |
| 523 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 524 | # Declare a dummy target to build all unit tests. Test targets should inject |
| 525 | # themselves as dependencies next to the target definition. |
| 526 | add_custom_target(all_tests) |
| 527 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 528 | add_custom_command( |
| 529 | OUTPUT crypto_test_data.cc |
| 530 | COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} > |
| 531 | ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc |
| 532 | DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA} |
| 533 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 534 | |
| 535 | add_library(crypto_test_data OBJECT crypto_test_data.cc) |
| 536 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 537 | add_subdirectory(crypto) |
| 538 | add_subdirectory(ssl) |
| 539 | add_subdirectory(ssl/test) |
Martin Kreichgauer | 118355c | 2017-05-12 15:34:45 -0700 | [diff] [blame] | 540 | add_subdirectory(fipstools) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 541 | add_subdirectory(tool) |
Adam Langley | c004dfc | 2015-02-03 10:45:12 -0800 | [diff] [blame] | 542 | add_subdirectory(decrepit) |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 543 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 544 | if(FUZZ) |
| 545 | add_subdirectory(fuzz) |
| 546 | endif() |
| 547 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 548 | if(NOT ${CMAKE_VERSION} VERSION_LESS "3.2") |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 549 | # USES_TERMINAL is only available in CMake 3.2 or later. |
| 550 | set(MAYBE_USES_TERMINAL USES_TERMINAL) |
| 551 | endif() |
| 552 | |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 553 | if(UNIX AND NOT APPLE AND NOT ANDROID) |
| 554 | set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>) |
| 555 | endif() |
| 556 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 557 | add_custom_target( |
| 558 | run_tests |
| 559 | COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir |
| 560 | ${CMAKE_BINARY_DIR} |
Adam Langley | d5c72c8 | 2016-09-23 16:43:17 -0700 | [diff] [blame] | 561 | COMMAND cd ssl/test/runner && |
| 562 | ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim> |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 563 | ${HANDSHAKER_ARGS} ${RUNNER_ARGS} |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 564 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
Steven Valdez | e5388e0 | 2018-08-01 16:54:48 -0400 | [diff] [blame] | 565 | DEPENDS all_tests bssl_shim handshaker |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 566 | ${MAYBE_USES_TERMINAL}) |