blob: 97ea2896b5f15066237fd3a5fce339ab4bc0c88f [file] [log] [blame]
David Benjamin96628432017-01-19 19:05:47 -05001cmake_minimum_required (VERSION 2.8.11)
Adam Langley95c29f32014-06-20 12:00:00 -07002
David Benjamin6979c7e2017-12-04 17:19:49 -05003# 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 Benjamin6b34d542016-02-05 21:58:39 -05009# 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
David Benjamin3ecd0a52017-05-19 15:26:18 -040018include(sources.cmake)
19
David Benjamin6b34d542016-02-05 21:58:39 -050020enable_language(C)
21enable_language(CXX)
Adam Langley95c29f32014-06-20 12:00:00 -070022
Adam Langley843ab662015-04-28 17:46:58 -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.
Tamas Berghammer5693e422016-05-19 14:28:14 +010026 if(NOT PERL_EXECUTABLE)
27 set(PERL_EXECUTABLE "perl")
28 endif()
29 if(NOT GO_EXECUTABLE)
30 set(GO_EXECUTABLE "go")
31 endif()
Adam Langley843ab662015-04-28 17:46:58 -070032else()
33 find_package(Perl REQUIRED)
34 find_program(GO_EXECUTABLE go)
35endif()
David Benjamin3ce3c362015-02-23 13:06:19 -050036
David Benjamind27eda02015-03-05 01:19:27 -050037if (NOT GO_EXECUTABLE)
38 message(FATAL_ERROR "Could not find Go")
39endif()
40
David Benjamin2507d9e2017-07-26 11:39:38 -040041if (BORINGSSL_ALLOW_CXX_RUNTIME)
42 add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
43endif()
44
David Benjamin02afbd32017-10-05 15:04:08 -040045if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
46 set(CLANG 1)
47endif()
Vincent Batts60931e22017-09-20 11:51:54 -040048
David Benjamin02afbd32017-10-05 15:04:08 -040049if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
50 # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
David Benjamin8d67f6f2018-01-05 15:43:09 -050051 # primarily on our normal Clang one.
52 set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
David Benjamin02afbd32017-10-05 15:04:08 -040053 if(MSVC)
David Benjamin8d67f6f2018-01-05 15:43:09 -050054 # 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")
David Benjamin02afbd32017-10-05 15:04:08 -040058 # 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()
David Benjamin8d67f6f2018-01-05 15:43:09 -050062 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common")
David Benjamin02afbd32017-10-05 15:04:08 -040063 endif()
64
65 if(CLANG)
David Benjamin9fb6fea2017-07-31 14:03:38 -040066 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
Adam Langley5c38c052017-04-28 14:47:06 -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 Benjamin9b7d8362016-08-29 14:59:31 -040071 endif()
Vincent Batts60931e22017-09-20 11:51:54 -040072
David Benjamin02afbd32017-10-05 15:04:08 -040073 if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
Vincent Batts60931e22017-09-20 11:51:54 -040074 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
75 endif()
76
Adam Langley01867872016-06-30 14:16:59 -070077 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
David Benjamin02afbd32017-10-05 15:04:08 -040078 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
David Benjamin2507d9e2017-07-26 11:39:38 -040079
David Benjamin02afbd32017-10-05 15:04:08 -040080 if(NOT MSVC)
81 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Daniel Wagner-Hall3b358b22017-10-16 20:58:08 +010082 if(APPLE)
83 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
84 endif()
David Benjamin02afbd32017-10-05 15:04:08 -040085 if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
86 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
87 endif()
David Benjamin2507d9e2017-07-26 11:39:38 -040088 endif()
89
David Benjamin4a8d1f32017-07-13 17:53:07 -040090 # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
91 # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
92 # spelling for both and -Wmissing-declarations is some other warning.
93 #
94 # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
95 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
96 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
David Benjamin02afbd32017-10-05 15:04:08 -040097 if(CLANG)
Vincent Batts60931e22017-09-20 11:51:54 -040098 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
David Benjamin4a8d1f32017-07-13 17:53:07 -040099 endif()
Daniel Wagner-Hall10154322017-10-09 20:09:43 +0100100
101 if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
102 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
103 endif()
104
Adam Langley95c29f32014-06-20 12:00:00 -0700105elseif(MSVC)
Brian Smithefed2212015-01-28 16:20:02 -0800106 set(MSVC_DISABLED_WARNINGS_LIST
David Benjamin96628432017-01-19 19:05:47 -0500107 "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
108 # explicitly handled by a case label
109 # Disable this because it flags even when there is a default.
Brian Smithefed2212015-01-28 16:20:02 -0800110 "C4100" # 'exarg' : unreferenced formal parameter
111 "C4127" # conditional expression is constant
112 "C4200" # nonstandard extension used : zero-sized array in
113 # struct/union.
David Benjaminffb11072016-11-13 10:32:10 +0900114 "C4204" # nonstandard extension used: non-constant aggregate initializer
115 "C4221" # nonstandard extension used : 'identifier' : cannot be
116 # initialized using address of automatic variable
Brian Smithefed2212015-01-28 16:20:02 -0800117 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
118 # possible loss of data
119 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
120 # possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500121 "C4267" # conversion from 'size_t' to 'int', possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500122 "C4371" # layout of class may have changed from a previous version of the
123 # compiler due to better packing of member '...'
124 "C4388" # signed/unsigned mismatch
Brian Smithefed2212015-01-28 16:20:02 -0800125 "C4296" # '>=' : expression is always true
126 "C4350" # behavior change: 'std::_Wrap_alloc...'
127 "C4365" # '=' : conversion from 'size_t' to 'int',
128 # signed/unsigned mismatch
129 "C4389" # '!=' : signed/unsigned mismatch
David Benjamin7acd6bc2016-05-02 12:57:01 -0400130 "C4464" # relative include path contains '..'
Brian Smithefed2212015-01-28 16:20:02 -0800131 "C4510" # 'argument' : default constructor could not be generated
132 "C4512" # 'argument' : assignment operator could not be generated
133 "C4514" # 'function': unreferenced inline function has been removed
134 "C4548" # expression before comma has no effect; expected expression with
135 # side-effect" caused by FD_* macros.
136 "C4610" # struct 'argument' can never be instantiated - user defined
137 # constructor required.
David Benjamin7acd6bc2016-05-02 12:57:01 -0400138 "C4623" # default constructor was implicitly defined as deleted
David Benjamin3673be72015-02-11 15:12:05 -0500139 "C4625" # copy constructor could not be generated because a base class
140 # copy constructor is inaccessible or deleted
141 "C4626" # assignment operator could not be generated because a base class
142 # assignment operator is inaccessible or deleted
David Benjamin96628432017-01-19 19:05:47 -0500143 "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
144 # '0' for 'directives'
145 # Disable this because GTest uses it everywhere.
Brian Smithefed2212015-01-28 16:20:02 -0800146 "C4706" # assignment within conditional expression
147 "C4710" # 'function': function not inlined
148 "C4711" # function 'function' selected for inline expansion
149 "C4800" # 'int' : forcing value to bool 'true' or 'false'
150 # (performance warning)
151 "C4820" # 'bytes' bytes padding added after construct 'member_name'
David Benjamin96628432017-01-19 19:05:47 -0500152 "C5026" # move constructor was implicitly defined as deleted
David Benjamin7acd6bc2016-05-02 12:57:01 -0400153 "C5027" # move assignment operator was implicitly defined as deleted
154 )
155 set(MSVC_LEVEL4_WARNINGS_LIST
156 # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
157 "C4265" # class has virtual functions, but destructor is not virtual
158 )
Brian Smithefed2212015-01-28 16:20:02 -0800159 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
160 ${MSVC_DISABLED_WARNINGS_LIST})
David Benjamin7acd6bc2016-05-02 12:57:01 -0400161 string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
162 ${MSVC_LEVEL4_WARNINGS_LIST})
sphawk3ab1a692018-03-11 19:20:51 +0900163 set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
164 set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
David Benjamine2568c42017-08-16 15:25:27 -0400165endif()
166
167if(WIN32)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800168 add_definitions(-D_HAS_EXCEPTIONS=0)
Brian Smitha87de9b2015-01-28 20:34:47 -0800169 add_definitions(-DWIN32_LEAN_AND_MEAN)
David Benjamin0e434b92015-04-02 13:20:01 -0400170 add_definitions(-DNOMINMAX)
David Benjamin9b6ff442017-06-15 20:44:30 -0400171 # Allow use of fopen.
172 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
173 # VS 2017 and higher supports STL-only warning suppressions.
174 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
Adam Langley95c29f32014-06-20 12:00:00 -0700175endif()
176
David Benjaminb826c0d2015-02-28 00:00:44 -0500177if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
David Benjamin02afbd32017-10-05 15:04:08 -0400178 CLANG)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800179 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
180 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
Adam Langley07100c62015-01-16 15:20:54 -0800181endif()
182
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400183if(CMAKE_COMPILER_IS_GNUCXX)
David Benjamin02afbd32017-10-05 15:04:08 -0400184 if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400185 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
186 else()
187 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
188 endif()
189endif()
190
191# pthread_rwlock_t requires a feature flag.
192if(NOT WIN32)
193 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
Adam Langley6f2e7332015-05-15 12:01:29 -0700194endif()
195
Adam Langley9a4beb82015-11-09 13:57:26 -0800196if(FUZZ)
David Benjamin02afbd32017-10-05 15:04:08 -0400197 if(NOT CLANG)
Alessandro Ghedinib6f69272016-09-28 22:14:01 +0100198 message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
Adam Langley9a4beb82015-11-09 13:57:26 -0800199 endif()
200
David Benjaminec978dd2016-11-04 18:59:33 -0400201 add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
202 set(RUNNER_ARGS "-deterministic")
203
204 if(NOT NO_FUZZER_MODE)
205 add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
206 set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
207 endif()
David Benjaminbc5b2a22016-03-01 22:57:32 -0500208
David Benjamin08ab59b2017-05-10 12:02:58 -0400209 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
210 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
Adam Langley9a4beb82015-11-09 13:57:26 -0800211 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
Adam Langley7104cc92015-11-10 15:00:51 -0800212 link_directories(.)
Adam Langley9a4beb82015-11-09 13:57:26 -0800213endif()
214
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700215add_definitions(-DBORINGSSL_IMPLEMENTATION)
216
David Benjamin507c1ee2015-01-28 00:50:21 -0500217if (BUILD_SHARED_LIBS)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800218 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
219 # Enable position-independent code globally. This is needed because
220 # some library targets are OBJECT libraries.
221 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
David Benjamin507c1ee2015-01-28 00:50:21 -0500222endif()
223
Adam Langley1bcd10c2016-12-16 10:48:23 -0800224if (MSAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400225 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800226 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
227 endif()
228
229 if (ASAN)
230 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
231 endif()
232
233 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
234 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
235 set(OPENSSL_NO_ASM "1")
236endif()
237
238if (ASAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400239 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800240 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
241 endif()
242
David Benjamin0d3c9632017-02-28 14:58:00 -0500243 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
244 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
Adam Langley1bcd10c2016-12-16 10:48:23 -0800245 set(OPENSSL_NO_ASM "1")
246endif()
247
David Benjaminc367ee52017-11-21 08:16:42 -0500248if(CFI)
249 if(NOT CLANG)
250 message(FATAL_ERROR "Cannot enable CFI unless using Clang")
251 endif()
252
253 # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
254 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
255 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
256 # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
257 # with -flto. That, in turn, can't handle -ggdb.
258 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
259 string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
260 string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
261 # -flto causes object files to contain LLVM bitcode. Mixing those with
262 # assembly output in the same static library breaks the linker.
263 set(OPENSSL_NO_ASM "1")
264endif()
265
David Benjamind035ab32016-12-27 12:15:56 -0500266if (GCOV)
267 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
268 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
269endif()
270
David Benjaminaff72a32017-04-06 23:26:04 -0400271if(FIPS)
272 add_definitions(-DBORINGSSL_FIPS)
Adam Langleyf64a6ee2017-05-17 13:05:50 -0700273 if(FIPS_BREAK_TEST)
274 add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
275 endif()
276 # Delocate does not work for ASan and MSan builds.
277 if(NOT ASAN AND NOT MSAN)
278 set(FIPS_DELOCATE "1")
279 endif()
David Benjaminaff72a32017-04-06 23:26:04 -0400280endif()
281
David Benjamin6291af42018-03-23 13:49:27 -0400282if(OPENSSL_SMALL)
283 add_definitions(-DOPENSSL_SMALL)
284endif()
285
David Benjaminaff72a32017-04-06 23:26:04 -0400286# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
287# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
288# alone, and expects all architecture-specific logic to be conditioned within
289# the source files rather than the build. This does not work for our assembly
290# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
291# builds.
292if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
293 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
294 if (NOT ${NUM_ARCHES} EQUAL 1)
295 message(FATAL_ERROR "Universal binaries not supported.")
296 endif()
297 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
298endif()
299
David Benjamin27b08e92015-05-04 15:16:57 -0400300if (OPENSSL_NO_ASM)
301 add_definitions(-DOPENSSL_NO_ASM)
302 set(ARCH "generic")
David Benjaminaff72a32017-04-06 23:26:04 -0400303elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
304 set(ARCH "x86_64")
305elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
306 set(ARCH "x86_64")
307elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
308 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
309 if (CMAKE_CL_64)
310 set(ARCH "x86_64")
311 else()
312 set(ARCH "x86")
313 endif()
314elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
315 set(ARCH "x86")
316elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
317 set(ARCH "x86")
318elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
319 set(ARCH "x86")
320elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
321 set(ARCH "aarch64")
322elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
323 set(ARCH "aarch64")
324elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
325 set(ARCH "arm")
326elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
327 # Just to avoid the “unknown processor” error.
328 set(ARCH "generic")
329elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
330 set(ARCH "ppc64le")
331else()
332 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
David Benjamin27b08e92015-05-04 15:16:57 -0400333endif()
334
David Benjamin9894ee92017-12-13 18:08:47 -0500335if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
336 # The third-party Android-NDK CMake files somehow fail to set the -march flag
337 # for assembly files. Without this flag, the compiler believes that it's
David Benjaminaff72a32017-04-06 23:26:04 -0400338 # building for ARMv5.
David Benjamin9894ee92017-12-13 18:08:47 -0500339 set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
David Benjaminaff72a32017-04-06 23:26:04 -0400340endif()
341
David Benjaminf5beb882017-10-27 10:43:15 -0400342if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
David Benjaminaff72a32017-04-06 23:26:04 -0400343 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
344 # but clang defaults to 64-bit builds on OS X unless otherwise told.
345 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
346 set(ARCH "x86_64")
Adam Langleyfd499932017-04-04 14:21:43 -0700347endif()
348
David Benjamin96628432017-01-19 19:05:47 -0500349# Add minimal googletest targets. The provided one has many side-effects, and
350# googletest has a very straightforward build.
Marek Gilbert11850d52018-01-03 23:07:58 -0800351add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc)
352target_include_directories(boringssl_gtest PRIVATE third_party/googletest)
David Benjamin96628432017-01-19 19:05:47 -0500353
354include_directories(third_party/googletest/include)
355
David Benjamin301afaf2015-10-14 21:34:40 -0400356# Declare a dummy target to build all unit tests. Test targets should inject
357# themselves as dependencies next to the target definition.
358add_custom_target(all_tests)
359
David Benjamin3ecd0a52017-05-19 15:26:18 -0400360add_custom_command(
361 OUTPUT crypto_test_data.cc
362 COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
363 ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
364 DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
365 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
366
367add_library(crypto_test_data OBJECT crypto_test_data.cc)
368
Adam Langley95c29f32014-06-20 12:00:00 -0700369add_subdirectory(crypto)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000370add_subdirectory(third_party/fiat)
Adam Langley95c29f32014-06-20 12:00:00 -0700371add_subdirectory(ssl)
372add_subdirectory(ssl/test)
Martin Kreichgauer118355c2017-05-12 15:34:45 -0700373add_subdirectory(fipstools)
Adam Langley95c29f32014-06-20 12:00:00 -0700374add_subdirectory(tool)
Adam Langleyc004dfc2015-02-03 10:45:12 -0800375add_subdirectory(decrepit)
David Benjamin301afaf2015-10-14 21:34:40 -0400376
Adam Langley9a4beb82015-11-09 13:57:26 -0800377if(FUZZ)
David Benjamin1e5cb822017-05-10 16:07:56 -0400378 if(LIBFUZZER_FROM_DEPS)
379 file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
380 add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
381 # libFuzzer does not pass our aggressive warnings. It also must be built
382 # without -fsanitize-coverage options or clang crashes.
David Benjamin6fb16cc2017-07-14 11:02:39 -0400383 set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0")
David Benjamin1e5cb822017-05-10 16:07:56 -0400384 endif()
385
Adam Langley9a4beb82015-11-09 13:57:26 -0800386 add_subdirectory(fuzz)
387endif()
388
David Benjamin301afaf2015-10-14 21:34:40 -0400389if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
390 # USES_TERMINAL is only available in CMake 3.2 or later.
391 set(MAYBE_USES_TERMINAL USES_TERMINAL)
392endif()
393
394add_custom_target(
395 run_tests
396 COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
397 ${CMAKE_BINARY_DIR}
Adam Langleyd5c72c82016-09-23 16:43:17 -0700398 COMMAND cd ssl/test/runner &&
399 ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
400 ${RUNNER_ARGS}
David Benjamin301afaf2015-10-14 21:34:40 -0400401 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
402 DEPENDS all_tests bssl_shim
403 ${MAYBE_USES_TERMINAL})