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