Pete Bentley | 00a7c40 | 2021-07-23 17:57:12 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.5) |
Robert Sloan | cd79cde | 2017-12-11 09:06:12 -0800 | [diff] [blame] | 2 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 3 | # Defer enabling C and CXX languages. |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 4 | project(BoringSSL NONE) |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 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 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 17 | # This is a dummy target which all other targets depend on (manually - see other |
| 18 | # CMakeLists.txt files). This gives us a hook to add any targets which need to |
| 19 | # run before all other targets. |
| 20 | add_custom_target(global_target) |
| 21 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 22 | if(ANDROID) |
| 23 | # Android-NDK CMake files reconfigure the path and so Go and Perl won't be |
| 24 | # 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] | 25 | if(NOT PERL_EXECUTABLE) |
| 26 | set(PERL_EXECUTABLE "perl") |
| 27 | endif() |
| 28 | if(NOT GO_EXECUTABLE) |
| 29 | set(GO_EXECUTABLE "go") |
| 30 | endif() |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 31 | else() |
| 32 | find_package(Perl REQUIRED) |
| 33 | find_program(GO_EXECUTABLE go) |
| 34 | endif() |
| 35 | |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 36 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING) |
| 37 | find_package(PkgConfig QUIET) |
| 38 | if (PkgConfig_FOUND) |
| 39 | pkg_check_modules(LIBUNWIND libunwind-generic) |
| 40 | if(LIBUNWIND_FOUND) |
| 41 | add_definitions(-DBORINGSSL_HAVE_LIBUNWIND) |
| 42 | else() |
| 43 | message("libunwind not found. Disabling unwind tests.") |
| 44 | endif() |
| 45 | else() |
| 46 | message("pkgconfig not found. Disabling unwind tests.") |
| 47 | endif() |
| 48 | endif() |
| 49 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 50 | if(NOT GO_EXECUTABLE) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 51 | message(FATAL_ERROR "Could not find Go") |
| 52 | endif() |
| 53 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 54 | if(USE_CUSTOM_LIBCXX) |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 55 | set(BORINGSSL_ALLOW_CXX_RUNTIME 1) |
| 56 | endif() |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 57 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 58 | if(BORINGSSL_ALLOW_CXX_RUNTIME) |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 59 | add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) |
| 60 | endif() |
| 61 | |
Pete Bentley | 470a930 | 2019-10-02 14:44:32 +0100 | [diff] [blame] | 62 | string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) |
| 63 | if(NOT FIPS) |
| 64 | if(CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithassert" OR |
| 65 | NOT CMAKE_BUILD_TYPE_LOWER MATCHES "rel") |
| 66 | add_definitions(-DBORINGSSL_DISPATCH_TEST) |
| 67 | # CMake automatically connects include_directories to the NASM |
| 68 | # command-line, but not add_definitions. |
| 69 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_DISPATCH_TEST") |
| 70 | endif() |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 71 | endif() |
| 72 | |
| 73 | # Add a RelWithAsserts build configuration. It is the same as Release, except it |
| 74 | # does not define NDEBUG, so asserts run. |
| 75 | foreach(VAR CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS) |
| 76 | string(REGEX REPLACE "(^| )[/-]DNDEBUG( |$)" " " "${VAR}_RELWITHASSERTS" |
| 77 | "${${VAR}_RELEASE}") |
| 78 | endforeach() |
| 79 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 80 | if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS) |
| 81 | add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}) |
Robert Sloan | 6e8c959 | 2018-12-03 11:20:49 -0800 | [diff] [blame] | 82 | # CMake automatically connects include_directories to the NASM command-line, |
| 83 | # but not add_definitions. |
| 84 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}") |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 85 | |
| 86 | # Use "symbol_prefix_include" to store generated header files |
| 87 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include) |
| 88 | add_custom_command( |
| 89 | OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h |
| 90 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 91 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc |
| 92 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include |
| 93 | COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS} |
| 94 | DEPENDS util/make_prefix_headers.go |
| 95 | ${CMAKE_BINARY_DIR}/${BORINGSSL_PREFIX_SYMBOLS}) |
| 96 | |
| 97 | # add_dependencies needs a target, not a file, so we add an intermediate |
| 98 | # target. |
| 99 | add_custom_target( |
| 100 | boringssl_prefix_symbols |
| 101 | DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h |
| 102 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 103 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc) |
| 104 | add_dependencies(global_target boringssl_prefix_symbols) |
| 105 | elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS) |
| 106 | message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS") |
| 107 | endif() |
| 108 | |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 109 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 110 | set(CLANG 1) |
| 111 | endif() |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 112 | |
Tobias Thierer | 580fcaf | 2019-09-12 20:23:01 +0100 | [diff] [blame] | 113 | if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") |
| 114 | set(EMSCRIPTEN 1) |
| 115 | endif() |
| 116 | |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 117 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 118 | # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration |
Robert Sloan | 978112c | 2018-01-22 12:53:01 -0800 | [diff] [blame] | 119 | # primarily on our normal Clang one. |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 120 | set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -Wvla -Wshadow") |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 121 | if(MSVC) |
Robert Sloan | 978112c | 2018-01-22 12:53:01 -0800 | [diff] [blame] | 122 | # clang-cl sets different default warnings than clang. It also treats -Wall |
| 123 | # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. |
| 124 | # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 |
| 125 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900") |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 126 | # googletest suppresses warning C4996 via a pragma, but clang-cl does not |
| 127 | # honor it. Suppress it here to compensate. See https://crbug.com/772117. |
| 128 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations") |
| 129 | else() |
Tobias Thierer | 580fcaf | 2019-09-12 20:23:01 +0100 | [diff] [blame] | 130 | if(EMSCRIPTEN) |
| 131 | # emscripten's emcc/clang does not accept the "-ggdb" flag. |
| 132 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -g") |
| 133 | else() |
| 134 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb") |
| 135 | endif() |
| 136 | |
| 137 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -fvisibility=hidden -fno-common") |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 138 | endif() |
| 139 | |
| 140 | if(CLANG) |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 141 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics") |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 142 | else() |
| 143 | # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls |
| 144 | # and declare that the code is trying to free a stack pointer. |
| 145 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 146 | endif() |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 147 | |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 148 | if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION) |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 149 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough") |
| 150 | endif() |
| 151 | |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 152 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes") |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 153 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations") |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 154 | |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 155 | if(NOT MSVC) |
| 156 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 157 | if(APPLE) |
| 158 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") |
| 159 | endif() |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 160 | if(NOT BORINGSSL_ALLOW_CXX_RUNTIME) |
| 161 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
| 162 | endif() |
Robert Sloan | fe7cd21 | 2017-08-07 09:03:39 -0700 | [diff] [blame] | 163 | endif() |
| 164 | |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 165 | # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes |
| 166 | # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the |
| 167 | # spelling for both and -Wmissing-declarations is some other warning. |
| 168 | # |
| 169 | # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options |
| 170 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes |
| 171 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 172 | if(CLANG) |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 173 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") |
Robert Sloan | a12bf46 | 2017-07-17 07:08:26 -0700 | [diff] [blame] | 174 | endif() |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 175 | elseif(MSVC) |
| 176 | set(MSVC_DISABLED_WARNINGS_LIST |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 177 | "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not |
| 178 | # explicitly handled by a case label |
| 179 | # Disable this because it flags even when there is a default. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 180 | "C4100" # 'exarg' : unreferenced formal parameter |
| 181 | "C4127" # conditional expression is constant |
| 182 | "C4200" # nonstandard extension used : zero-sized array in |
| 183 | # struct/union. |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 184 | "C4204" # nonstandard extension used: non-constant aggregate initializer |
| 185 | "C4221" # nonstandard extension used : 'identifier' : cannot be |
| 186 | # initialized using address of automatic variable |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 187 | "C4242" # 'function' : conversion from 'int' to 'uint8_t', |
| 188 | # possible loss of data |
| 189 | "C4244" # 'function' : conversion from 'int' to 'uint8_t', |
| 190 | # possible loss of data |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 191 | "C4267" # conversion from 'size_t' to 'int', possible loss of data |
| 192 | "C4371" # layout of class may have changed from a previous version of the |
| 193 | # compiler due to better packing of member '...' |
| 194 | "C4388" # signed/unsigned mismatch |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 195 | "C4296" # '>=' : expression is always true |
| 196 | "C4350" # behavior change: 'std::_Wrap_alloc...' |
| 197 | "C4365" # '=' : conversion from 'size_t' to 'int', |
| 198 | # signed/unsigned mismatch |
| 199 | "C4389" # '!=' : signed/unsigned mismatch |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 200 | "C4464" # relative include path contains '..' |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 201 | "C4510" # 'argument' : default constructor could not be generated |
| 202 | "C4512" # 'argument' : assignment operator could not be generated |
| 203 | "C4514" # 'function': unreferenced inline function has been removed |
| 204 | "C4548" # expression before comma has no effect; expected expression with |
| 205 | # side-effect" caused by FD_* macros. |
| 206 | "C4610" # struct 'argument' can never be instantiated - user defined |
| 207 | # constructor required. |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 208 | "C4623" # default constructor was implicitly defined as deleted |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 209 | "C4625" # copy constructor could not be generated because a base class |
| 210 | # copy constructor is inaccessible or deleted |
| 211 | "C4626" # assignment operator could not be generated because a base class |
| 212 | # assignment operator is inaccessible or deleted |
Robert Sloan | f63bd1f | 2019-04-16 09:26:20 -0700 | [diff] [blame] | 213 | "C4628" # digraphs not supported with -Ze |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 214 | "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with |
| 215 | # '0' for 'directives' |
| 216 | # Disable this because GTest uses it everywhere. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 217 | "C4706" # assignment within conditional expression |
| 218 | "C4710" # 'function': function not inlined |
| 219 | "C4711" # function 'function' selected for inline expansion |
| 220 | "C4800" # 'int' : forcing value to bool 'true' or 'false' |
| 221 | # (performance warning) |
| 222 | "C4820" # 'bytes' bytes padding added after construct 'member_name' |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 223 | "C5026" # move constructor was implicitly defined as deleted |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 224 | "C5027" # move assignment operator was implicitly defined as deleted |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 225 | "C5045" # Compiler will insert Spectre mitigation for memory load if |
| 226 | # /Qspectre switch specified |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 227 | ) |
| 228 | set(MSVC_LEVEL4_WARNINGS_LIST |
| 229 | # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header |
| 230 | "C4265" # class has virtual functions, but destructor is not virtual |
| 231 | ) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 232 | string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR |
| 233 | ${MSVC_DISABLED_WARNINGS_LIST}) |
David Benjamin | 9aaebef | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 234 | string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR |
| 235 | ${MSVC_LEVEL4_WARNINGS_LIST}) |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 236 | set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
| 237 | set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}") |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 238 | endif() |
| 239 | |
| 240 | if(WIN32) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 241 | add_definitions(-D_HAS_EXCEPTIONS=0) |
| 242 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 243 | add_definitions(-DNOMINMAX) |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 244 | # Allow use of fopen. |
| 245 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Tobias Thierer | 580fcaf | 2019-09-12 20:23:01 +0100 | [diff] [blame] | 246 | # VS 2017 and higher supports STL-only warning suppressions. |
| 247 | # A bug in CMake < 3.13.0 may cause the space in this value to |
| 248 | # cause issues when building with NASM. In that case, update CMake. |
| 249 | add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987") |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 250 | endif() |
| 251 | |
David Benjamin | 6e899c7 | 2016-06-09 18:02:18 -0400 | [diff] [blame] | 252 | if(CMAKE_COMPILER_IS_GNUCXX) |
Pete Bentley | 00a7c40 | 2021-07-23 17:57:12 +0100 | [diff] [blame] | 253 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") |
David Benjamin | 6e899c7 | 2016-06-09 18:02:18 -0400 | [diff] [blame] | 254 | endif() |
| 255 | |
| 256 | # pthread_rwlock_t requires a feature flag. |
| 257 | if(NOT WIN32) |
| 258 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 259 | endif() |
| 260 | |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 261 | if(FUZZ) |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 262 | if(NOT CLANG) |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 263 | 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] | 264 | endif() |
| 265 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 266 | if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0") |
| 267 | message(FATAL_ERROR "You need Clang ≥ 6.0.0") |
| 268 | endif() |
| 269 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 270 | add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 271 | set(RUNNER_ARGS "-deterministic") |
| 272 | |
| 273 | if(NOT NO_FUZZER_MODE) |
| 274 | add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE) |
| 275 | set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json") |
| 276 | endif() |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 277 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 278 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
| 279 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 280 | endif() |
| 281 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 282 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 283 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 284 | if(BUILD_SHARED_LIBS) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 285 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 286 | # Enable position-independent code globally. This is needed because |
| 287 | # some library targets are OBJECT libraries. |
| 288 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 289 | endif() |
| 290 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 291 | if(MSAN) |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 292 | if(NOT CLANG) |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 293 | message(FATAL_ERROR "Cannot enable MSAN unless using Clang") |
| 294 | endif() |
| 295 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 296 | if(ASAN) |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 297 | message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") |
| 298 | endif() |
| 299 | |
| 300 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 301 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 302 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 303 | endif() |
| 304 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 305 | if(ASAN) |
Robert Sloan | 73fa5d6 | 2017-10-09 13:53:06 -0700 | [diff] [blame] | 306 | if(NOT CLANG) |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 307 | message(FATAL_ERROR "Cannot enable ASAN unless using Clang") |
| 308 | endif() |
| 309 | |
Robert Sloan | 7d422bc | 2017-03-06 10:04:29 -0800 | [diff] [blame] | 310 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
| 311 | 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] | 312 | endif() |
| 313 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 314 | if(CFI) |
| 315 | if(NOT CLANG) |
| 316 | message(FATAL_ERROR "Cannot enable CFI unless using Clang") |
| 317 | endif() |
| 318 | |
Robert Sloan | 5bdaadb | 2018-10-30 16:00:26 -0700 | [diff] [blame] | 319 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
| 320 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 321 | # We use Chromium's copy of clang, which requires -fuse-ld=lld if building |
| 322 | # with -flto. That, in turn, can't handle -ggdb. |
| 323 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 324 | string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 325 | string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 326 | # -flto causes object files to contain LLVM bitcode. Mixing those with |
| 327 | # assembly output in the same static library breaks the linker. |
| 328 | set(OPENSSL_NO_ASM "1") |
| 329 | endif() |
| 330 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 331 | if(TSAN) |
| 332 | if(NOT CLANG) |
| 333 | message(FATAL_ERROR "Cannot enable TSAN unless using Clang") |
| 334 | endif() |
| 335 | |
| 336 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") |
| 337 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") |
| 338 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") |
| 339 | endif() |
| 340 | |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 341 | if(UBSAN) |
| 342 | if(NOT CLANG) |
| 343 | message(FATAL_ERROR "Cannot enable UBSAN unless using Clang") |
| 344 | endif() |
| 345 | |
| 346 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") |
| 347 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") |
| 348 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") |
| 349 | |
| 350 | if(NOT UBSAN_RECOVER) |
| 351 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=undefined") |
| 352 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=undefined") |
| 353 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-sanitize-recover=undefined") |
| 354 | endif() |
| 355 | endif() |
| 356 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 357 | if(GCOV) |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 358 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 359 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") |
| 360 | endif() |
| 361 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 362 | if(FIPS) |
| 363 | add_definitions(-DBORINGSSL_FIPS) |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 364 | if(FIPS_BREAK_TEST) |
| 365 | add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1") |
| 366 | endif() |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame] | 367 | # The FIPS integrity check does not work for ASan and MSan builds. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 368 | if(NOT ASAN AND NOT MSAN) |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame] | 369 | if(BUILD_SHARED_LIBS) |
| 370 | set(FIPS_SHARED "1") |
| 371 | else() |
| 372 | set(FIPS_DELOCATE "1") |
| 373 | endif() |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 374 | endif() |
Tobias Thierer | 65d184c | 2019-10-19 00:33:07 +0100 | [diff] [blame] | 375 | if(FIPS_SHARED) |
| 376 | # The Android CMake files set -ffunction-sections and -fdata-sections, |
| 377 | # which is incompatible with FIPS_SHARED. |
| 378 | set(CMAKE_C_FLAGS |
| 379 | "${CMAKE_C_FLAGS} -fno-function-sections -fno-data-sections") |
| 380 | set(CMAKE_CXX_FLAGS |
| 381 | "${CMAKE_CXX_FLAGS} -fno-function-sections -fno-data-sections") |
| 382 | endif() |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 383 | endif() |
| 384 | |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 385 | if(OPENSSL_SMALL) |
| 386 | add_definitions(-DOPENSSL_SMALL) |
| 387 | endif() |
| 388 | |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 389 | if(CONSTANT_TIME_VALIDATION) |
| 390 | add_definitions(-DBORINGSSL_CONSTANT_TIME_VALIDATION) |
| 391 | # Asserts will often test secret data. |
| 392 | add_definitions(-DNDEBUG) |
| 393 | endif() |
| 394 | |
Robert Sloan | f573be7 | 2018-09-17 15:29:11 -0700 | [diff] [blame] | 395 | function(go_executable dest package) |
| 396 | set(godeps "${CMAKE_SOURCE_DIR}/util/godeps.go") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 397 | if(CMAKE_VERSION VERSION_LESS "3.7" OR NOT CMAKE_GENERATOR STREQUAL "Ninja") |
Robert Sloan | f573be7 | 2018-09-17 15:29:11 -0700 | [diff] [blame] | 398 | # The DEPFILE parameter to add_custom_command is new as of CMake 3.7 and |
| 399 | # only works with Ninja. Query the sources at configure time. Additionally, |
| 400 | # everything depends on go.mod. That affects what external packages to use. |
| 401 | execute_process(COMMAND ${GO_EXECUTABLE} run ${godeps} -format cmake |
| 402 | -pkg ${package} |
| 403 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 404 | OUTPUT_VARIABLE sources |
| 405 | RESULT_VARIABLE godeps_result) |
| 406 | add_custom_command(OUTPUT ${dest} |
| 407 | COMMAND ${GO_EXECUTABLE} build |
| 408 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 409 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 410 | DEPENDS ${sources} ${CMAKE_SOURCE_DIR}/go.mod) |
| 411 | else() |
| 412 | # Ninja expects the target in the depfile to match the output. This is a |
| 413 | # relative path from the build directory. |
| 414 | string(LENGTH "${CMAKE_BINARY_DIR}" root_dir_length) |
| 415 | math(EXPR root_dir_length "${root_dir_length} + 1") |
| 416 | string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}" ${root_dir_length} -1 target) |
| 417 | set(target "${target}/${dest}") |
| 418 | |
| 419 | set(depfile "${CMAKE_CURRENT_BINARY_DIR}/${dest}.d") |
| 420 | add_custom_command(OUTPUT ${dest} |
| 421 | COMMAND ${GO_EXECUTABLE} build |
| 422 | -o ${CMAKE_CURRENT_BINARY_DIR}/${dest} ${package} |
| 423 | COMMAND ${GO_EXECUTABLE} run ${godeps} -format depfile |
| 424 | -target ${target} -pkg ${package} -out ${depfile} |
| 425 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 426 | DEPENDS ${godeps} ${CMAKE_SOURCE_DIR}/go.mod |
| 427 | DEPFILE ${depfile}) |
| 428 | endif() |
| 429 | endfunction() |
| 430 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 431 | # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an |
| 432 | # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR |
| 433 | # alone, and expects all architecture-specific logic to be conditioned within |
| 434 | # the source files rather than the build. This does not work for our assembly |
| 435 | # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture |
| 436 | # builds. |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 437 | if(NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES) |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 438 | list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES) |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 439 | if(NOT NUM_ARCHES EQUAL 1) |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 440 | message(FATAL_ERROR "Universal binaries not supported.") |
| 441 | endif() |
| 442 | list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR) |
| 443 | endif() |
| 444 | |
Tobias Thierer | 43be7d2 | 2020-03-02 19:23:34 +0000 | [diff] [blame] | 445 | if(OPENSSL_NO_SSE2_FOR_TESTING) |
| 446 | add_definitions(-DOPENSSL_NO_SSE2_FOR_TESTING) |
| 447 | endif() |
| 448 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 449 | if(OPENSSL_NO_ASM) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 450 | add_definitions(-DOPENSSL_NO_ASM) |
| 451 | set(ARCH "generic") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 452 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 453 | set(ARCH "x86_64") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 454 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 455 | set(ARCH "x86_64") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 456 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 457 | # cmake reports AMD64 on Windows, but we might be building for 32-bit. |
Pete Bentley | f23caaf | 2020-09-22 18:02:11 +0100 | [diff] [blame] | 458 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 459 | set(ARCH "x86_64") |
| 460 | else() |
| 461 | set(ARCH "x86") |
| 462 | endif() |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 463 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 464 | set(ARCH "x86") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 465 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 466 | set(ARCH "x86") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 467 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "i686") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 468 | set(ARCH "x86") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 469 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 470 | set(ARCH "aarch64") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 471 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64") |
Pete Bentley | 1748611 | 2021-01-20 11:51:47 +0000 | [diff] [blame] | 472 | set(ARCH "aarch64") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 473 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 474 | set(ARCH "aarch64") |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame] | 475 | # Apple A12 Bionic chipset which is added in iPhone XS/XS Max/XR uses arm64e architecture. |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 476 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64e") |
Robert Sloan | c9abfe4 | 2018-11-26 12:19:07 -0800 | [diff] [blame] | 477 | set(ARCH "aarch64") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 478 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm*") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 479 | set(ARCH "arm") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 480 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "mips") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 481 | # Just to avoid the “unknown processor” error. |
| 482 | set(ARCH "generic") |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 483 | elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 484 | set(ARCH "ppc64le") |
| 485 | else() |
| 486 | message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) |
| 487 | endif() |
| 488 | |
Pete Bentley | 2f26c21 | 2021-10-01 11:32:03 +0000 | [diff] [blame] | 489 | if(ANDROID AND NOT ANDROID_NDK_REVISION AND ARCH STREQUAL "arm") |
Robert Sloan | 5581810 | 2017-12-18 11:26:17 -0800 | [diff] [blame] | 490 | # The third-party Android-NDK CMake files somehow fail to set the -march flag |
| 491 | # for assembly files. Without this flag, the compiler believes that it's |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 492 | # building for ARMv5. |
Robert Sloan | 5581810 | 2017-12-18 11:26:17 -0800 | [diff] [blame] | 493 | set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}") |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 494 | endif() |
| 495 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 496 | if(USE_CUSTOM_LIBCXX) |
| 497 | if(NOT CLANG) |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 498 | message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") |
| 499 | endif() |
| 500 | |
| 501 | # CMAKE_CXX_FLAGS ends up in the linker flags as well, so use |
| 502 | # add_compile_options. There does not appear to be a way to set |
| 503 | # language-specific compile-only flags. |
| 504 | add_compile_options("-nostdinc++") |
| 505 | set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++") |
| 506 | include_directories( |
| 507 | SYSTEM |
| 508 | util/bot/libcxx/include |
| 509 | util/bot/libcxxabi/include |
| 510 | ) |
| 511 | |
| 512 | # This is patterned after buildtools/third_party/libc++/BUILD.gn and |
| 513 | # buildtools/third_party/libc++abi/BUILD.gn in Chromium. |
| 514 | |
| 515 | file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp") |
| 516 | file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp") |
| 517 | |
| 518 | # This file is meant for exception-less builds. |
| 519 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp") |
| 520 | # libc++ also defines new and delete. |
| 521 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp") |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 522 | if(TSAN) |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 523 | # ThreadSanitizer tries to intercept these symbols. Skip them to avoid |
| 524 | # symbol conflicts. |
| 525 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp") |
| 526 | endif() |
| 527 | |
| 528 | add_library(libcxxabi ${LIBCXXABI_SOURCES}) |
| 529 | target_compile_definitions( |
| 530 | libcxxabi PRIVATE |
| 531 | -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS |
| 532 | ) |
| 533 | set_target_properties(libcxxabi PROPERTIES COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough") |
| 534 | |
| 535 | add_library(libcxx ${LIBCXX_SOURCES}) |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 536 | if(ASAN OR MSAN OR TSAN) |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 537 | # Sanitizers try to intercept new and delete. |
| 538 | target_compile_definitions( |
| 539 | libcxx PRIVATE |
| 540 | -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS |
| 541 | ) |
| 542 | endif() |
| 543 | target_compile_definitions( |
| 544 | libcxx PRIVATE |
| 545 | -D_LIBCPP_BUILDING_LIBRARY |
| 546 | -DLIBCXX_BUILDING_LIBCXXABI |
| 547 | ) |
| 548 | target_link_libraries(libcxx libcxxabi) |
| 549 | endif() |
| 550 | |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 551 | # Add minimal googletest targets. The provided one has many side-effects, and |
| 552 | # googletest has a very straightforward build. |
Robert Sloan | a450c92 | 2018-01-08 10:35:32 -0800 | [diff] [blame] | 553 | add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc) |
| 554 | target_include_directories(boringssl_gtest PRIVATE third_party/googletest) |
David Benjamin | f31229b | 2017-01-25 14:08:15 -0500 | [diff] [blame] | 555 | |
| 556 | include_directories(third_party/googletest/include) |
| 557 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 558 | # Declare a dummy target to build all unit tests. Test targets should inject |
| 559 | # themselves as dependencies next to the target definition. |
| 560 | add_custom_target(all_tests) |
| 561 | |
Pete Bentley | f23caaf | 2020-09-22 18:02:11 +0100 | [diff] [blame] | 562 | # On Windows, CRYPTO_TEST_DATA is too long to fit in command-line limits. |
| 563 | # TODO(davidben): CMake 3.12 has a list(JOIN) command. Use that when we've |
| 564 | # updated the minimum version. |
| 565 | set(EMBED_TEST_DATA_ARGS "") |
| 566 | foreach(arg ${CRYPTO_TEST_DATA}) |
| 567 | set(EMBED_TEST_DATA_ARGS "${EMBED_TEST_DATA_ARGS}${arg}\n") |
| 568 | endforeach() |
| 569 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/embed_test_data_args.txt" |
| 570 | "${EMBED_TEST_DATA_ARGS}") |
| 571 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 572 | add_custom_command( |
| 573 | OUTPUT crypto_test_data.cc |
Pete Bentley | f23caaf | 2020-09-22 18:02:11 +0100 | [diff] [blame] | 574 | COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go -file-list |
| 575 | "${CMAKE_CURRENT_BINARY_DIR}/embed_test_data_args.txt" > |
| 576 | "${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc" |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 577 | DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA} |
| 578 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 579 | |
| 580 | add_library(crypto_test_data OBJECT crypto_test_data.cc) |
| 581 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 582 | add_subdirectory(crypto) |
| 583 | add_subdirectory(ssl) |
| 584 | add_subdirectory(ssl/test) |
| 585 | add_subdirectory(tool) |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame] | 586 | add_subdirectory(util/fipstools/cavp) |
| 587 | add_subdirectory(util/fipstools/acvp/modulewrapper) |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 588 | add_subdirectory(decrepit) |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 589 | |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 590 | if(FUZZ) |
Robert Sloan | 4c22c5f | 2019-03-01 15:53:37 -0800 | [diff] [blame] | 591 | if(LIBFUZZER_FROM_DEPS) |
| 592 | file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp") |
| 593 | add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES}) |
| 594 | # libFuzzer does not pass our aggressive warnings. It also must be built |
| 595 | # without -fsanitize-coverage options or clang crashes. |
| 596 | set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0") |
| 597 | endif() |
| 598 | |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 599 | add_subdirectory(fuzz) |
| 600 | endif() |
| 601 | |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 602 | if(UNIX AND NOT APPLE AND NOT ANDROID) |
| 603 | set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>) |
| 604 | endif() |
| 605 | |
Pete Bentley | 1748611 | 2021-01-20 11:51:47 +0000 | [diff] [blame] | 606 | if(FIPS) |
| 607 | add_custom_target( |
| 608 | acvp_tests |
| 609 | COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/acvptool |
| 610 | boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool |
| 611 | COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_BINARY_DIR}/testmodulewrapper |
| 612 | boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool/testmodulewrapper |
| 613 | COMMAND cd util/fipstools/acvp/acvptool/test && |
| 614 | ${GO_EXECUTABLE} run check_expected.go |
| 615 | -tool ${CMAKE_BINARY_DIR}/acvptool |
| 616 | -module-wrappers modulewrapper:$<TARGET_FILE:modulewrapper>,testmodulewrapper:${CMAKE_BINARY_DIR}/testmodulewrapper |
| 617 | -tests tests.json |
| 618 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 619 | DEPENDS modulewrapper |
| 620 | USES_TERMINAL) |
| 621 | |
| 622 | add_custom_target( |
| 623 | fips_specific_tests_if_any |
| 624 | DEPENDS acvp_tests |
| 625 | ) |
| 626 | else() |
| 627 | add_custom_target(fips_specific_tests_if_any) |
| 628 | endif() |
| 629 | |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 630 | add_custom_target( |
| 631 | run_tests |
| 632 | COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir |
| 633 | ${CMAKE_BINARY_DIR} |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 634 | COMMAND cd ssl/test/runner && |
| 635 | ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim> |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 636 | ${HANDSHAKER_ARGS} ${RUNNER_ARGS} |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 637 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
Pete Bentley | 1748611 | 2021-01-20 11:51:47 +0000 | [diff] [blame] | 638 | DEPENDS all_tests bssl_shim handshaker fips_specific_tests_if_any |
Pete Bentley | f23caaf | 2020-09-22 18:02:11 +0100 | [diff] [blame] | 639 | USES_TERMINAL) |