David Benjamin | 9662843 | 2017-01-19 19:05:47 -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. |
| 10 | project (BoringSSL NONE) |
| 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 | |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 23 | if(ANDROID) |
| 24 | # Android-NDK CMake files reconfigure the path and so Go and Perl won't be |
| 25 | # 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] | 26 | if(NOT PERL_EXECUTABLE) |
| 27 | set(PERL_EXECUTABLE "perl") |
| 28 | endif() |
| 29 | if(NOT GO_EXECUTABLE) |
| 30 | set(GO_EXECUTABLE "go") |
| 31 | endif() |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 32 | else() |
| 33 | find_package(Perl REQUIRED) |
| 34 | find_program(GO_EXECUTABLE go) |
| 35 | endif() |
David Benjamin | 3ce3c36 | 2015-02-23 13:06:19 -0500 | [diff] [blame] | 36 | |
David Benjamin | d27eda0 | 2015-03-05 01:19:27 -0500 | [diff] [blame] | 37 | if (NOT GO_EXECUTABLE) |
| 38 | message(FATAL_ERROR "Could not find Go") |
| 39 | endif() |
| 40 | |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 41 | if (BORINGSSL_ALLOW_CXX_RUNTIME) |
| 42 | add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) |
| 43 | endif() |
| 44 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 45 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 46 | set(CLANG 1) |
| 47 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 48 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 49 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 50 | # 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] | 51 | # primarily on our normal Clang one. |
| 52 | 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] | 53 | if(MSVC) |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 54 | # clang-cl sets different default warnings than clang. It also treats -Wall |
| 55 | # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. |
| 56 | # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 |
| 57 | 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] | 58 | # googletest suppresses warning C4996 via a pragma, but clang-cl does not |
| 59 | # honor it. Suppress it here to compensate. See https://crbug.com/772117. |
| 60 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations") |
| 61 | else() |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 62 | 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] | 63 | endif() |
| 64 | |
| 65 | if(CLANG) |
David Benjamin | 9fb6fea | 2017-07-31 14:03:38 -0400 | [diff] [blame] | 66 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics") |
Adam Langley | 5c38c05 | 2017-04-28 14:47:06 -0700 | [diff] [blame] | 67 | else() |
| 68 | # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls |
| 69 | # and declare that the code is trying to free a stack pointer. |
| 70 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") |
David Benjamin | 9b7d836 | 2016-08-29 14:59:31 -0400 | [diff] [blame] | 71 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 72 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 73 | 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] | 74 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough") |
| 75 | endif() |
| 76 | |
Adam Langley | 0186787 | 2016-06-30 14:16:59 -0700 | [diff] [blame] | 77 | 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] | 78 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations") |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 79 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 80 | if(NOT MSVC) |
| 81 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Daniel Wagner-Hall | 3b358b2 | 2017-10-16 20:58:08 +0100 | [diff] [blame] | 82 | if(APPLE) |
| 83 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 84 | endif() |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 85 | if(NOT BORINGSSL_ALLOW_CXX_RUNTIME) |
| 86 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
| 87 | endif() |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 88 | endif() |
| 89 | |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 90 | # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes |
| 91 | # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the |
| 92 | # spelling for both and -Wmissing-declarations is some other warning. |
| 93 | # |
| 94 | # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options |
| 95 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes |
| 96 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 97 | if(CLANG) |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 98 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 99 | endif() |
Daniel Wagner-Hall | 1015432 | 2017-10-09 20:09:43 +0100 | [diff] [blame] | 100 | |
| 101 | if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION) |
| 102 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds") |
| 103 | endif() |
| 104 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 105 | elseif(MSVC) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 106 | set(MSVC_DISABLED_WARNINGS_LIST |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 107 | "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not |
| 108 | # explicitly handled by a case label |
| 109 | # Disable this because it flags even when there is a default. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 110 | "C4100" # 'exarg' : unreferenced formal parameter |
| 111 | "C4127" # conditional expression is constant |
| 112 | "C4200" # nonstandard extension used : zero-sized array in |
| 113 | # struct/union. |
David Benjamin | ffb1107 | 2016-11-13 10:32:10 +0900 | [diff] [blame] | 114 | "C4204" # nonstandard extension used: non-constant aggregate initializer |
| 115 | "C4221" # nonstandard extension used : 'identifier' : cannot be |
| 116 | # initialized using address of automatic variable |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 117 | "C4242" # 'function' : conversion from 'int' to 'uint8_t', |
| 118 | # possible loss of data |
| 119 | "C4244" # 'function' : conversion from 'int' to 'uint8_t', |
| 120 | # possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 121 | "C4267" # conversion from 'size_t' to 'int', possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 122 | "C4371" # layout of class may have changed from a previous version of the |
| 123 | # compiler due to better packing of member '...' |
| 124 | "C4388" # signed/unsigned mismatch |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 125 | "C4296" # '>=' : expression is always true |
| 126 | "C4350" # behavior change: 'std::_Wrap_alloc...' |
| 127 | "C4365" # '=' : conversion from 'size_t' to 'int', |
| 128 | # signed/unsigned mismatch |
| 129 | "C4389" # '!=' : signed/unsigned mismatch |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 130 | "C4464" # relative include path contains '..' |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 131 | "C4510" # 'argument' : default constructor could not be generated |
| 132 | "C4512" # 'argument' : assignment operator could not be generated |
| 133 | "C4514" # 'function': unreferenced inline function has been removed |
| 134 | "C4548" # expression before comma has no effect; expected expression with |
| 135 | # side-effect" caused by FD_* macros. |
| 136 | "C4610" # struct 'argument' can never be instantiated - user defined |
| 137 | # constructor required. |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 138 | "C4623" # default constructor was implicitly defined as deleted |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 139 | "C4625" # copy constructor could not be generated because a base class |
| 140 | # copy constructor is inaccessible or deleted |
| 141 | "C4626" # assignment operator could not be generated because a base class |
| 142 | # assignment operator is inaccessible or deleted |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 143 | "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with |
| 144 | # '0' for 'directives' |
| 145 | # Disable this because GTest uses it everywhere. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 146 | "C4706" # assignment within conditional expression |
| 147 | "C4710" # 'function': function not inlined |
| 148 | "C4711" # function 'function' selected for inline expansion |
| 149 | "C4800" # 'int' : forcing value to bool 'true' or 'false' |
| 150 | # (performance warning) |
| 151 | "C4820" # 'bytes' bytes padding added after construct 'member_name' |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 152 | "C5026" # move constructor was implicitly defined as deleted |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 153 | "C5027" # move assignment operator was implicitly defined as deleted |
| 154 | ) |
| 155 | set(MSVC_LEVEL4_WARNINGS_LIST |
| 156 | # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header |
| 157 | "C4265" # class has virtual functions, but destructor is not virtual |
| 158 | ) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 159 | string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR |
| 160 | ${MSVC_DISABLED_WARNINGS_LIST}) |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 161 | string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR |
| 162 | ${MSVC_LEVEL4_WARNINGS_LIST}) |
sphawk | 3ab1a69 | 2018-03-11 19:20:51 +0900 | [diff] [blame] | 163 | set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
| 164 | 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] | 165 | endif() |
| 166 | |
| 167 | if(WIN32) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 168 | add_definitions(-D_HAS_EXCEPTIONS=0) |
Brian Smith | a87de9b | 2015-01-28 20:34:47 -0800 | [diff] [blame] | 169 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
David Benjamin | 0e434b9 | 2015-04-02 13:20:01 -0400 | [diff] [blame] | 170 | add_definitions(-DNOMINMAX) |
David Benjamin | 9b6ff44 | 2017-06-15 20:44:30 -0400 | [diff] [blame] | 171 | # Allow use of fopen. |
| 172 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 173 | # VS 2017 and higher supports STL-only warning suppressions. |
| 174 | add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987") |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 175 | endif() |
| 176 | |
David Benjamin | b826c0d | 2015-02-28 00:00:44 -0500 | [diff] [blame] | 177 | 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] | 178 | CLANG) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 179 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
| 180 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") |
Adam Langley | 07100c6 | 2015-01-16 15:20:54 -0800 | [diff] [blame] | 181 | endif() |
| 182 | |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 183 | if(CMAKE_COMPILER_IS_GNUCXX) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 184 | if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG) |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 185 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") |
| 186 | else() |
| 187 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") |
| 188 | endif() |
| 189 | endif() |
| 190 | |
| 191 | # pthread_rwlock_t requires a feature flag. |
| 192 | if(NOT WIN32) |
| 193 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
Adam Langley | 6f2e733 | 2015-05-15 12:01:29 -0700 | [diff] [blame] | 194 | endif() |
| 195 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 196 | if(FUZZ) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 197 | if(NOT CLANG) |
Alessandro Ghedini | b6f6927 | 2016-09-28 22:14:01 +0100 | [diff] [blame] | 198 | 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] | 199 | endif() |
| 200 | |
David Benjamin | ec978dd | 2016-11-04 18:59:33 -0400 | [diff] [blame] | 201 | add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 202 | set(RUNNER_ARGS "-deterministic") |
| 203 | |
| 204 | if(NOT NO_FUZZER_MODE) |
| 205 | add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE) |
| 206 | set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json") |
| 207 | endif() |
David Benjamin | bc5b2a2 | 2016-03-01 22:57:32 -0500 | [diff] [blame] | 208 | |
David Benjamin | 08ab59b | 2017-05-10 12:02:58 -0400 | [diff] [blame] | 209 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard") |
| 210 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard") |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 211 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") |
Adam Langley | 7104cc9 | 2015-11-10 15:00:51 -0800 | [diff] [blame] | 212 | link_directories(.) |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 213 | endif() |
| 214 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 215 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 216 | |
David Benjamin | 507c1ee | 2015-01-28 00:50:21 -0500 | [diff] [blame] | 217 | if (BUILD_SHARED_LIBS) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 218 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 219 | # Enable position-independent code globally. This is needed because |
| 220 | # some library targets are OBJECT libraries. |
| 221 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
David Benjamin | 507c1ee | 2015-01-28 00:50:21 -0500 | [diff] [blame] | 222 | endif() |
| 223 | |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 224 | if (MSAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 225 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 226 | message(FATAL_ERROR "Cannot enable MSAN unless using Clang") |
| 227 | endif() |
| 228 | |
| 229 | if (ASAN) |
| 230 | message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") |
| 231 | endif() |
| 232 | |
| 233 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 234 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 235 | set(OPENSSL_NO_ASM "1") |
| 236 | endif() |
| 237 | |
| 238 | if (ASAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 239 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 240 | message(FATAL_ERROR "Cannot enable ASAN unless using Clang") |
| 241 | endif() |
| 242 | |
David Benjamin | 0d3c963 | 2017-02-28 14:58:00 -0500 | [diff] [blame] | 243 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
| 244 | 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] | 245 | set(OPENSSL_NO_ASM "1") |
| 246 | endif() |
| 247 | |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 248 | if(CFI) |
| 249 | if(NOT CLANG) |
| 250 | message(FATAL_ERROR "Cannot enable CFI unless using Clang") |
| 251 | endif() |
| 252 | |
| 253 | # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers. |
| 254 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto") |
| 255 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto") |
| 256 | # We use Chromium's copy of clang, which requires -fuse-ld=lld if building |
| 257 | # with -flto. That, in turn, can't handle -ggdb. |
| 258 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 259 | string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 260 | string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 261 | # -flto causes object files to contain LLVM bitcode. Mixing those with |
| 262 | # assembly output in the same static library breaks the linker. |
| 263 | set(OPENSSL_NO_ASM "1") |
| 264 | endif() |
| 265 | |
David Benjamin | d035ab3 | 2016-12-27 12:15:56 -0500 | [diff] [blame] | 266 | if (GCOV) |
| 267 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 268 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") |
| 269 | endif() |
| 270 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 271 | if(FIPS) |
| 272 | add_definitions(-DBORINGSSL_FIPS) |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 273 | if(FIPS_BREAK_TEST) |
| 274 | add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1") |
| 275 | endif() |
| 276 | # Delocate does not work for ASan and MSan builds. |
| 277 | if(NOT ASAN AND NOT MSAN) |
| 278 | set(FIPS_DELOCATE "1") |
| 279 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 280 | endif() |
| 281 | |
David Benjamin | 6291af4 | 2018-03-23 13:49:27 -0400 | [diff] [blame] | 282 | if(OPENSSL_SMALL) |
| 283 | add_definitions(-DOPENSSL_SMALL) |
| 284 | endif() |
| 285 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 286 | # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an |
| 287 | # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR |
| 288 | # alone, and expects all architecture-specific logic to be conditioned within |
| 289 | # the source files rather than the build. This does not work for our assembly |
| 290 | # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture |
| 291 | # builds. |
| 292 | if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) |
| 293 | list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) |
| 294 | if (NOT ${NUM_ARCHES} EQUAL 1) |
| 295 | message(FATAL_ERROR "Universal binaries not supported.") |
| 296 | endif() |
| 297 | list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) |
| 298 | endif() |
| 299 | |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 300 | if (OPENSSL_NO_ASM) |
| 301 | add_definitions(-DOPENSSL_NO_ASM) |
| 302 | set(ARCH "generic") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 303 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
| 304 | set(ARCH "x86_64") |
| 305 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") |
| 306 | set(ARCH "x86_64") |
| 307 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") |
| 308 | # cmake reports AMD64 on Windows, but we might be building for 32-bit. |
| 309 | if (CMAKE_CL_64) |
| 310 | set(ARCH "x86_64") |
| 311 | else() |
| 312 | set(ARCH "x86") |
| 313 | endif() |
| 314 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") |
| 315 | set(ARCH "x86") |
| 316 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") |
| 317 | set(ARCH "x86") |
| 318 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") |
| 319 | set(ARCH "x86") |
| 320 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") |
| 321 | set(ARCH "aarch64") |
| 322 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") |
| 323 | set(ARCH "aarch64") |
| 324 | elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*") |
| 325 | set(ARCH "arm") |
| 326 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips") |
| 327 | # Just to avoid the “unknown processor” error. |
| 328 | set(ARCH "generic") |
| 329 | elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le") |
| 330 | set(ARCH "ppc64le") |
| 331 | else() |
| 332 | message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 333 | endif() |
| 334 | |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 335 | if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm") |
| 336 | # The third-party Android-NDK CMake files somehow fail to set the -march flag |
| 337 | # for assembly files. Without this flag, the compiler believes that it's |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 338 | # building for ARMv5. |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 339 | set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 340 | endif() |
| 341 | |
David Benjamin | f5beb88 | 2017-10-27 10:43:15 -0400 | [diff] [blame] | 342 | 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] | 343 | # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X, |
| 344 | # but clang defaults to 64-bit builds on OS X unless otherwise told. |
| 345 | # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3. |
| 346 | set(ARCH "x86_64") |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 347 | endif() |
| 348 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 349 | # Add minimal googletest targets. The provided one has many side-effects, and |
| 350 | # googletest has a very straightforward build. |
Marek Gilbert | 11850d5 | 2018-01-03 23:07:58 -0800 | [diff] [blame] | 351 | add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc) |
| 352 | target_include_directories(boringssl_gtest PRIVATE third_party/googletest) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 353 | |
| 354 | include_directories(third_party/googletest/include) |
| 355 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 356 | # Declare a dummy target to build all unit tests. Test targets should inject |
| 357 | # themselves as dependencies next to the target definition. |
| 358 | add_custom_target(all_tests) |
| 359 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 360 | add_custom_command( |
| 361 | OUTPUT crypto_test_data.cc |
| 362 | COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} > |
| 363 | ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc |
| 364 | DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA} |
| 365 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 366 | |
| 367 | add_library(crypto_test_data OBJECT crypto_test_data.cc) |
| 368 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 369 | add_subdirectory(crypto) |
Andres Erbsen | 5b280a8 | 2017-10-30 15:58:33 +0000 | [diff] [blame] | 370 | add_subdirectory(third_party/fiat) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 371 | add_subdirectory(ssl) |
| 372 | add_subdirectory(ssl/test) |
Martin Kreichgauer | 118355c | 2017-05-12 15:34:45 -0700 | [diff] [blame] | 373 | add_subdirectory(fipstools) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 374 | add_subdirectory(tool) |
Adam Langley | c004dfc | 2015-02-03 10:45:12 -0800 | [diff] [blame] | 375 | add_subdirectory(decrepit) |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 376 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 377 | if(FUZZ) |
David Benjamin | 1e5cb82 | 2017-05-10 16:07:56 -0400 | [diff] [blame] | 378 | if(LIBFUZZER_FROM_DEPS) |
| 379 | file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp") |
| 380 | add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES}) |
| 381 | # libFuzzer does not pass our aggressive warnings. It also must be built |
| 382 | # without -fsanitize-coverage options or clang crashes. |
David Benjamin | 6fb16cc | 2017-07-14 11:02:39 -0400 | [diff] [blame] | 383 | set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0") |
David Benjamin | 1e5cb82 | 2017-05-10 16:07:56 -0400 | [diff] [blame] | 384 | endif() |
| 385 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 386 | add_subdirectory(fuzz) |
| 387 | endif() |
| 388 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 389 | if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2") |
| 390 | # USES_TERMINAL is only available in CMake 3.2 or later. |
| 391 | set(MAYBE_USES_TERMINAL USES_TERMINAL) |
| 392 | endif() |
| 393 | |
| 394 | add_custom_target( |
| 395 | run_tests |
| 396 | COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir |
| 397 | ${CMAKE_BINARY_DIR} |
Adam Langley | d5c72c8 | 2016-09-23 16:43:17 -0700 | [diff] [blame] | 398 | COMMAND cd ssl/test/runner && |
| 399 | ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim> |
| 400 | ${RUNNER_ARGS} |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 401 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 402 | DEPENDS all_tests bssl_shim |
| 403 | ${MAYBE_USES_TERMINAL}) |