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