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