blob: 6674a419f19aea3ba4741871720d984a6c6b3192 [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
51 # primarily on our normal Clang one because the MSVC one is mostly
52 # suppressions for an overaggressive -Wall.
53 set(C_CXX_FLAGS "-Wall -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
54 if(MSVC)
55 # clang-cl sets different default warnings than clang.
David Benjamin4519a5a2017-10-06 11:27:11 -040056 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-unused-parameter -fmsc-version=1900")
David Benjamin02afbd32017-10-05 15:04:08 -040057 # googletest suppresses warning C4996 via a pragma, but clang-cl does not
58 # honor it. Suppress it here to compensate. See https://crbug.com/772117.
59 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
60 else()
61 set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb -fvisibility=hidden -fno-common")
62 endif()
63
64 if(CLANG)
David Benjamin9fb6fea2017-07-31 14:03:38 -040065 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
Adam Langley5c38c052017-04-28 14:47:06 -070066 else()
67 # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
68 # and declare that the code is trying to free a stack pointer.
69 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
David Benjamin9b7d8362016-08-29 14:59:31 -040070 endif()
Vincent Batts60931e22017-09-20 11:51:54 -040071
David Benjamin6979c7e2017-12-04 17:19:49 -050072 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
73 NOT "6.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
74 # Clang's -Wtautological-constant-compare is far too aggressive and does not
75 # account for, say, wanting the same code to work on both 32-bit and 64-bit
76 # platforms.
77 #
78 # Note "Clang" and "AppleClang" version differently, so we check for an
79 # exact match on the COMPILER_ID. As of writing, the warning is not in any
80 # release of AppleClang yet.
81 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-tautological-constant-compare -Wtautological-constant-out-of-range-compare")
82 endif()
83
David Benjamin02afbd32017-10-05 15:04:08 -040084 if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
Vincent Batts60931e22017-09-20 11:51:54 -040085 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
86 endif()
87
Adam Langley01867872016-06-30 14:16:59 -070088 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
David Benjamin02afbd32017-10-05 15:04:08 -040089 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
David Benjamin2507d9e2017-07-26 11:39:38 -040090
David Benjamin02afbd32017-10-05 15:04:08 -040091 if(NOT MSVC)
92 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Daniel Wagner-Hall3b358b22017-10-16 20:58:08 +010093 if(APPLE)
94 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
95 endif()
David Benjamin02afbd32017-10-05 15:04:08 -040096 if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
97 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
98 endif()
David Benjamin2507d9e2017-07-26 11:39:38 -040099 endif()
100
David Benjamin4a8d1f32017-07-13 17:53:07 -0400101 # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
102 # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
103 # spelling for both and -Wmissing-declarations is some other warning.
104 #
105 # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
106 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
107 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
David Benjamin02afbd32017-10-05 15:04:08 -0400108 if(CLANG)
Vincent Batts60931e22017-09-20 11:51:54 -0400109 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
David Benjamin4a8d1f32017-07-13 17:53:07 -0400110 endif()
Daniel Wagner-Hall10154322017-10-09 20:09:43 +0100111
112 if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
113 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
114 endif()
115
Adam Langley95c29f32014-06-20 12:00:00 -0700116elseif(MSVC)
Brian Smithefed2212015-01-28 16:20:02 -0800117 set(MSVC_DISABLED_WARNINGS_LIST
David Benjamin96628432017-01-19 19:05:47 -0500118 "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
119 # explicitly handled by a case label
120 # Disable this because it flags even when there is a default.
Brian Smithefed2212015-01-28 16:20:02 -0800121 "C4100" # 'exarg' : unreferenced formal parameter
122 "C4127" # conditional expression is constant
123 "C4200" # nonstandard extension used : zero-sized array in
124 # struct/union.
David Benjaminffb11072016-11-13 10:32:10 +0900125 "C4204" # nonstandard extension used: non-constant aggregate initializer
126 "C4221" # nonstandard extension used : 'identifier' : cannot be
127 # initialized using address of automatic variable
Brian Smithefed2212015-01-28 16:20:02 -0800128 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
129 # possible loss of data
130 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
131 # possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500132 "C4267" # conversion from 'size_t' to 'int', possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500133 "C4371" # layout of class may have changed from a previous version of the
134 # compiler due to better packing of member '...'
135 "C4388" # signed/unsigned mismatch
Brian Smithefed2212015-01-28 16:20:02 -0800136 "C4296" # '>=' : expression is always true
137 "C4350" # behavior change: 'std::_Wrap_alloc...'
138 "C4365" # '=' : conversion from 'size_t' to 'int',
139 # signed/unsigned mismatch
140 "C4389" # '!=' : signed/unsigned mismatch
David Benjamin7acd6bc2016-05-02 12:57:01 -0400141 "C4464" # relative include path contains '..'
Brian Smithefed2212015-01-28 16:20:02 -0800142 "C4510" # 'argument' : default constructor could not be generated
143 "C4512" # 'argument' : assignment operator could not be generated
144 "C4514" # 'function': unreferenced inline function has been removed
145 "C4548" # expression before comma has no effect; expected expression with
146 # side-effect" caused by FD_* macros.
147 "C4610" # struct 'argument' can never be instantiated - user defined
148 # constructor required.
David Benjamin7acd6bc2016-05-02 12:57:01 -0400149 "C4623" # default constructor was implicitly defined as deleted
David Benjamin3673be72015-02-11 15:12:05 -0500150 "C4625" # copy constructor could not be generated because a base class
151 # copy constructor is inaccessible or deleted
152 "C4626" # assignment operator could not be generated because a base class
153 # assignment operator is inaccessible or deleted
David Benjamin96628432017-01-19 19:05:47 -0500154 "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
155 # '0' for 'directives'
156 # Disable this because GTest uses it everywhere.
Brian Smithefed2212015-01-28 16:20:02 -0800157 "C4706" # assignment within conditional expression
158 "C4710" # 'function': function not inlined
159 "C4711" # function 'function' selected for inline expansion
160 "C4800" # 'int' : forcing value to bool 'true' or 'false'
161 # (performance warning)
162 "C4820" # 'bytes' bytes padding added after construct 'member_name'
David Benjamin96628432017-01-19 19:05:47 -0500163 "C5026" # move constructor was implicitly defined as deleted
David Benjamin7acd6bc2016-05-02 12:57:01 -0400164 "C5027" # move assignment operator was implicitly defined as deleted
165 )
166 set(MSVC_LEVEL4_WARNINGS_LIST
167 # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
168 "C4265" # class has virtual functions, but destructor is not virtual
169 )
Brian Smithefed2212015-01-28 16:20:02 -0800170 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
171 ${MSVC_DISABLED_WARNINGS_LIST})
David Benjamin7acd6bc2016-05-02 12:57:01 -0400172 string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
173 ${MSVC_LEVEL4_WARNINGS_LIST})
Brian Smithdc6c1b82016-01-17 22:21:42 -1000174 set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
175 set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
David Benjamine2568c42017-08-16 15:25:27 -0400176endif()
177
178if(WIN32)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800179 add_definitions(-D_HAS_EXCEPTIONS=0)
Brian Smitha87de9b2015-01-28 20:34:47 -0800180 add_definitions(-DWIN32_LEAN_AND_MEAN)
David Benjamin0e434b92015-04-02 13:20:01 -0400181 add_definitions(-DNOMINMAX)
David Benjamin9b6ff442017-06-15 20:44:30 -0400182 # Allow use of fopen.
183 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
184 # VS 2017 and higher supports STL-only warning suppressions.
185 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
Adam Langley95c29f32014-06-20 12:00:00 -0700186endif()
187
David Benjaminb826c0d2015-02-28 00:00:44 -0500188if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
David Benjamin02afbd32017-10-05 15:04:08 -0400189 CLANG)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800190 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
191 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
Adam Langley07100c62015-01-16 15:20:54 -0800192endif()
193
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400194if(CMAKE_COMPILER_IS_GNUCXX)
David Benjamin02afbd32017-10-05 15:04:08 -0400195 if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400196 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
197 else()
198 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
199 endif()
200endif()
201
202# pthread_rwlock_t requires a feature flag.
203if(NOT WIN32)
204 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
Adam Langley6f2e7332015-05-15 12:01:29 -0700205endif()
206
Adam Langley9a4beb82015-11-09 13:57:26 -0800207if(FUZZ)
David Benjamin02afbd32017-10-05 15:04:08 -0400208 if(NOT CLANG)
Alessandro Ghedinib6f69272016-09-28 22:14:01 +0100209 message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
Adam Langley9a4beb82015-11-09 13:57:26 -0800210 endif()
211
David Benjaminec978dd2016-11-04 18:59:33 -0400212 add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
213 set(RUNNER_ARGS "-deterministic")
214
215 if(NOT NO_FUZZER_MODE)
216 add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
217 set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
218 endif()
David Benjaminbc5b2a22016-03-01 22:57:32 -0500219
David Benjamin08ab59b2017-05-10 12:02:58 -0400220 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
221 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
Adam Langley9a4beb82015-11-09 13:57:26 -0800222 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
Adam Langley7104cc92015-11-10 15:00:51 -0800223 link_directories(.)
Adam Langley9a4beb82015-11-09 13:57:26 -0800224endif()
225
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700226add_definitions(-DBORINGSSL_IMPLEMENTATION)
227
David Benjamin507c1ee2015-01-28 00:50:21 -0500228if (BUILD_SHARED_LIBS)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800229 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
230 # Enable position-independent code globally. This is needed because
231 # some library targets are OBJECT libraries.
232 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
David Benjamin507c1ee2015-01-28 00:50:21 -0500233endif()
234
Adam Langley1bcd10c2016-12-16 10:48:23 -0800235if (MSAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400236 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800237 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
238 endif()
239
240 if (ASAN)
241 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
242 endif()
243
244 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
245 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
246 set(OPENSSL_NO_ASM "1")
247endif()
248
249if (ASAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400250 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800251 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
252 endif()
253
David Benjamin0d3c9632017-02-28 14:58:00 -0500254 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
255 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 -0800256 set(OPENSSL_NO_ASM "1")
257endif()
258
David Benjaminc367ee52017-11-21 08:16:42 -0500259if(CFI)
260 if(NOT CLANG)
261 message(FATAL_ERROR "Cannot enable CFI unless using Clang")
262 endif()
263
264 # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
265 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
266 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
267 # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
268 # with -flto. That, in turn, can't handle -ggdb.
269 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
270 string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
271 string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
272 # -flto causes object files to contain LLVM bitcode. Mixing those with
273 # assembly output in the same static library breaks the linker.
274 set(OPENSSL_NO_ASM "1")
275endif()
276
David Benjamind035ab32016-12-27 12:15:56 -0500277if (GCOV)
278 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
279 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
280endif()
281
David Benjaminaff72a32017-04-06 23:26:04 -0400282if(FIPS)
283 add_definitions(-DBORINGSSL_FIPS)
Adam Langleyf64a6ee2017-05-17 13:05:50 -0700284 if(FIPS_BREAK_TEST)
285 add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
286 endif()
287 # Delocate does not work for ASan and MSan builds.
288 if(NOT ASAN AND NOT MSAN)
289 set(FIPS_DELOCATE "1")
290 endif()
David Benjaminaff72a32017-04-06 23:26:04 -0400291endif()
292
293# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
294# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
295# alone, and expects all architecture-specific logic to be conditioned within
296# the source files rather than the build. This does not work for our assembly
297# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
298# builds.
299if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
300 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
301 if (NOT ${NUM_ARCHES} EQUAL 1)
302 message(FATAL_ERROR "Universal binaries not supported.")
303 endif()
304 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
305endif()
306
David Benjamin27b08e92015-05-04 15:16:57 -0400307if (OPENSSL_NO_ASM)
308 add_definitions(-DOPENSSL_NO_ASM)
309 set(ARCH "generic")
David Benjaminaff72a32017-04-06 23:26:04 -0400310elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
311 set(ARCH "x86_64")
312elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
313 set(ARCH "x86_64")
314elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
315 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
316 if (CMAKE_CL_64)
317 set(ARCH "x86_64")
318 else()
319 set(ARCH "x86")
320 endif()
321elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
322 set(ARCH "x86")
323elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
324 set(ARCH "x86")
325elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
326 set(ARCH "x86")
327elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
328 set(ARCH "aarch64")
329elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
330 set(ARCH "aarch64")
331elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
332 set(ARCH "arm")
333elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
334 # Just to avoid the “unknown processor” error.
335 set(ARCH "generic")
336elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
337 set(ARCH "ppc64le")
338else()
339 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
David Benjamin27b08e92015-05-04 15:16:57 -0400340endif()
341
David Benjaminaff72a32017-04-06 23:26:04 -0400342if (ANDROID AND ${ARCH} STREQUAL "arm")
343 # The Android-NDK CMake files somehow fail to set the -march flag for
344 # assembly files. Without this flag, the compiler believes that it's
345 # building for ARMv5.
346 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
347endif()
348
David Benjaminf5beb882017-10-27 10:43:15 -0400349if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
David Benjaminaff72a32017-04-06 23:26:04 -0400350 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
351 # but clang defaults to 64-bit builds on OS X unless otherwise told.
352 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
353 set(ARCH "x86_64")
Adam Langleyfd499932017-04-04 14:21:43 -0700354endif()
355
David Benjamin96628432017-01-19 19:05:47 -0500356# Add minimal googletest targets. The provided one has many side-effects, and
357# googletest has a very straightforward build.
358add_library(gtest third_party/googletest/src/gtest-all.cc)
359target_include_directories(gtest PRIVATE third_party/googletest)
David Benjamin96628432017-01-19 19:05:47 -0500360
361include_directories(third_party/googletest/include)
362
David Benjamin301afaf2015-10-14 21:34:40 -0400363# Declare a dummy target to build all unit tests. Test targets should inject
364# themselves as dependencies next to the target definition.
365add_custom_target(all_tests)
366
David Benjamin3ecd0a52017-05-19 15:26:18 -0400367add_custom_command(
368 OUTPUT crypto_test_data.cc
369 COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
370 ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
371 DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
372 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
373
374add_library(crypto_test_data OBJECT crypto_test_data.cc)
375
Adam Langley95c29f32014-06-20 12:00:00 -0700376add_subdirectory(crypto)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000377add_subdirectory(third_party/fiat)
Adam Langley95c29f32014-06-20 12:00:00 -0700378add_subdirectory(ssl)
379add_subdirectory(ssl/test)
Martin Kreichgauer118355c2017-05-12 15:34:45 -0700380add_subdirectory(fipstools)
Adam Langley95c29f32014-06-20 12:00:00 -0700381add_subdirectory(tool)
Adam Langleyc004dfc2015-02-03 10:45:12 -0800382add_subdirectory(decrepit)
David Benjamin301afaf2015-10-14 21:34:40 -0400383
Adam Langley9a4beb82015-11-09 13:57:26 -0800384if(FUZZ)
David Benjamin1e5cb822017-05-10 16:07:56 -0400385 if(LIBFUZZER_FROM_DEPS)
386 file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
387 add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
388 # libFuzzer does not pass our aggressive warnings. It also must be built
389 # without -fsanitize-coverage options or clang crashes.
David Benjamin6fb16cc2017-07-14 11:02:39 -0400390 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 -0400391 endif()
392
Adam Langley9a4beb82015-11-09 13:57:26 -0800393 add_subdirectory(fuzz)
394endif()
395
David Benjamin301afaf2015-10-14 21:34:40 -0400396if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
397 # USES_TERMINAL is only available in CMake 3.2 or later.
398 set(MAYBE_USES_TERMINAL USES_TERMINAL)
399endif()
400
401add_custom_target(
402 run_tests
403 COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
404 ${CMAKE_BINARY_DIR}
Adam Langleyd5c72c82016-09-23 16:43:17 -0700405 COMMAND cd ssl/test/runner &&
406 ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
407 ${RUNNER_ARGS}
David Benjamin301afaf2015-10-14 21:34:40 -0400408 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
409 DEPENDS all_tests bssl_shim
410 ${MAYBE_USES_TERMINAL})