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