blob: 46a8465a677a4087611c3e5104a8d5c243aa1888 [file] [log] [blame]
David Benjaminf31229b2017-01-25 14:08:15 -05001cmake_minimum_required (VERSION 2.8.11)
Adam Langleyd9e397b2015-01-22 14:27:53 -08002
Robert Sloancd79cde2017-12-11 09:06:12 -08003# Report AppleClang separately from Clang. Their version numbers are different.
4# https://cmake.org/cmake/help/v3.0/policy/CMP0025.html
5if(POLICY CMP0025)
6 cmake_policy(SET CMP0025 NEW)
7endif()
8
David Benjamin4969cc92016-04-22 15:02:23 -04009# Defer enabling C and CXX languages.
10project (BoringSSL NONE)
11
12if(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)
16endif()
17
Robert Sloan8ff03552017-06-14 12:40:58 -070018include(sources.cmake)
19
David Benjamin4969cc92016-04-22 15:02:23 -040020enable_language(C)
21enable_language(CXX)
Adam Langleyd9e397b2015-01-22 14:27:53 -080022
Adam Langleye9ada862015-05-11 17:20:37 -070023if(ANDROID)
24 # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
25 # found. However, ninja will still find them in $PATH if we just name them.
David Benjamind316cba2016-06-02 16:17:39 -040026 if(NOT PERL_EXECUTABLE)
27 set(PERL_EXECUTABLE "perl")
28 endif()
29 if(NOT GO_EXECUTABLE)
30 set(GO_EXECUTABLE "go")
31 endif()
Adam Langleye9ada862015-05-11 17:20:37 -070032else()
33 find_package(Perl REQUIRED)
34 find_program(GO_EXECUTABLE go)
35endif()
36
37if (NOT GO_EXECUTABLE)
38 message(FATAL_ERROR "Could not find Go")
39endif()
40
Robert Sloanfe7cd212017-08-07 09:03:39 -070041if (BORINGSSL_ALLOW_CXX_RUNTIME)
42 add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
43endif()
44
Robert Sloan73fa5d62017-10-09 13:53:06 -070045if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46 set(CLANG 1)
47endif()
Robert Sloan2e9e66a2017-09-25 09:08:29 -070048
Robert Sloan73fa5d62017-10-09 13:53:06 -070049if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
50 # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
Robert Sloan978112c2018-01-22 12:53:01 -080051 # primarily on our normal Clang one.
52 set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
Robert Sloan73fa5d62017-10-09 13:53:06 -070053 if(MSVC)
Robert Sloan978112c2018-01-22 12:53:01 -080054 # clang-cl sets different default warnings than clang. It also treats -Wall
55 # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall.
56 # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116
57 set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900")
Robert Sloan73fa5d62017-10-09 13:53:06 -070058 # googletest suppresses warning C4996 via a pragma, but clang-cl does not
59 # honor it. Suppress it here to compensate. See https://crbug.com/772117.
60 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
61 else()
Robert Sloan978112c2018-01-22 12:53:01 -080062 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common")
Robert Sloan73fa5d62017-10-09 13:53:06 -070063 endif()
64
65 if(CLANG)
Robert Sloanfe7cd212017-08-07 09:03:39 -070066 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
Robert Sloan8ff03552017-06-14 12:40:58 -070067 else()
68 # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
69 # and declare that the code is trying to free a stack pointer.
70 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
David Benjaminf0c4a6c2016-08-11 13:26:41 -040071 endif()
Robert Sloan2e9e66a2017-09-25 09:08:29 -070072
Robert Sloancd79cde2017-12-11 09:06:12 -080073 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
74 NOT "6.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
75 # Clang's -Wtautological-constant-compare is far too aggressive and does not
76 # account for, say, wanting the same code to work on both 32-bit and 64-bit
77 # platforms.
78 #
79 # Note "Clang" and "AppleClang" version differently, so we check for an
80 # exact match on the COMPILER_ID. As of writing, the warning is not in any
81 # release of AppleClang yet.
82 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-tautological-constant-compare -Wtautological-constant-out-of-range-compare")
83 endif()
84
Robert Sloan73fa5d62017-10-09 13:53:06 -070085 if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
Robert Sloan2e9e66a2017-09-25 09:08:29 -070086 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
87 endif()
88
David Benjaminc895d6b2016-08-11 13:26:41 -040089 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
Robert Sloan73fa5d62017-10-09 13:53:06 -070090 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
Robert Sloanfe7cd212017-08-07 09:03:39 -070091
Robert Sloan73fa5d62017-10-09 13:53:06 -070092 if(NOT MSVC)
93 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Robert Sloan29c1d2c2017-10-30 14:10:28 -070094 if(APPLE)
95 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
96 endif()
Robert Sloan73fa5d62017-10-09 13:53:06 -070097 if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
98 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
99 endif()
Robert Sloanfe7cd212017-08-07 09:03:39 -0700100 endif()
101
Robert Sloana12bf462017-07-17 07:08:26 -0700102 # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
103 # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
104 # spelling for both and -Wmissing-declarations is some other warning.
105 #
106 # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
107 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
108 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
Robert Sloan73fa5d62017-10-09 13:53:06 -0700109 if(CLANG)
Robert Sloan2e9e66a2017-09-25 09:08:29 -0700110 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
Robert Sloana12bf462017-07-17 07:08:26 -0700111 endif()
Robert Sloan73fa5d62017-10-09 13:53:06 -0700112
113 if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
114 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
115 endif()
116
Adam Langleyd9e397b2015-01-22 14:27:53 -0800117elseif(MSVC)
118 set(MSVC_DISABLED_WARNINGS_LIST
David Benjaminf31229b2017-01-25 14:08:15 -0500119 "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
120 # explicitly handled by a case label
121 # Disable this because it flags even when there is a default.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800122 "C4100" # 'exarg' : unreferenced formal parameter
123 "C4127" # conditional expression is constant
124 "C4200" # nonstandard extension used : zero-sized array in
125 # struct/union.
Steven Valdez909b19f2016-11-21 15:35:44 -0500126 "C4204" # nonstandard extension used: non-constant aggregate initializer
127 "C4221" # nonstandard extension used : 'identifier' : cannot be
128 # initialized using address of automatic variable
Adam Langleyd9e397b2015-01-22 14:27:53 -0800129 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
130 # possible loss of data
131 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
132 # possible loss of data
Adam Langleye9ada862015-05-11 17:20:37 -0700133 "C4267" # conversion from 'size_t' to 'int', possible loss of data
134 "C4371" # layout of class may have changed from a previous version of the
135 # compiler due to better packing of member '...'
136 "C4388" # signed/unsigned mismatch
Adam Langleyd9e397b2015-01-22 14:27:53 -0800137 "C4296" # '>=' : expression is always true
138 "C4350" # behavior change: 'std::_Wrap_alloc...'
139 "C4365" # '=' : conversion from 'size_t' to 'int',
140 # signed/unsigned mismatch
141 "C4389" # '!=' : signed/unsigned mismatch
David Benjamin9aaebef2016-04-22 15:02:23 -0400142 "C4464" # relative include path contains '..'
Adam Langleyd9e397b2015-01-22 14:27:53 -0800143 "C4510" # 'argument' : default constructor could not be generated
144 "C4512" # 'argument' : assignment operator could not be generated
145 "C4514" # 'function': unreferenced inline function has been removed
146 "C4548" # expression before comma has no effect; expected expression with
147 # side-effect" caused by FD_* macros.
148 "C4610" # struct 'argument' can never be instantiated - user defined
149 # constructor required.
David Benjamin9aaebef2016-04-22 15:02:23 -0400150 "C4623" # default constructor was implicitly defined as deleted
Adam Langleye9ada862015-05-11 17:20:37 -0700151 "C4625" # copy constructor could not be generated because a base class
152 # copy constructor is inaccessible or deleted
153 "C4626" # assignment operator could not be generated because a base class
154 # assignment operator is inaccessible or deleted
David Benjaminf31229b2017-01-25 14:08:15 -0500155 "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
156 # '0' for 'directives'
157 # Disable this because GTest uses it everywhere.
Adam Langleyd9e397b2015-01-22 14:27:53 -0800158 "C4706" # assignment within conditional expression
159 "C4710" # 'function': function not inlined
160 "C4711" # function 'function' selected for inline expansion
161 "C4800" # 'int' : forcing value to bool 'true' or 'false'
162 # (performance warning)
163 "C4820" # 'bytes' bytes padding added after construct 'member_name'
David Benjaminf31229b2017-01-25 14:08:15 -0500164 "C5026" # move constructor was implicitly defined as deleted
David Benjamin9aaebef2016-04-22 15:02:23 -0400165 "C5027" # move assignment operator was implicitly defined as deleted
166 )
167 set(MSVC_LEVEL4_WARNINGS_LIST
168 # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
169 "C4265" # class has virtual functions, but destructor is not virtual
170 )
Adam Langleyd9e397b2015-01-22 14:27:53 -0800171 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
172 ${MSVC_DISABLED_WARNINGS_LIST})
David Benjamin9aaebef2016-04-22 15:02:23 -0400173 string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
174 ${MSVC_LEVEL4_WARNINGS_LIST})
David Benjamin4969cc92016-04-22 15:02:23 -0400175 set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
176 set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
Robert Sloan8f860b12017-08-28 07:37:06 -0700177endif()
178
179if(WIN32)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800180 add_definitions(-D_HAS_EXCEPTIONS=0)
181 add_definitions(-DWIN32_LEAN_AND_MEAN)
Adam Langleye9ada862015-05-11 17:20:37 -0700182 add_definitions(-DNOMINMAX)
Robert Sloane56da3e2017-06-26 08:26:42 -0700183 # Allow use of fopen.
184 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
185 # VS 2017 and higher supports STL-only warning suppressions.
186 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
Adam Langleyd9e397b2015-01-22 14:27:53 -0800187endif()
188
Adam Langleye9ada862015-05-11 17:20:37 -0700189if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
Robert Sloan73fa5d62017-10-09 13:53:06 -0700190 CLANG)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800191 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
192 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
193endif()
194
David Benjamin6e899c72016-06-09 18:02:18 -0400195if(CMAKE_COMPILER_IS_GNUCXX)
Robert Sloan73fa5d62017-10-09 13:53:06 -0700196 if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
David Benjamin6e899c72016-06-09 18:02:18 -0400197 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
198 else()
199 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
200 endif()
201endif()
202
203# pthread_rwlock_t requires a feature flag.
204if(NOT WIN32)
205 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
Adam Langleyf4e42722015-06-04 17:45:09 -0700206endif()
207
Adam Langleyfad63272015-11-12 12:15:39 -0800208if(FUZZ)
Robert Sloan73fa5d62017-10-09 13:53:06 -0700209 if(NOT CLANG)
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400210 message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
Adam Langleyfad63272015-11-12 12:15:39 -0800211 endif()
212
Steven Valdez909b19f2016-11-21 15:35:44 -0500213 add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
214 set(RUNNER_ARGS "-deterministic")
215
216 if(NOT NO_FUZZER_MODE)
217 add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
218 set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
219 endif()
David Benjamin4969cc92016-04-22 15:02:23 -0400220
Robert Sloan8ff03552017-06-14 12:40:58 -0700221 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
222 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
Adam Langleyfad63272015-11-12 12:15:39 -0800223 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
224 link_directories(.)
225endif()
226
Adam Langleyd9e397b2015-01-22 14:27:53 -0800227add_definitions(-DBORINGSSL_IMPLEMENTATION)
228
229if (BUILD_SHARED_LIBS)
230 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
231 # Enable position-independent code globally. This is needed because
232 # some library targets are OBJECT libraries.
233 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
234endif()
235
Robert Sloan69939df2017-01-09 10:53:07 -0800236if (MSAN)
Robert Sloan73fa5d62017-10-09 13:53:06 -0700237 if(NOT CLANG)
Robert Sloan69939df2017-01-09 10:53:07 -0800238 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
239 endif()
240
241 if (ASAN)
242 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
243 endif()
244
245 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
246 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
247 set(OPENSSL_NO_ASM "1")
248endif()
249
250if (ASAN)
Robert Sloan73fa5d62017-10-09 13:53:06 -0700251 if(NOT CLANG)
Robert Sloan69939df2017-01-09 10:53:07 -0800252 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
253 endif()
254
Robert Sloan7d422bc2017-03-06 10:04:29 -0800255 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
256 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
Robert Sloan69939df2017-01-09 10:53:07 -0800257 set(OPENSSL_NO_ASM "1")
258endif()
259
Robert Sloan99319a12017-11-27 10:32:46 -0800260if(CFI)
261 if(NOT CLANG)
262 message(FATAL_ERROR "Cannot enable CFI unless using Clang")
263 endif()
264
265 # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
266 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
267 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
268 # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
269 # with -flto. That, in turn, can't handle -ggdb.
270 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
271 string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
272 string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
273 # -flto causes object files to contain LLVM bitcode. Mixing those with
274 # assembly output in the same static library breaks the linker.
275 set(OPENSSL_NO_ASM "1")
276endif()
277
Robert Sloan69939df2017-01-09 10:53:07 -0800278if (GCOV)
279 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
280 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
281endif()
282
Robert Sloan572a4e22017-04-17 10:52:19 -0700283if(FIPS)
284 add_definitions(-DBORINGSSL_FIPS)
Robert Sloan8ff03552017-06-14 12:40:58 -0700285 if(FIPS_BREAK_TEST)
286 add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
287 endif()
288 # Delocate does not work for ASan and MSan builds.
289 if(NOT ASAN AND NOT MSAN)
290 set(FIPS_DELOCATE "1")
291 endif()
Robert Sloan572a4e22017-04-17 10:52:19 -0700292endif()
293
294# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
295# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
296# alone, and expects all architecture-specific logic to be conditioned within
297# the source files rather than the build. This does not work for our assembly
298# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
299# builds.
300if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
301 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
302 if (NOT ${NUM_ARCHES} EQUAL 1)
303 message(FATAL_ERROR "Universal binaries not supported.")
304 endif()
305 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
306endif()
307
Adam Langleye9ada862015-05-11 17:20:37 -0700308if (OPENSSL_NO_ASM)
309 add_definitions(-DOPENSSL_NO_ASM)
310 set(ARCH "generic")
Robert Sloan572a4e22017-04-17 10:52:19 -0700311elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
312 set(ARCH "x86_64")
313elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
314 set(ARCH "x86_64")
315elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
316 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
317 if (CMAKE_CL_64)
318 set(ARCH "x86_64")
319 else()
320 set(ARCH "x86")
321 endif()
322elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
323 set(ARCH "x86")
324elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
325 set(ARCH "x86")
326elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
327 set(ARCH "x86")
328elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
329 set(ARCH "aarch64")
330elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
331 set(ARCH "aarch64")
332elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
333 set(ARCH "arm")
334elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
335 # Just to avoid the “unknown processor” error.
336 set(ARCH "generic")
337elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
338 set(ARCH "ppc64le")
339else()
340 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
341endif()
342
Robert Sloan55818102017-12-18 11:26:17 -0800343if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
344 # The third-party Android-NDK CMake files somehow fail to set the -march flag
345 # for assembly files. Without this flag, the compiler believes that it's
Robert Sloan572a4e22017-04-17 10:52:19 -0700346 # building for ARMv5.
Robert Sloan55818102017-12-18 11:26:17 -0800347 set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
Robert Sloan572a4e22017-04-17 10:52:19 -0700348endif()
349
Robert Sloan29c1d2c2017-10-30 14:10:28 -0700350if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
Robert Sloan572a4e22017-04-17 10:52:19 -0700351 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
352 # but clang defaults to 64-bit builds on OS X unless otherwise told.
353 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
354 set(ARCH "x86_64")
Adam Langleye9ada862015-05-11 17:20:37 -0700355endif()
356
David Benjaminf31229b2017-01-25 14:08:15 -0500357# Add minimal googletest targets. The provided one has many side-effects, and
358# googletest has a very straightforward build.
Robert Sloana450c922018-01-08 10:35:32 -0800359add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc)
360target_include_directories(boringssl_gtest PRIVATE third_party/googletest)
David Benjaminf31229b2017-01-25 14:08:15 -0500361
362include_directories(third_party/googletest/include)
363
Kenny Roote99801b2015-11-06 15:31:15 -0800364# Declare a dummy target to build all unit tests. Test targets should inject
365# themselves as dependencies next to the target definition.
366add_custom_target(all_tests)
367
Robert Sloan8ff03552017-06-14 12:40:58 -0700368add_custom_command(
369 OUTPUT crypto_test_data.cc
370 COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
371 ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
372 DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
373 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
374
375add_library(crypto_test_data OBJECT crypto_test_data.cc)
376
Adam Langleyd9e397b2015-01-22 14:27:53 -0800377add_subdirectory(crypto)
Robert Sloanb1b54b82017-11-06 13:50:02 -0800378add_subdirectory(third_party/fiat)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800379add_subdirectory(ssl)
380add_subdirectory(ssl/test)
Robert Sloan8ff03552017-06-14 12:40:58 -0700381add_subdirectory(fipstools)
Adam Langleyd9e397b2015-01-22 14:27:53 -0800382add_subdirectory(tool)
Adam Langleye9ada862015-05-11 17:20:37 -0700383add_subdirectory(decrepit)
Kenny Roote99801b2015-11-06 15:31:15 -0800384
Adam Langleyfad63272015-11-12 12:15:39 -0800385if(FUZZ)
Robert Sloan8ff03552017-06-14 12:40:58 -0700386 if(LIBFUZZER_FROM_DEPS)
387 file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
388 add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
389 # libFuzzer does not pass our aggressive warnings. It also must be built
390 # without -fsanitize-coverage options or clang crashes.
Robert Sloana12bf462017-07-17 07:08:26 -0700391 set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0")
Robert Sloan8ff03552017-06-14 12:40:58 -0700392 endif()
393
Adam Langleyfad63272015-11-12 12:15:39 -0800394 add_subdirectory(fuzz)
395endif()
396
Kenny Roote99801b2015-11-06 15:31:15 -0800397if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
398 # USES_TERMINAL is only available in CMake 3.2 or later.
399 set(MAYBE_USES_TERMINAL USES_TERMINAL)
400endif()
401
402add_custom_target(
403 run_tests
404 COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
405 ${CMAKE_BINARY_DIR}
Steven Valdezbb1ceac2016-10-07 10:34:51 -0400406 COMMAND cd ssl/test/runner &&
407 ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
408 ${RUNNER_ARGS}
Kenny Roote99801b2015-11-06 15:31:15 -0800409 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
410 DEPENDS all_tests bssl_shim
411 ${MAYBE_USES_TERMINAL})