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