David Benjamin | a1843d6 | 2023-09-17 10:17:50 -0400 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.12) |
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) |
David Benjamin | 261ec61 | 2023-01-29 16:34:48 -0500 | [diff] [blame] | 19 | include(cmake/go.cmake) |
David Benjamin | b0b1f9d | 2023-04-19 17:18:27 -0400 | [diff] [blame] | 20 | include(cmake/paths.cmake) |
David Benjamin | 1967621 | 2023-01-25 10:03:53 -0500 | [diff] [blame] | 21 | include(cmake/perlasm.cmake) |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 22 | |
David Benjamin | 6b34d54 | 2016-02-05 21:58:39 -0500 | [diff] [blame] | 23 | enable_language(C) |
| 24 | enable_language(CXX) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 25 | |
Daniel Thornburgh | 48f7947 | 2022-04-25 20:52:43 +0000 | [diff] [blame] | 26 | include(GNUInstallDirs) |
| 27 | |
David Benjamin | e5f7266 | 2023-01-29 18:59:45 -0500 | [diff] [blame] | 28 | # CMake versions before 3.14 do not have default destination values. Executable |
| 29 | # and library targets that use a default destination should include this |
| 30 | # variable. |
| 31 | if(CMAKE_VERSION VERSION_LESS "3.14") |
| 32 | set(INSTALL_DESTINATION_DEFAULT |
| 33 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 34 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 35 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 36 | endif() |
| 37 | |
| 38 | # Wrap the CMake install function so we can disable it. |
| 39 | set(INSTALL_ENABLED 1) |
| 40 | function(install_if_enabled) |
| 41 | if(INSTALL_ENABLED) |
| 42 | install(${ARGV}) |
| 43 | endif() |
| 44 | endfunction() |
| 45 | |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 46 | if(ANDROID) |
David Benjamin | 261ec61 | 2023-01-29 16:34:48 -0500 | [diff] [blame] | 47 | # Android-NDK CMake files reconfigure the path and so Perl won't be found. |
| 48 | # 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] | 49 | if(NOT PERL_EXECUTABLE) |
| 50 | set(PERL_EXECUTABLE "perl") |
| 51 | endif() |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 52 | else() |
| 53 | find_package(Perl REQUIRED) |
Adam Langley | 843ab66 | 2015-04-28 17:46:58 -0700 | [diff] [blame] | 54 | endif() |
David Benjamin | 3ce3c36 | 2015-02-23 13:06:19 -0500 | [diff] [blame] | 55 | |
David Benjamin | f36c3ad | 2019-01-15 12:45:57 -0600 | [diff] [blame] | 56 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_CROSSCOMPILING) |
Adam Langley | 9dfaf25 | 2019-01-04 07:53:25 -0800 | [diff] [blame] | 57 | find_package(PkgConfig QUIET) |
| 58 | if (PkgConfig_FOUND) |
David Benjamin | f86dd18 | 2023-08-29 16:51:53 -0400 | [diff] [blame] | 59 | pkg_check_modules(LIBUNWIND libunwind-generic>=1.3.0) |
Adam Langley | 9dfaf25 | 2019-01-04 07:53:25 -0800 | [diff] [blame] | 60 | if(LIBUNWIND_FOUND) |
| 61 | add_definitions(-DBORINGSSL_HAVE_LIBUNWIND) |
| 62 | else() |
| 63 | message("libunwind not found. Disabling unwind tests.") |
| 64 | endif() |
David Benjamin | 17d553d | 2018-12-21 17:58:36 -0600 | [diff] [blame] | 65 | else() |
Adam Langley | 9dfaf25 | 2019-01-04 07:53:25 -0800 | [diff] [blame] | 66 | message("pkgconfig not found. Disabling unwind tests.") |
David Benjamin | 17d553d | 2018-12-21 17:58:36 -0600 | [diff] [blame] | 67 | endif() |
| 68 | endif() |
| 69 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 70 | if(USE_CUSTOM_LIBCXX) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 71 | set(BORINGSSL_ALLOW_CXX_RUNTIME 1) |
| 72 | endif() |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 73 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 74 | if(BORINGSSL_ALLOW_CXX_RUNTIME) |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 75 | add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME) |
| 76 | endif() |
| 77 | |
David Benjamin | 0de64a7 | 2019-09-26 15:59:40 -0400 | [diff] [blame] | 78 | string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) |
| 79 | if(NOT FIPS) |
| 80 | if(CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithassert" OR |
| 81 | NOT CMAKE_BUILD_TYPE_LOWER MATCHES "rel") |
| 82 | add_definitions(-DBORINGSSL_DISPATCH_TEST) |
| 83 | # CMake automatically connects include_directories to the NASM |
| 84 | # command-line, but not add_definitions. |
| 85 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_DISPATCH_TEST") |
| 86 | endif() |
Adam Langley | c161571 | 2018-11-27 14:07:12 -0800 | [diff] [blame] | 87 | endif() |
| 88 | |
David Benjamin | c47f793 | 2019-01-22 19:49:35 -0600 | [diff] [blame] | 89 | # Add a RelWithAsserts build configuration. It is the same as Release, except it |
| 90 | # does not define NDEBUG, so asserts run. |
| 91 | foreach(VAR CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_ASM_FLAGS) |
| 92 | string(REGEX REPLACE "(^| )[/-]DNDEBUG( |$)" " " "${VAR}_RELWITHASSERTS" |
| 93 | "${${VAR}_RELEASE}") |
| 94 | endforeach() |
| 95 | |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 96 | if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS) |
| 97 | add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}) |
David Benjamin | 8c23d3a | 2018-11-25 15:58:02 -0600 | [diff] [blame] | 98 | # CMake automatically connects include_directories to the NASM command-line, |
| 99 | # but not add_definitions. |
| 100 | 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] | 101 | |
| 102 | # Use "symbol_prefix_include" to store generated header files |
| 103 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include) |
| 104 | add_custom_command( |
| 105 | OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h |
| 106 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 107 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc |
| 108 | COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include |
| 109 | COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS} |
| 110 | DEPENDS util/make_prefix_headers.go |
David Benjamin | 8c75ed0 | 2023-02-05 13:44:26 -0500 | [diff] [blame] | 111 | ${BORINGSSL_PREFIX_SYMBOLS}) |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 112 | |
| 113 | # add_dependencies needs a target, not a file, so we add an intermediate |
| 114 | # target. |
| 115 | add_custom_target( |
| 116 | boringssl_prefix_symbols |
| 117 | DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h |
| 118 | symbol_prefix_include/boringssl_prefix_symbols_asm.h |
| 119 | symbol_prefix_include/boringssl_prefix_symbols_nasm.inc) |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 120 | elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS) |
| 121 | message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS") |
David Benjamin | 8c75ed0 | 2023-02-05 13:44:26 -0500 | [diff] [blame] | 122 | else() |
| 123 | add_custom_target(boringssl_prefix_symbols) |
Joshua Liebow-Feeser | 8c7c635 | 2018-08-26 18:53:36 -0700 | [diff] [blame] | 124 | endif() |
| 125 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 126 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 127 | set(CLANG 1) |
| 128 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 129 | |
Alexei Lozovsky | 356a9a0 | 2019-04-10 14:50:55 +0300 | [diff] [blame] | 130 | if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") |
| 131 | set(EMSCRIPTEN 1) |
| 132 | endif() |
| 133 | |
David Benjamin | a928171 | 2022-05-20 12:41:15 -0400 | [diff] [blame] | 134 | set(CMAKE_CXX_STANDARD 14) |
| 135 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
David Benjamin | c371b8b | 2023-01-25 17:14:35 -0500 | [diff] [blame] | 136 | set(CMAKE_C_STANDARD 11) |
| 137 | set(CMAKE_C_STANDARD_REQUIRED ON) |
David Benjamin | a928171 | 2022-05-20 12:41:15 -0400 | [diff] [blame] | 138 | |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 139 | if(CMAKE_COMPILER_IS_GNUCXX OR CLANG) |
| 140 | # 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] | 141 | # primarily on our normal Clang one. |
Bob Beck | bc97b7a | 2023-04-18 08:35:15 -0600 | [diff] [blame] | 142 | # TODO(bbe) took out -Wmissing-field-initializers for pki - fix and put back or disable only for pki |
| 143 | set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wwrite-strings -Wvla -Wshadow -Wtype-limits") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 144 | if(MSVC) |
David Benjamin | 8d67f6f | 2018-01-05 15:43:09 -0500 | [diff] [blame] | 145 | # clang-cl sets different default warnings than clang. It also treats -Wall |
| 146 | # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall. |
| 147 | # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116 |
| 148 | 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] | 149 | else() |
Alexei Lozovsky | 356a9a0 | 2019-04-10 14:50:55 +0300 | [diff] [blame] | 150 | if(EMSCRIPTEN) |
| 151 | # emscripten's emcc/clang does not accept the "-ggdb" flag. |
| 152 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -g") |
| 153 | else() |
| 154 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb") |
| 155 | endif() |
| 156 | |
| 157 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -fvisibility=hidden -fno-common") |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 158 | endif() |
| 159 | |
| 160 | if(CLANG) |
David Benjamin | 9fb6fea | 2017-07-31 14:03:38 -0400 | [diff] [blame] | 161 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics") |
Adam Langley | 5c38c05 | 2017-04-28 14:47:06 -0700 | [diff] [blame] | 162 | else() |
| 163 | # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls |
| 164 | # and declare that the code is trying to free a stack pointer. |
| 165 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object") |
David Benjamin | 9b7d836 | 2016-08-29 14:59:31 -0400 | [diff] [blame] | 166 | endif() |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 167 | |
David Benjamin | 7d1fc2b | 2022-10-14 08:44:15 -0400 | [diff] [blame] | 168 | # -Wstring-concatenation was added in Clang 12.0.0, which corresponds to |
| 169 | # AppleClang 13.0.0 per the table in |
| 170 | # https://en.wikipedia.org/wiki/Xcode#Toolchain_versions |
| 171 | if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND |
| 172 | CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0") OR |
| 173 | (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND |
| 174 | CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0.0")) |
| 175 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wstring-concatenation") |
| 176 | endif() |
| 177 | |
David Benjamin | c8d3137 | 2022-07-12 11:46:03 -0400 | [diff] [blame] | 178 | 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] | 179 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough") |
| 180 | endif() |
| 181 | |
David Benjamin | d7936c2 | 2021-12-15 17:25:10 -0500 | [diff] [blame] | 182 | if(CMAKE_COMPILER_IS_GNUCXX) |
| 183 | set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wformat-signedness") |
| 184 | endif() |
| 185 | |
Adam Langley | 0186787 | 2016-06-30 14:16:59 -0700 | [diff] [blame] | 186 | 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] | 187 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations") |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 188 | |
David Benjamin | a928171 | 2022-05-20 12:41:15 -0400 | [diff] [blame] | 189 | if(NOT MSVC AND NOT BORINGSSL_ALLOW_CXX_RUNTIME) |
| 190 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
David Benjamin | 2507d9e | 2017-07-26 11:39:38 -0400 | [diff] [blame] | 191 | endif() |
| 192 | |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 193 | # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes |
| 194 | # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the |
| 195 | # spelling for both and -Wmissing-declarations is some other warning. |
| 196 | # |
| 197 | # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options |
| 198 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes |
| 199 | # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 200 | if(CLANG) |
Vincent Batts | 60931e2 | 2017-09-20 11:51:54 -0400 | [diff] [blame] | 201 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes") |
David Benjamin | 4a8d1f3 | 2017-07-13 17:53:07 -0400 | [diff] [blame] | 202 | endif() |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 203 | elseif(MSVC) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 204 | set(MSVC_DISABLED_WARNINGS_LIST |
| 205 | "C4100" # 'exarg' : unreferenced formal parameter |
| 206 | "C4127" # conditional expression is constant |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 207 | "C4244" # 'function' : conversion from 'int' to 'uint8_t', |
| 208 | # possible loss of data |
David Benjamin | 3673be7 | 2015-02-11 15:12:05 -0500 | [diff] [blame] | 209 | "C4267" # conversion from 'size_t' to 'int', possible loss of data |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 210 | "C4706" # assignment within conditional expression |
David Benjamin | 7acd6bc | 2016-05-02 12:57:01 -0400 | [diff] [blame] | 211 | ) |
Brian Smith | efed221 | 2015-01-28 16:20:02 -0800 | [diff] [blame] | 212 | string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR |
| 213 | ${MSVC_DISABLED_WARNINGS_LIST}) |
David Benjamin | 3251ca1 | 2023-01-12 16:04:58 -0500 | [diff] [blame] | 214 | set(CMAKE_C_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}") |
| 215 | set(CMAKE_CXX_FLAGS "-utf-8 -W4 -WX ${MSVC_DISABLED_WARNINGS_STR}") |
David Benjamin | e2568c4 | 2017-08-16 15:25:27 -0400 | [diff] [blame] | 216 | endif() |
| 217 | |
| 218 | if(WIN32) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 219 | add_definitions(-D_HAS_EXCEPTIONS=0) |
Brian Smith | a87de9b | 2015-01-28 20:34:47 -0800 | [diff] [blame] | 220 | add_definitions(-DWIN32_LEAN_AND_MEAN) |
David Benjamin | 0e434b9 | 2015-04-02 13:20:01 -0400 | [diff] [blame] | 221 | add_definitions(-DNOMINMAX) |
David Benjamin | 9b6ff44 | 2017-06-15 20:44:30 -0400 | [diff] [blame] | 222 | # Allow use of fopen. |
| 223 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 224 | endif() |
| 225 | |
David Benjamin | 387f820 | 2022-01-25 12:16:48 -0500 | [diff] [blame] | 226 | # pthread_rwlock_t on Linux requires a feature flag. We limit this to Linux |
| 227 | # because, on Apple platforms, it instead disables APIs we use. See compat(5) |
| 228 | # and sys/cdefs.h. Reportedly, FreeBSD also breaks when this is set. See |
| 229 | # https://crbug.com/boringssl/471. |
| 230 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
David Benjamin | 2e8ba2d | 2016-06-09 16:22:26 -0400 | [diff] [blame] | 231 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700") |
Adam Langley | 6f2e733 | 2015-05-15 12:01:29 -0700 | [diff] [blame] | 232 | endif() |
| 233 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 234 | if(FUZZ) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 235 | if(NOT CLANG) |
Alessandro Ghedini | b6f6927 | 2016-09-28 22:14:01 +0100 | [diff] [blame] | 236 | 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] | 237 | endif() |
| 238 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 239 | if(CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0") |
| 240 | message(FATAL_ERROR "You need Clang ≥ 6.0.0") |
| 241 | endif() |
| 242 | |
David Benjamin | ec978dd | 2016-11-04 18:59:33 -0400 | [diff] [blame] | 243 | add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE) |
| 244 | set(RUNNER_ARGS "-deterministic") |
| 245 | |
| 246 | if(NOT NO_FUZZER_MODE) |
| 247 | add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE) |
| 248 | set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json") |
| 249 | endif() |
David Benjamin | bc5b2a2 | 2016-03-01 22:57:32 -0500 | [diff] [blame] | 250 | |
Adam Langley | 9c969bf | 2018-08-24 10:46:01 -0700 | [diff] [blame] | 251 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address,fuzzer-no-link -fsanitize-coverage=edge,indirect-calls") |
| 252 | 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] | 253 | endif() |
| 254 | |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 255 | add_definitions(-DBORINGSSL_IMPLEMENTATION) |
| 256 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 257 | if(BUILD_SHARED_LIBS) |
Adam Langley | 4a0f0c4 | 2015-01-28 16:37:10 -0800 | [diff] [blame] | 258 | add_definitions(-DBORINGSSL_SHARED_LIBRARY) |
| 259 | # Enable position-independent code globally. This is needed because |
| 260 | # some library targets are OBJECT libraries. |
| 261 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
David Benjamin | 507c1ee | 2015-01-28 00:50:21 -0500 | [diff] [blame] | 262 | endif() |
| 263 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 264 | if(MSAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 265 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 266 | message(FATAL_ERROR "Cannot enable MSAN unless using Clang") |
| 267 | endif() |
| 268 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 269 | if(ASAN) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 270 | message(FATAL_ERROR "ASAN and MSAN are mutually exclusive") |
| 271 | endif() |
| 272 | |
| 273 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") |
| 274 | 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] | 275 | 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] | 276 | endif() |
| 277 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 278 | if(ASAN) |
David Benjamin | 02afbd3 | 2017-10-05 15:04:08 -0400 | [diff] [blame] | 279 | if(NOT CLANG) |
Adam Langley | 1bcd10c | 2016-12-16 10:48:23 -0800 | [diff] [blame] | 280 | message(FATAL_ERROR "Cannot enable ASAN unless using Clang") |
| 281 | endif() |
| 282 | |
David Benjamin | 0d3c963 | 2017-02-28 14:58:00 -0500 | [diff] [blame] | 283 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") |
| 284 | 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] | 285 | endif() |
| 286 | |
David Benjamin | c367ee5 | 2017-11-21 08:16:42 -0500 | [diff] [blame] | 287 | if(CFI) |
| 288 | if(NOT CLANG) |
| 289 | message(FATAL_ERROR "Cannot enable CFI unless using Clang") |
| 290 | endif() |
| 291 | |
David Benjamin | 6650898 | 2018-09-22 16:19:15 -0500 | [diff] [blame] | 292 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -flto=thin") |
| 293 | 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] | 294 | # We use Chromium's copy of clang, which requires -fuse-ld=lld if building |
| 295 | # with -flto. That, in turn, can't handle -ggdb. |
| 296 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 297 | string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 298 | string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 299 | # -flto causes object files to contain LLVM bitcode. Mixing those with |
| 300 | # assembly output in the same static library breaks the linker. |
| 301 | set(OPENSSL_NO_ASM "1") |
| 302 | endif() |
| 303 | |
David Benjamin | 5852cfc | 2018-07-19 17:50:45 -0400 | [diff] [blame] | 304 | if(TSAN) |
| 305 | if(NOT CLANG) |
| 306 | message(FATAL_ERROR "Cannot enable TSAN unless using Clang") |
| 307 | endif() |
| 308 | |
| 309 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") |
| 310 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") |
| 311 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") |
| 312 | endif() |
| 313 | |
David Benjamin | fc27a19 | 2019-01-21 07:25:12 +0000 | [diff] [blame] | 314 | if(UBSAN) |
| 315 | if(NOT CLANG) |
| 316 | message(FATAL_ERROR "Cannot enable UBSAN unless using Clang") |
| 317 | endif() |
| 318 | |
| 319 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") |
| 320 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") |
| 321 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") |
| 322 | |
| 323 | if(NOT UBSAN_RECOVER) |
| 324 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-sanitize-recover=undefined") |
| 325 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-sanitize-recover=undefined") |
| 326 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-sanitize-recover=undefined") |
| 327 | endif() |
| 328 | endif() |
| 329 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 330 | if(GCOV) |
David Benjamin | d035ab3 | 2016-12-27 12:15:56 -0500 | [diff] [blame] | 331 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") |
| 332 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") |
| 333 | endif() |
| 334 | |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 335 | if(FIPS) |
| 336 | add_definitions(-DBORINGSSL_FIPS) |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 337 | if(FIPS_BREAK_TEST) |
| 338 | add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1") |
| 339 | endif() |
Adam Langley | d72e47f | 2019-05-09 16:39:49 -0700 | [diff] [blame] | 340 | # The FIPS integrity check does not work for ASan and MSan builds. |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 341 | if(NOT ASAN AND NOT MSAN) |
Adam Langley | d72e47f | 2019-05-09 16:39:49 -0700 | [diff] [blame] | 342 | if(BUILD_SHARED_LIBS) |
| 343 | set(FIPS_SHARED "1") |
| 344 | else() |
| 345 | set(FIPS_DELOCATE "1") |
| 346 | endif() |
Adam Langley | f64a6ee | 2017-05-17 13:05:50 -0700 | [diff] [blame] | 347 | endif() |
David Benjamin | e481d94 | 2019-10-18 16:43:12 -0400 | [diff] [blame] | 348 | if(FIPS_SHARED) |
| 349 | # The Android CMake files set -ffunction-sections and -fdata-sections, |
| 350 | # which is incompatible with FIPS_SHARED. |
| 351 | set(CMAKE_C_FLAGS |
| 352 | "${CMAKE_C_FLAGS} -fno-function-sections -fno-data-sections") |
| 353 | set(CMAKE_CXX_FLAGS |
| 354 | "${CMAKE_CXX_FLAGS} -fno-function-sections -fno-data-sections") |
| 355 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 356 | endif() |
| 357 | |
David Benjamin | 6291af4 | 2018-03-23 13:49:27 -0400 | [diff] [blame] | 358 | if(OPENSSL_SMALL) |
| 359 | add_definitions(-DOPENSSL_SMALL) |
| 360 | endif() |
| 361 | |
Adam Langley | a6a049a | 2018-12-06 17:15:58 -0800 | [diff] [blame] | 362 | if(CONSTANT_TIME_VALIDATION) |
| 363 | add_definitions(-DBORINGSSL_CONSTANT_TIME_VALIDATION) |
| 364 | # Asserts will often test secret data. |
| 365 | add_definitions(-DNDEBUG) |
| 366 | endif() |
| 367 | |
David Benjamin | 582904f | 2023-02-04 18:30:36 -0500 | [diff] [blame] | 368 | if(MALLOC_FAILURE_TESTING) |
| 369 | add_definitions(-DBORINGSSL_MALLOC_FAILURE_TESTING) |
| 370 | endif() |
| 371 | |
David Benjamin | 1967621 | 2023-01-25 10:03:53 -0500 | [diff] [blame] | 372 | if(OPENSSL_NO_ASM) |
| 373 | add_definitions(-DOPENSSL_NO_ASM) |
| 374 | endif() |
| 375 | |
| 376 | if(FIPS_DELOCATE OR NOT OPENSSL_NO_ASM) |
| 377 | # On x86 and x86_64 Windows, we use the NASM output. |
| 378 | if(WIN32 AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|x86_64|amd64|x86|i[3-6]86") |
| 379 | enable_language(ASM_NASM) |
| 380 | set(OPENSSL_NASM TRUE) |
| 381 | set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -gcv8") |
| 382 | else() |
| 383 | enable_language(ASM) |
| 384 | set(OPENSSL_ASM TRUE) |
David Benjamin | 61266e4 | 2023-01-29 15:53:30 -0500 | [diff] [blame] | 385 | # Work around https://gitlab.kitware.com/cmake/cmake/-/issues/20771 in older |
| 386 | # CMake versions. |
| 387 | if(APPLE AND CMAKE_VERSION VERSION_LESS 3.19) |
David Benjamin | 1967621 | 2023-01-25 10:03:53 -0500 | [diff] [blame] | 388 | if(CMAKE_OSX_SYSROOT) |
| 389 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -isysroot \"${CMAKE_OSX_SYSROOT}\"") |
| 390 | endif() |
| 391 | foreach(arch ${CMAKE_OSX_ARCHITECTURES}) |
| 392 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -arch ${arch}") |
| 393 | endforeach() |
| 394 | endif() |
| 395 | if(NOT WIN32) |
| 396 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,--noexecstack") |
| 397 | endif() |
| 398 | # Clang's integerated assembler does not support debug symbols. |
| 399 | if(NOT CMAKE_ASM_COMPILER_ID MATCHES "Clang") |
| 400 | set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g") |
| 401 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 402 | endif() |
David Benjamin | aff72a3 | 2017-04-06 23:26:04 -0400 | [diff] [blame] | 403 | endif() |
| 404 | |
David Benjamin | 6887d5e | 2019-12-17 13:56:30 -0500 | [diff] [blame] | 405 | if(OPENSSL_NO_SSE2_FOR_TESTING) |
| 406 | add_definitions(-DOPENSSL_NO_SSE2_FOR_TESTING) |
| 407 | endif() |
| 408 | |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 409 | if(USE_CUSTOM_LIBCXX) |
| 410 | if(NOT CLANG) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 411 | message(FATAL_ERROR "USE_CUSTOM_LIBCXX only supported with Clang") |
| 412 | endif() |
| 413 | |
David Benjamin | e5f7266 | 2023-01-29 18:59:45 -0500 | [diff] [blame] | 414 | # CMake does not allow installing a library without installing dependencies. |
| 415 | # If we installed libcrypto, we'd have to install our custom libc++, which |
| 416 | # does not make sense. As this is a test-only configuration, disable |
| 417 | # installing. |
| 418 | set(INSTALL_ENABLED 0) |
| 419 | |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 420 | # CMAKE_CXX_FLAGS ends up in the linker flags as well, so use |
| 421 | # add_compile_options. There does not appear to be a way to set |
| 422 | # language-specific compile-only flags. |
| 423 | add_compile_options("-nostdinc++") |
| 424 | set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -nostdlib++") |
| 425 | include_directories( |
| 426 | SYSTEM |
David Benjamin | 16b3af7 | 2021-10-26 17:07:39 -0400 | [diff] [blame] | 427 | util/bot/libcxx-config |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 428 | util/bot/libcxx/include |
| 429 | util/bot/libcxxabi/include |
| 430 | ) |
| 431 | |
| 432 | # This is patterned after buildtools/third_party/libc++/BUILD.gn and |
| 433 | # buildtools/third_party/libc++abi/BUILD.gn in Chromium. |
| 434 | |
| 435 | file(GLOB LIBCXX_SOURCES "util/bot/libcxx/src/*.cpp") |
| 436 | file(GLOB LIBCXXABI_SOURCES "util/bot/libcxxabi/src/*.cpp") |
| 437 | |
| 438 | # This file is meant for exception-less builds. |
| 439 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_noexception.cpp") |
| 440 | # libc++ also defines new and delete. |
| 441 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/stdlib_new_delete.cpp") |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 442 | if(TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 443 | # ThreadSanitizer tries to intercept these symbols. Skip them to avoid |
| 444 | # symbol conflicts. |
| 445 | list(REMOVE_ITEM LIBCXXABI_SOURCES "trunk/src/cxa_guard.cpp") |
| 446 | endif() |
| 447 | |
| 448 | add_library(libcxxabi ${LIBCXXABI_SOURCES}) |
| 449 | target_compile_definitions( |
| 450 | libcxxabi PRIVATE |
| 451 | -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS |
| 452 | ) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 453 | |
| 454 | add_library(libcxx ${LIBCXX_SOURCES}) |
David Benjamin | e6fd125 | 2018-08-10 10:30:55 -0500 | [diff] [blame] | 455 | if(ASAN OR MSAN OR TSAN) |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 456 | # Sanitizers try to intercept new and delete. |
| 457 | target_compile_definitions( |
| 458 | libcxx PRIVATE |
| 459 | -D_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS |
| 460 | ) |
| 461 | endif() |
| 462 | target_compile_definitions( |
| 463 | libcxx PRIVATE |
| 464 | -D_LIBCPP_BUILDING_LIBRARY |
| 465 | -DLIBCXX_BUILDING_LIBCXXABI |
| 466 | ) |
David Benjamin | aa72a6c | 2022-11-21 15:27:15 -0500 | [diff] [blame] | 467 | set_target_properties( |
| 468 | libcxx libcxxabi PROPERTIES |
| 469 | COMPILE_FLAGS "-Wno-missing-prototypes -Wno-implicit-fallthrough" |
| 470 | # libc++ and libc++abi must be built in C++20 mode. |
| 471 | CXX_STANDARD 20 |
| 472 | CXX_STANDARD_REQUIRED TRUE |
| 473 | ) |
| 474 | # libc++abi depends on libc++ internal headers. |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 475 | set_property(TARGET libcxx libcxxabi APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/util/bot/libcxx/src") |
David Benjamin | e9ae99b | 2018-08-09 15:33:07 -0500 | [diff] [blame] | 476 | target_link_libraries(libcxx libcxxabi) |
| 477 | endif() |
| 478 | |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 479 | # Add minimal googletest targets. The provided one has many side-effects, and |
| 480 | # googletest has a very straightforward build. |
David Benjamin | fa343af | 2023-09-01 21:23:01 -0400 | [diff] [blame] | 481 | add_library( |
| 482 | boringssl_gtest |
| 483 | third_party/googletest/googlemock/src/gmock-all.cc |
| 484 | third_party/googletest/googletest/src/gtest-all.cc |
| 485 | ) |
David Benjamin | 987dff1 | 2023-02-15 11:04:01 -0500 | [diff] [blame] | 486 | if(USE_CUSTOM_LIBCXX) |
| 487 | target_link_libraries(boringssl_gtest libcxx) |
| 488 | endif() |
David Benjamin | 8bc06cf | 2023-02-04 20:05:04 -0500 | [diff] [blame] | 489 | target_include_directories( |
| 490 | boringssl_gtest |
David Benjamin | fa343af | 2023-09-01 21:23:01 -0400 | [diff] [blame] | 491 | PUBLIC |
| 492 | third_party/googletest/googlemock/include |
| 493 | third_party/googletest/googletest/include |
| 494 | PRIVATE |
| 495 | third_party/googletest/googlemock |
| 496 | third_party/googletest/googletest |
David Benjamin | 8bc06cf | 2023-02-04 20:05:04 -0500 | [diff] [blame] | 497 | ) |
David Benjamin | 9662843 | 2017-01-19 19:05:47 -0500 | [diff] [blame] | 498 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 499 | # Declare a dummy target to build all unit tests. Test targets should inject |
| 500 | # themselves as dependencies next to the target definition. |
| 501 | add_custom_target(all_tests) |
| 502 | |
David Benjamin | cbac9c3 | 2020-06-18 16:14:24 -0400 | [diff] [blame] | 503 | # On Windows, CRYPTO_TEST_DATA is too long to fit in command-line limits. |
| 504 | # TODO(davidben): CMake 3.12 has a list(JOIN) command. Use that when we've |
| 505 | # updated the minimum version. |
| 506 | set(EMBED_TEST_DATA_ARGS "") |
| 507 | foreach(arg ${CRYPTO_TEST_DATA}) |
| 508 | set(EMBED_TEST_DATA_ARGS "${EMBED_TEST_DATA_ARGS}${arg}\n") |
| 509 | endforeach() |
| 510 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/embed_test_data_args.txt" |
| 511 | "${EMBED_TEST_DATA_ARGS}") |
| 512 | |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 513 | add_custom_command( |
| 514 | OUTPUT crypto_test_data.cc |
David Benjamin | cbac9c3 | 2020-06-18 16:14:24 -0400 | [diff] [blame] | 515 | COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go -file-list |
| 516 | "${CMAKE_CURRENT_BINARY_DIR}/embed_test_data_args.txt" > |
| 517 | "${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc" |
David Benjamin | 3ecd0a5 | 2017-05-19 15:26:18 -0400 | [diff] [blame] | 518 | DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA} |
| 519 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
| 520 | |
| 521 | add_library(crypto_test_data OBJECT crypto_test_data.cc) |
| 522 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 523 | add_subdirectory(crypto) |
| 524 | add_subdirectory(ssl) |
| 525 | add_subdirectory(ssl/test) |
Adam Langley | ea9fb94 | 2022-02-07 12:32:09 -0800 | [diff] [blame] | 526 | add_subdirectory(util/fipstools) |
Adam Langley | b7f0c1b | 2019-07-09 18:02:14 -0700 | [diff] [blame] | 527 | add_subdirectory(util/fipstools/acvp/modulewrapper) |
Adam Langley | c004dfc | 2015-02-03 10:45:12 -0800 | [diff] [blame] | 528 | add_subdirectory(decrepit) |
David Benjamin | 9bbf0d9 | 2023-06-30 13:17:03 -0400 | [diff] [blame] | 529 | |
David Benjamin | 847a395 | 2023-06-30 15:05:24 -0400 | [diff] [blame] | 530 | add_library(test_support_lib STATIC ${TEST_SUPPORT_SOURCES}) |
| 531 | if (LIBUNWIND_FOUND) |
| 532 | target_compile_options(test_support_lib PRIVATE ${LIBUNWIND_CFLAGS_OTHER}) |
| 533 | target_include_directories(test_support_lib PRIVATE ${LIBUNWIND_INCLUDE_DIRS}) |
| 534 | target_link_libraries(test_support_lib ${LIBUNWIND_LDFLAGS}) |
| 535 | endif() |
| 536 | if(WIN32) |
| 537 | target_link_libraries(test_support_lib dbghelp) |
| 538 | endif() |
| 539 | target_link_libraries(test_support_lib boringssl_gtest crypto) |
| 540 | |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 541 | # urandom_test is a separate binary because it needs to be able to observe the |
| 542 | # PRNG initialisation, which means that it can't have other tests running before |
| 543 | # it does. |
| 544 | add_executable(urandom_test ${URANDOM_TEST_SOURCES}) |
| 545 | target_link_libraries(urandom_test test_support_lib boringssl_gtest crypto) |
| 546 | add_dependencies(all_tests urandom_test) |
| 547 | |
| 548 | add_executable(crypto_test ${CRYPTO_TEST_SOURCES} $<TARGET_OBJECTS:crypto_test_data>) |
David Benjamin | 847a395 | 2023-06-30 15:05:24 -0400 | [diff] [blame] | 549 | target_link_libraries(crypto_test test_support_lib boringssl_gtest crypto) |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 550 | add_dependencies(all_tests crypto_test) |
| 551 | |
| 552 | add_executable(ssl_test ${SSL_TEST_SOURCES}) |
David Benjamin | 847a395 | 2023-06-30 15:05:24 -0400 | [diff] [blame] | 553 | target_link_libraries(ssl_test test_support_lib boringssl_gtest ssl crypto) |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 554 | add_dependencies(all_tests ssl_test) |
| 555 | |
| 556 | add_executable(decrepit_test ${DECREPIT_TEST_SOURCES}) |
David Benjamin | 847a395 | 2023-06-30 15:05:24 -0400 | [diff] [blame] | 557 | target_link_libraries(decrepit_test test_support_lib boringssl_gtest |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 558 | decrepit crypto) |
| 559 | add_dependencies(all_tests decrepit_test) |
| 560 | |
David Benjamin | 9bbf0d9 | 2023-06-30 13:17:03 -0400 | [diff] [blame] | 561 | if(APPLE) |
| 562 | set(PKI_CXX_FLAGS "-fno-aligned-new") |
| 563 | endif() |
| 564 | |
| 565 | add_library(pki ${PKI_SOURCES}) |
David Benjamin | 9bbf0d9 | 2023-06-30 13:17:03 -0400 | [diff] [blame] | 566 | target_link_libraries(pki crypto) |
| 567 | |
| 568 | add_executable(pki_test ${PKI_TEST_SOURCES}) |
David Benjamin | 847a395 | 2023-06-30 15:05:24 -0400 | [diff] [blame] | 569 | target_link_libraries(pki_test test_support_lib boringssl_gtest pki crypto) |
David Benjamin | 9bbf0d9 | 2023-06-30 13:17:03 -0400 | [diff] [blame] | 570 | add_dependencies(all_tests pki_test) |
| 571 | |
| 572 | # The PKI library requires C++17. |
| 573 | set_target_properties( |
| 574 | pki pki_test |
| 575 | PROPERTIES |
| 576 | CXX_STANDARD 17 |
| 577 | CXX_STANDARD_REQUIRED YES |
| 578 | COMPILE_FLAGS "${PKI_CXX_FLAGS}") |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 579 | |
David Benjamin | 99ce1e0 | 2023-06-30 15:43:24 -0400 | [diff] [blame] | 580 | add_executable(bssl ${BSSL_SOURCES}) |
| 581 | install_if_enabled(TARGETS bssl DESTINATION ${INSTALL_DESTINATION_DEFAULT}) |
| 582 | target_link_libraries(bssl ssl crypto) |
| 583 | |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 584 | # Historically, targets were built in subdirectories. For compatibility with |
| 585 | # existing tools, we, for now, copy the targets into the subdirectories. This |
| 586 | # will be removed sometime in 2024. |
| 587 | copy_post_build(crypto crypto_test urandom_test) |
| 588 | copy_post_build(ssl ssl_test) |
| 589 | copy_post_build(decrepit decrepit_test) |
David Benjamin | 99ce1e0 | 2023-06-30 15:43:24 -0400 | [diff] [blame] | 590 | copy_post_build(tool bssl) |
David Benjamin | 197b571 | 2023-06-30 14:10:42 -0400 | [diff] [blame] | 591 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 592 | if(FUZZ) |
David Benjamin | 6c597be | 2019-01-07 15:13:04 -0600 | [diff] [blame] | 593 | if(LIBFUZZER_FROM_DEPS) |
| 594 | file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp") |
| 595 | add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES}) |
| 596 | # libFuzzer does not pass our aggressive warnings. It also must be built |
| 597 | # without -fsanitize-coverage options or clang crashes. |
| 598 | set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0") |
| 599 | endif() |
| 600 | |
Adam Langley | 9a4beb8 | 2015-11-09 13:57:26 -0800 | [diff] [blame] | 601 | add_subdirectory(fuzz) |
| 602 | endif() |
| 603 | |
Benjamin Brittain | ea46caf | 2022-01-20 15:50:12 -0500 | [diff] [blame] | 604 | if(RUST_BINDINGS) |
| 605 | find_program(BINDGEN_EXECUTABLE bindgen) |
| 606 | if(NOT BINDGEN_EXECUTABLE) |
| 607 | message(FATAL_ERROR "Could not find bindgen but was asked to generate Rust bindings.") |
| 608 | else() |
| 609 | add_subdirectory(rust) |
| 610 | endif() |
| 611 | endif() |
| 612 | |
David Benjamin | 0f4454c | 2022-01-26 14:17:08 -0500 | [diff] [blame] | 613 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 614 | set(HANDSHAKER_ARGS "-handshaker-path" $<TARGET_FILE:handshaker>) |
| 615 | endif() |
| 616 | |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 617 | if(FIPS) |
| 618 | add_custom_target( |
| 619 | acvp_tests |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 620 | COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/acvptool |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 621 | boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 622 | COMMAND ${GO_EXECUTABLE} build -o ${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 623 | boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool/testmodulewrapper |
| 624 | COMMAND cd util/fipstools/acvp/acvptool/test && |
| 625 | ${GO_EXECUTABLE} run check_expected.go |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 626 | -tool ${CMAKE_CURRENT_BINARY_DIR}/acvptool |
| 627 | -module-wrappers modulewrapper:$<TARGET_FILE:modulewrapper>,testmodulewrapper:${CMAKE_CURRENT_BINARY_DIR}/testmodulewrapper |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 628 | -tests tests.json |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 629 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 630 | DEPENDS modulewrapper |
| 631 | USES_TERMINAL) |
| 632 | |
| 633 | add_custom_target( |
| 634 | fips_specific_tests_if_any |
| 635 | DEPENDS acvp_tests |
| 636 | ) |
| 637 | else() |
| 638 | add_custom_target(fips_specific_tests_if_any) |
| 639 | endif() |
| 640 | |
David Benjamin | 49bfec5 | 2023-06-30 13:07:24 -0400 | [diff] [blame] | 641 | file(STRINGS util/go_tests.txt GO_TESTS) |
David Benjamin | f53ca9f | 2023-02-24 09:07:36 -0500 | [diff] [blame] | 642 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS |
| 643 | util/go_tests.txt) |
| 644 | |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 645 | add_custom_target( |
| 646 | run_tests |
David Benjamin | e3a5fac | 2023-02-27 16:36:24 -0500 | [diff] [blame] | 647 | COMMAND ${GO_EXECUTABLE} test ${GO_TESTS} |
David Benjamin | 301afaf | 2015-10-14 21:34:40 -0400 | [diff] [blame] | 648 | COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 649 | ${CMAKE_CURRENT_BINARY_DIR} |
Adam Langley | d5c72c8 | 2016-09-23 16:43:17 -0700 | [diff] [blame] | 650 | COMMAND cd ssl/test/runner && |
| 651 | ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim> |
David Benjamin | 17dc94e | 2018-08-10 09:05:20 -0500 | [diff] [blame] | 652 | ${HANDSHAKER_ARGS} ${RUNNER_ARGS} |
David Benjamin | 8c4ec3b | 2023-02-27 12:46:12 -0500 | [diff] [blame] | 653 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
Adam Langley | 4f75b76 | 2020-12-17 14:06:25 -0800 | [diff] [blame] | 654 | DEPENDS all_tests bssl_shim handshaker fips_specific_tests_if_any |
David Benjamin | 81a998a | 2020-05-26 11:35:58 -0400 | [diff] [blame] | 655 | USES_TERMINAL) |
Daniel Thornburgh | 2fc6d38 | 2022-04-04 11:23:56 -0700 | [diff] [blame] | 656 | |
David Benjamin | e5f7266 | 2023-01-29 18:59:45 -0500 | [diff] [blame] | 657 | install_if_enabled(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
Daniel Thornburgh | 2fc6d38 | 2022-04-04 11:23:56 -0700 | [diff] [blame] | 658 | |
David Benjamin | e5f7266 | 2023-01-29 18:59:45 -0500 | [diff] [blame] | 659 | install_if_enabled(EXPORT OpenSSLTargets |
Daniel Thornburgh | 2fc6d38 | 2022-04-04 11:23:56 -0700 | [diff] [blame] | 660 | FILE OpenSSLTargets.cmake |
| 661 | NAMESPACE OpenSSL:: |
| 662 | DESTINATION lib/cmake/OpenSSL |
| 663 | ) |
David Benjamin | e5f7266 | 2023-01-29 18:59:45 -0500 | [diff] [blame] | 664 | install_if_enabled(FILES cmake/OpenSSLConfig.cmake DESTINATION lib/cmake/OpenSSL) |