David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.11) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 2 | |
David Benjamin | 6979c7e | 2017-12-04 17:19:49 -0500 | [diff] [blame] | 3 | # Report AppleClang separately from Clang. Their version numbers are different. |
| 4 | # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html |
| 5 | if(POLICY CMP0025) |
| 6 | cmake_policy(SET CMP0025 NEW) |
| 7 | endif() |
| 8 | |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 9 | # Defer enabling C and CXX languages. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 10 | project(BoringSSL NONE) |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 11 | |
| 12 | if(WIN32) |
| 13 | # On Windows, prefer cl over gcc if both are available. By default most of |
| 14 | # the CMake generators prefer gcc, even on Windows. |
| 15 | set(CMAKE_GENERATOR_CC cl) |
| 16 | endif() |
| 17 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 18 | include(sources.cmake) |
| 19 | |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 20 | enable_language(C) |
| 21 | enable_language(CXX) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 22 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 23 | # This is a dummy target which all other targets depend on (manually - see other |
| 24 | # CMakeLists.txt files). This gives us a hook to add any targets which need to |
| 25 | # run before all other targets. |
| 26 | add_custom_target(global_target) |
| 27 | |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 28 | if(ANDROID) |
| 29 | # Android-NDK CMake files reconfigure the path and so Go and Perl won't be |
| 30 | # 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] | 31 | if(NOT PERL_EXECUTABLE) |
| 32 | set(PERL_EXECUTABLE "perl") |
| 33 | endif() |
| 34 | if(NOT GO_EXECUTABLE) |
| 35 | set(GO_EXECUTABLE "go") |
| 36 | endif() |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 37 | else() |
| 38 | find_package(Perl REQUIRED) |
| 39 | find_program(GO_EXECUTABLE go) |
| 40 | endif() |
David Benjamin | 3ce3c36 | 2015-02-23 13:06:19 -0500 | [diff] [blame] | 41 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 42 | if(NOT GO_EXECUTABLE) |
David Benjamin | d27eda0 | 2015-03-05 01:19:27 -0500 | [diff] [blame] | 43 | message(FATAL_ERROR "Could not find Go") |
| 44 | endif() |
| 45 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 46 | if(USE_CUSTOM_LIBCXX) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 47 | set(BORINGSSL_ALLOW_CXX_RUNTIME 1) |
| 48 | endif() |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 49 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 50 | if(BORINGSSL_ALLOW_CXX_RUNTIME) |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 51 | add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) |
| 52 | endif() |
| 53 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 54 | if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS) |
| 55 | add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}) |
| 56 | |
| 57 | # Use "symbol_prefix_include" to store generated header files |
| 58 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include) |
| 59 | add_custom_command( |
| 60 | OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h |
| 61 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 62 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc |
| 63 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include |
| 64 | COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS} |
| 65 | DEPENDS util/make_prefix_headers.go |
| 66 | ${CMAKE_BINARY_DIR}/${BORINGSSL_PREFIX_SYMBOLS}) |
| 67 | |
| 68 | # add_dependencies needs a target, not a file, so we add an intermediate |
| 69 | # target. |
| 70 | add_custom_target( |
| 71 | boringssl_prefix_symbols |
| 72 | DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h |
| 73 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 74 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc) |
| 75 | add_dependencies(global_target boringssl_prefix_symbols) |
| 76 | elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS) |
| 77 | message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS") |
| 78 | endif() |
| 79 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 80 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 81 | set(CLANG 1) |
| 82 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 83 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 84 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 85 | # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 86 | # primarily on our normal Clang one. |
| 87 | set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 88 | if(MSVC) |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 89 | # clang-cl sets different default warnings than clang. It also treats -Wall |
| 90 | # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. |
| 91 | # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 |
| 92 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 93 | # googletest suppresses warning C4996 via a pragma, but clang-cl does not |
| 94 | # honor it. Suppress it here to compensate. See https://crbug.com/772117. |
| 95 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations") |
| 96 | else() |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 97 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 98 | endif() |
| 99 | |
| 100 | if(CLANG) |
David Benjamin | 9fb6fea | 2017-07-31 14:03:38 -0400 | [diff] [blame] | 101 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics") |
Adam Langley | 5c38c05 | 2017-04-28 14:47:06 -0700 | [diff] [blame] | 102 | else() |
| 103 | # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls |
| 104 | # and declare that the code is trying to free a stack pointer. |
| 105 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") |
David Benjamin | 9b7d836 | 2016-08-29 14:59:31 -0400 | [diff] [blame] | 106 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 107 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 108 | 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] | 109 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough") |
| 110 | endif() |
| 111 | |
Adam Langley | 0186787 | 2016-06-30 14:16:59 -0700 | [diff] [blame] | 112 | 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] | 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations") |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 114 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 115 | if(NOT MSVC) |
| 116 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Daniel Wagner-Hall | 3b358b2 | 2017-10-16 20:58:08 +0100 | [diff] [blame] | 117 | if(APPLE) |
| 118 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 119 | endif() |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 120 | if(NOT BORINGSSL_ALLOW_CXX_RUNTIME) |
| 121 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
| 122 | endif() |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 123 | endif() |
| 124 | |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 125 | # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes |
| 126 | # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the |
| 127 | # spelling for both and -Wmissing-declarations is some other warning. |
| 128 | # |
| 129 | # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options |
| 130 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes |
| 131 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 132 | if(CLANG) |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 133 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 134 | endif() |
Daniel Wagner-Hall | 1015432 | 2017-10-09 20:09:43 +0100 | [diff] [blame] | 135 | |
| 136 | if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION) |
| 137 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds") |
| 138 | endif() |
| 139 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 140 | elseif(MSVC) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 141 | set(MSVC_DISABLED_WARNINGS_LIST |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 142 | "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not |
| 143 | # explicitly handled by a case label |
| 144 | # Disable this because it flags even when there is a default. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 145 | "C4100" # 'exarg' : unreferenced formal parameter |
| 146 | "C4127" # conditional expression is constant |
| 147 | "C4200" # nonstandard extension used : zero-sized array in |
| 148 | # struct/union. |
David Benjamin | ffb1107 | 2016-11-13 10:32:10 +0900 | [diff] [blame] | 149 | "C4204" # nonstandard extension used: non-constant aggregate initializer |
| 150 | "C4221" # nonstandard extension used : 'identifier' : cannot be |
| 151 | # initialized using address of automatic variable |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 152 | "C4242" # 'function' : conversion from 'int' to 'uint8_t', |
| 153 | # possible loss of data |
| 154 | "C4244" # 'function' : conversion from 'int' to 'uint8_t', |
| 155 | # possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 156 | "C4267" # conversion from 'size_t' to 'int', possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 157 | "C4371" # layout of class may have changed from a previous version of the |
| 158 | # compiler due to better packing of member '...' |
| 159 | "C4388" # signed/unsigned mismatch |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 160 | "C4296" # '>=' : expression is always true |
| 161 | "C4350" # behavior change: 'std::_Wrap_alloc...' |
| 162 | "C4365" # '=' : conversion from 'size_t' to 'int', |
| 163 | # signed/unsigned mismatch |
| 164 | "C4389" # '!=' : signed/unsigned mismatch |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 165 | "C4464" # relative include path contains '..' |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 166 | "C4510" # 'argument' : default constructor could not be generated |
| 167 | "C4512" # 'argument' : assignment operator could not be generated |
| 168 | "C4514" # 'function': unreferenced inline function has been removed |
| 169 | "C4548" # expression before comma has no effect; expected expression with |
| 170 | # side-effect" caused by FD_* macros. |
| 171 | "C4610" # struct 'argument' can never be instantiated - user defined |
| 172 | # constructor required. |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 173 | "C4623" # default constructor was implicitly defined as deleted |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 174 | "C4625" # copy constructor could not be generated because a base class |
| 175 | # copy constructor is inaccessible or deleted |
| 176 | "C4626" # assignment operator could not be generated because a base class |
| 177 | # assignment operator is inaccessible or deleted |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 178 | "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with |
| 179 | # '0' for 'directives' |
| 180 | # Disable this because GTest uses it everywhere. |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 181 | "C4706" # assignment within conditional expression |
| 182 | "C4710" # 'function': function not inlined |
| 183 | "C4711" # function 'function' selected for inline expansion |
| 184 | "C4800" # 'int' : forcing value to bool 'true' or 'false' |
| 185 | # (performance warning) |
| 186 | "C4820" # 'bytes' bytes padding added after construct 'member_name' |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 187 | "C5026" # move constructor was implicitly defined as deleted |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 188 | "C5027" # move assignment operator was implicitly defined as deleted |
Adam Vartanian | 189270c | 2018-05-22 13:50:44 +0100 | [diff] [blame] | 189 | "C5045" # Compiler will insert Spectre mitigation for memory load if |
| 190 | # /Qspectre switch specified |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 191 | ) |
| 192 | set(MSVC_LEVEL4_WARNINGS_LIST |
| 193 | # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header |
| 194 | "C4265" # class has virtual functions, but destructor is not virtual |
| 195 | ) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 196 | string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR |
| 197 | ${MSVC_DISABLED_WARNINGS_LIST}) |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 198 | string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR |
| 199 | ${MSVC_LEVEL4_WARNINGS_LIST}) |
sphawk | 3ab1a69 | 2018-03-11 19:20:51 +0900 | [diff] [blame] | 200 | set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
| 201 | set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
David Benjamin | e2568c4 | 2017-08-16 15:25:27 -0400 | [diff] [blame] | 202 | endif() |
| 203 | |
| 204 | if(WIN32) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 205 | add_definitions(-D_HAS_EXCEPTIONS=0) |
Brian Smith | a87de9b | 2015-01-28 20:34:47 -0800 | [diff] [blame] | 206 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
David Benjamin | 0e434b9 | 2015-04-02 13:20:01 -0400 | [diff] [blame] | 207 | add_definitions(-DNOMINMAX) |
David Benjamin | 9b6ff44 | 2017-06-15 20:44:30 -0400 | [diff] [blame] | 208 | # Allow use of fopen. |
| 209 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Guillaume Egles | 791f282 | 2018-06-29 10:44:36 -0700 | [diff] [blame] | 210 | # VS 2017 and higher supports STL-only warning suppressions. Manually add to |
| 211 | # C++ only to work around a CMake quoting bug when using NASM with the Visual |
David Benjamin | e7b2b13 | 2018-07-06 14:46:30 -0400 | [diff] [blame] | 212 | # Studio generator. This will be fixed in CMake 3.13.0. See |
| 213 | # https://gitlab.kitware.com/cmake/cmake/merge_requests/2179 |
Guillaume Egles | 791f282 | 2018-06-29 10:44:36 -0700 | [diff] [blame] | 214 | add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_STL_EXTRA_DISABLED_WARNINGS=4774\ 4987>) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 215 | endif() |
| 216 | |
David Benjamin | b826c0d | 2015-02-28 00:00:44 -0500 | [diff] [blame] | 217 | 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] | 218 | CLANG) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 219 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") |
| 220 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow") |
Adam Langley | 07100c6 | 2015-01-16 15:20:54 -0800 | [diff] [blame] | 221 | endif() |
| 222 | |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 223 | if(CMAKE_COMPILER_IS_GNUCXX) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 224 | if((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG) |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 225 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") |
| 226 | else() |
| 227 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") |
| 228 | endif() |
| 229 | endif() |
| 230 | |
| 231 | # pthread_rwlock_t requires a feature flag. |
| 232 | if(NOT WIN32) |
| 233 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
Adam Langley | 6f2e733 | 2015-05-15 12:01:29 -0700 | [diff] [blame] | 234 | endif() |
| 235 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 236 | if(FUZZ) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 237 | if(NOT CLANG) |
Alessandro Ghedini | b6f6927 | 2016-09-28 22:14:01 +0100 | [diff] [blame] | 238 | 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] | 239 | endif() |
| 240 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 241 | if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0") |
| 242 | message(FATAL_ERROR "You need Clang ≥ 6.0.0") |
| 243 | endif() |
| 244 | |
David Benjamin | ec978dd | 2016-11-04 18:59:33 -0400 | [diff] [blame] | 245 | add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 246 | set(RUNNER_ARGS "-deterministic") |
| 247 | |
| 248 | if(NOT NO_FUZZER_MODE) |
| 249 | add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE) |
| 250 | set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json") |
| 251 | endif() |
David Benjamin | bc5b2a2 | 2016-03-01 22:57:32 -0500 | [diff] [blame] | 252 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 253 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
| 254 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 255 | endif() |
| 256 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 257 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 258 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 259 | if(BUILD_SHARED_LIBS) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 260 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 261 | # Enable position-independent code globally. This is needed because |
| 262 | # some library targets are OBJECT libraries. |
| 263 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
David Benjamin | 507c1ee | 2015-01-28 00:50:21 -0500 | [diff] [blame] | 264 | endif() |
| 265 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 266 | if(MSAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 267 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 268 | message(FATAL_ERROR "Cannot enable MSAN unless using Clang") |
| 269 | endif() |
| 270 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 271 | if(ASAN) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 272 | message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") |
| 273 | endif() |
| 274 | |
| 275 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 276 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Adam Langley | e77c27d | 2018-09-07 11:20:23 -0700 | [diff] [blame] | 277 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 278 | endif() |
| 279 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 280 | if(ASAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 281 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 282 | message(FATAL_ERROR "Cannot enable ASAN unless using Clang") |
| 283 | endif() |
| 284 | |
David Benjamin | 0d3c963 | 2017-02-28 14:58:00 -0500 | [diff] [blame] | 285 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
| 286 | 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] | 287 | endif() |
| 288 | |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 289 | if(CFI) |
| 290 | if(NOT CLANG) |
| 291 | message(FATAL_ERROR "Cannot enable CFI unless using Clang") |
| 292 | endif() |
| 293 | |
David Benjamin | 6650898 | 2018-09-22 16:19:15 -0500 | [diff] [blame] | 294 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
| 295 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 296 | # We use Chromium's copy of clang, which requires -fuse-ld=lld if building |
| 297 | # with -flto. That, in turn, can't handle -ggdb. |
| 298 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 299 | string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 300 | string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 301 | # -flto causes object files to contain LLVM bitcode. Mixing those with |
| 302 | # assembly output in the same static library breaks the linker. |
| 303 | set(OPENSSL_NO_ASM "1") |
| 304 | endif() |
| 305 | |
David Benjamin | 5852cfc | 2018-07-19 17:50:45 -0400 | [diff] [blame] | 306 | if(TSAN) |
| 307 | if(NOT CLANG) |
| 308 | message(FATAL_ERROR "Cannot enable TSAN unless using Clang") |
| 309 | endif() |
| 310 | |
| 311 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") |
| 312 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") |
| 313 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") |
| 314 | endif() |
| 315 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 316 | if(GCOV) |
David Benjamin | d035ab3 | 2016-12-27 12:15:56 -0500 | [diff] [blame] | 317 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 318 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") |
| 319 | endif() |
| 320 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 321 | if(FIPS) |
| 322 | add_definitions(-DBORINGSSL_FIPS) |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 323 | if(FIPS_BREAK_TEST) |
| 324 | add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1") |
| 325 | endif() |
| 326 | # Delocate does not work for ASan and MSan builds. |
| 327 | if(NOT ASAN AND NOT MSAN) |
| 328 | set(FIPS_DELOCATE "1") |
| 329 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 330 | endif() |
| 331 | |
David Benjamin | 6291af4 | 2018-03-23 13:49:27 -0400 | [diff] [blame] | 332 | if(OPENSSL_SMALL) |
| 333 | add_definitions(-DOPENSSL_SMALL) |
| 334 | endif() |
| 335 | |
David Benjamin | 5baee45 | 2018-09-13 16:37:28 -0500 | [diff] [blame] | 336 | function(go_executable dest package) |
| 337 | set(godeps "${CMAKE_SOURCE_DIR}/util/godeps.go") |
| 338 | if(${CMAKE_VERSION} VERSION_LESS "3.7" OR |
| 339 | NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") |
| 340 | # The DEPFILE parameter to add_custom_command is new as of CMake 3.7 and |
| 341 | # only works with Ninja. Query the sources at configure time. Additionally, |
| 342 | # everything depends on go.mod. That affects what external packages to use. |
| 343 | execute_process(COMMAND ${GO_EXECUTABLE} run ${godeps} -format cmake |
| 344 | -pkg ${package} |
| 345 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 346 | OUTPUT_VARIABLE sources |
| 347 | RESULT_VARIABLE godeps_result) |
| 348 | add_custom_command(OUTPUT ${dest} |
| 349 | COMMAND ${GO_EXECUTABLE} build |
| 350 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 351 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 352 | DEPENDS ${sources} ${CMAKE_SOURCE_DIR}/go.mod) |
| 353 | else() |
| 354 | # Ninja expects the target in the depfile to match the output. This is a |
| 355 | # relative path from the build directory. |
| 356 | string(LENGTH "${CMAKE_BINARY_DIR}" root_dir_length) |
| 357 | math(EXPR root_dir_length "${root_dir_length} + 1") |
| 358 | string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}" ${root_dir_length} -1 target) |
| 359 | set(target "${target}/${dest}") |
| 360 | |
| 361 | set(depfile "${CMAKE_CURRENT_BINARY_DIR}/${dest}.d") |
| 362 | add_custom_command(OUTPUT ${dest} |
| 363 | COMMAND ${GO_EXECUTABLE} build |
| 364 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 365 | COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile |
| 366 | -target ${target} -pkg ${package} -out ${depfile} |
| 367 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 368 | DEPENDS ${godeps} ${CMAKE_SOURCE_DIR}/go.mod |
| 369 | DEPFILE ${depfile}) |
| 370 | endif() |
| 371 | endfunction() |
| 372 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 373 | # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an |
| 374 | # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR |
| 375 | # alone, and expects all architecture-specific logic to be conditioned within |
| 376 | # the source files rather than the build. This does not work for our assembly |
| 377 | # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture |
| 378 | # builds. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 379 | if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 380 | list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 381 | if(NOT ${NUM_ARCHES} EQUAL 1) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 382 | message(FATAL_ERROR "Universal binaries not supported.") |
| 383 | endif() |
| 384 | list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) |
| 385 | endif() |
| 386 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 387 | if(OPENSSL_NO_ASM) |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 388 | add_definitions(-DOPENSSL_NO_ASM) |
| 389 | set(ARCH "generic") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 390 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 391 | set(ARCH "x86_64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 392 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 393 | set(ARCH "x86_64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 394 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 395 | # cmake reports AMD64 on Windows, but we might be building for 32-bit. |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 396 | if(CMAKE_CL_64) |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 397 | set(ARCH "x86_64") |
| 398 | else() |
| 399 | set(ARCH "x86") |
| 400 | endif() |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 401 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 402 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 403 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 404 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 405 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 406 | set(ARCH "x86") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 407 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 408 | set(ARCH "aarch64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 409 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 410 | set(ARCH "aarch64") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 411 | elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 412 | set(ARCH "arm") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 413 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 414 | # Just to avoid the “unknown processor” error. |
| 415 | set(ARCH "generic") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 416 | elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 417 | set(ARCH "ppc64le") |
| 418 | else() |
| 419 | message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) |
David Benjamin | 27b08e9 | 2015-05-04 15:16:57 -0400 | [diff] [blame] | 420 | endif() |
| 421 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 422 | if(ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm") |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 423 | # The third-party Android-NDK CMake files somehow fail to set the -march flag |
| 424 | # for assembly files. Without this flag, the compiler believes that it's |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 425 | # building for ARMv5. |
David Benjamin | 9894ee9 | 2017-12-13 18:08:47 -0500 | [diff] [blame] | 426 | set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}") |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 427 | endif() |
| 428 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 429 | 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] | 430 | # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X, |
| 431 | # but clang defaults to 64-bit builds on OS X unless otherwise told. |
| 432 | # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3. |
| 433 | set(ARCH "x86_64") |
Adam Langley | fd49993 | 2017-04-04 14:21:43 -0700 | [diff] [blame] | 434 | endif() |
| 435 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 436 | if(USE_CUSTOM_LIBCXX) |
| 437 | if(NOT CLANG) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 438 | message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") |
| 439 | endif() |
| 440 | |
| 441 | # CMAKE_CXX_FLAGS ends up in the linker flags as well, so use |
| 442 | # add_compile_options. There does not appear to be a way to set |
| 443 | # language-specific compile-only flags. |
| 444 | add_compile_options("-nostdinc++") |
| 445 | set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++") |
| 446 | include_directories( |
| 447 | SYSTEM |
| 448 | util/bot/libcxx/include |
| 449 | util/bot/libcxxabi/include |
| 450 | ) |
| 451 | |
| 452 | # This is patterned after buildtools/third_party/libc++/BUILD.gn and |
| 453 | # buildtools/third_party/libc++abi/BUILD.gn in Chromium. |
| 454 | |
| 455 | file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp") |
| 456 | file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp") |
| 457 | |
| 458 | # This file is meant for exception-less builds. |
| 459 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp") |
| 460 | # libc++ also defines new and delete. |
| 461 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 462 | if(TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 463 | # ThreadSanitizer tries to intercept these symbols. Skip them to avoid |
| 464 | # symbol conflicts. |
| 465 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp") |
| 466 | endif() |
| 467 | |
| 468 | add_library(libcxxabi ${LIBCXXABI_SOURCES}) |
| 469 | target_compile_definitions( |
| 470 | libcxxabi PRIVATE |
| 471 | -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS |
| 472 | ) |
| 473 | set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough") |
| 474 | |
| 475 | add_library(libcxx ${LIBCXX_SOURCES}) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 476 | if(ASAN OR MSAN OR TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 477 | # Sanitizers try to intercept new and delete. |
| 478 | target_compile_definitions( |
| 479 | libcxx PRIVATE |
| 480 | -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS |
| 481 | ) |
| 482 | endif() |
| 483 | target_compile_definitions( |
| 484 | libcxx PRIVATE |
| 485 | -D_LIBCPP_BUILDING_LIBRARY |
| 486 | -DLIBCXX_BUILDING_LIBCXXABI |
| 487 | ) |
| 488 | target_link_libraries(libcxx libcxxabi) |
| 489 | endif() |
| 490 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 491 | # Add minimal googletest targets. The provided one has many side-effects, and |
| 492 | # googletest has a very straightforward build. |
Marek Gilbert | 11850d5 | 2018-01-03 23:07:58 -0800 | [diff] [blame] | 493 | add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc) |
| 494 | target_include_directories(boringssl_gtest PRIVATE third_party/googletest) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 495 | |
| 496 | include_directories(third_party/googletest/include) |
| 497 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 498 | # Declare a dummy target to build all unit tests. Test targets should inject |
| 499 | # themselves as dependencies next to the target definition. |
| 500 | add_custom_target(all_tests) |
| 501 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 502 | add_custom_command( |
| 503 | OUTPUT crypto_test_data.cc |
| 504 | COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} > |
| 505 | ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc |
| 506 | DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA} |
| 507 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 508 | |
| 509 | add_library(crypto_test_data OBJECT crypto_test_data.cc) |
| 510 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 511 | add_subdirectory(crypto) |
| 512 | add_subdirectory(ssl) |
| 513 | add_subdirectory(ssl/test) |
Martin Kreichgauer | 118355c | 2017-05-12 15:34:45 -0700 | [diff] [blame] | 514 | add_subdirectory(fipstools) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 515 | add_subdirectory(tool) |
Adam Langley | c004dfc | 2015-02-03 10:45:12 -0800 | [diff] [blame] | 516 | add_subdirectory(decrepit) |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 517 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 518 | if(FUZZ) |
| 519 | add_subdirectory(fuzz) |
| 520 | endif() |
| 521 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 522 | if(NOT ${CMAKE_VERSION} VERSION_LESS "3.2") |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 523 | # USES_TERMINAL is only available in CMake 3.2 or later. |
| 524 | set(MAYBE_USES_TERMINAL USES_TERMINAL) |
| 525 | endif() |
| 526 | |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 527 | if(UNIX AND NOT APPLE AND NOT ANDROID) |
| 528 | set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>) |
| 529 | endif() |
| 530 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 531 | add_custom_target( |
| 532 | run_tests |
| 533 | COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir |
| 534 | ${CMAKE_BINARY_DIR} |
Adam Langley | d5c72c8 | 2016-09-23 16:43:17 -0700 | [diff] [blame] | 535 | COMMAND cd ssl/test/runner && |
| 536 | ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim> |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 537 | ${HANDSHAKER_ARGS} ${RUNNER_ARGS} |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 538 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
Steven Valdez | e5388e0 | 2018-08-01 16:54:48 -0400 | [diff] [blame] | 539 | DEPENDS all_tests bssl_shim handshaker |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 540 | ${MAYBE_USES_TERMINAL}) |