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