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