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