blob: eb8717ac2a86974f89695f0693f0b4506828c239 [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 Benjamin6b34d542016-02-05 21:58:39 -05003# Defer enabling C and CXX languages.
4project (BoringSSL NONE)
5
6if(WIN32)
7 # On Windows, prefer cl over gcc if both are available. By default most of
8 # the CMake generators prefer gcc, even on Windows.
9 set(CMAKE_GENERATOR_CC cl)
10endif()
11
David Benjamin3ecd0a52017-05-19 15:26:18 -040012include(sources.cmake)
13
David Benjamin6b34d542016-02-05 21:58:39 -050014enable_language(C)
15enable_language(CXX)
Adam Langley95c29f32014-06-20 12:00:00 -070016
Adam Langley843ab662015-04-28 17:46:58 -070017if(ANDROID)
18 # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
19 # found. However, ninja will still find them in $PATH if we just name them.
Tamas Berghammer5693e422016-05-19 14:28:14 +010020 if(NOT PERL_EXECUTABLE)
21 set(PERL_EXECUTABLE "perl")
22 endif()
23 if(NOT GO_EXECUTABLE)
24 set(GO_EXECUTABLE "go")
25 endif()
Adam Langley843ab662015-04-28 17:46:58 -070026else()
27 find_package(Perl REQUIRED)
28 find_program(GO_EXECUTABLE go)
29endif()
David Benjamin3ce3c362015-02-23 13:06:19 -050030
David Benjamind27eda02015-03-05 01:19:27 -050031if (NOT GO_EXECUTABLE)
32 message(FATAL_ERROR "Could not find Go")
33endif()
34
David Benjamin2507d9e2017-07-26 11:39:38 -040035if (BORINGSSL_ALLOW_CXX_RUNTIME)
36 add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
37endif()
38
David Benjamin02afbd32017-10-05 15:04:08 -040039if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
40 set(CLANG 1)
41endif()
Vincent Batts60931e22017-09-20 11:51:54 -040042
David Benjamin02afbd32017-10-05 15:04:08 -040043if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
44 # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
45 # primarily on our normal Clang one because the MSVC one is mostly
46 # suppressions for an overaggressive -Wall.
47 set(C_CXX_FLAGS "-Wall -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
48 if(MSVC)
49 # clang-cl sets different default warnings than clang.
David Benjamin4519a5a2017-10-06 11:27:11 -040050 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-unused-parameter -fmsc-version=1900")
David Benjamin02afbd32017-10-05 15:04:08 -040051 # googletest suppresses warning C4996 via a pragma, but clang-cl does not
52 # honor it. Suppress it here to compensate. See https://crbug.com/772117.
53 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
54 else()
55 set(C_CXX_FLAGS "${C_CXX_FLAGS} -ggdb -fvisibility=hidden -fno-common")
56 endif()
57
58 if(CLANG)
David Benjamin9fb6fea2017-07-31 14:03:38 -040059 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
Adam Langley5c38c052017-04-28 14:47:06 -070060 else()
61 # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
62 # and declare that the code is trying to free a stack pointer.
63 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
David Benjamin9b7d8362016-08-29 14:59:31 -040064 endif()
Vincent Batts60931e22017-09-20 11:51:54 -040065
David Benjamin02afbd32017-10-05 15:04:08 -040066 if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
Vincent Batts60931e22017-09-20 11:51:54 -040067 set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
68 endif()
69
Adam Langley01867872016-06-30 14:16:59 -070070 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
David Benjamin02afbd32017-10-05 15:04:08 -040071 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
David Benjamin2507d9e2017-07-26 11:39:38 -040072
David Benjamin02afbd32017-10-05 15:04:08 -040073 if(NOT MSVC)
74 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Daniel Wagner-Hall3b358b22017-10-16 20:58:08 +010075 if(APPLE)
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
77 endif()
David Benjamin02afbd32017-10-05 15:04:08 -040078 if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
80 endif()
David Benjamin2507d9e2017-07-26 11:39:38 -040081 endif()
82
David Benjamin4a8d1f32017-07-13 17:53:07 -040083 # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
84 # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
85 # spelling for both and -Wmissing-declarations is some other warning.
86 #
87 # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
88 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
89 # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
David Benjamin02afbd32017-10-05 15:04:08 -040090 if(CLANG)
Vincent Batts60931e22017-09-20 11:51:54 -040091 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
David Benjamin4a8d1f32017-07-13 17:53:07 -040092 endif()
Daniel Wagner-Hall10154322017-10-09 20:09:43 +010093
94 if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
95 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
96 endif()
97
Adam Langley95c29f32014-06-20 12:00:00 -070098elseif(MSVC)
Brian Smithefed2212015-01-28 16:20:02 -080099 set(MSVC_DISABLED_WARNINGS_LIST
David Benjamin96628432017-01-19 19:05:47 -0500100 "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
101 # explicitly handled by a case label
102 # Disable this because it flags even when there is a default.
Brian Smithefed2212015-01-28 16:20:02 -0800103 "C4100" # 'exarg' : unreferenced formal parameter
104 "C4127" # conditional expression is constant
105 "C4200" # nonstandard extension used : zero-sized array in
106 # struct/union.
David Benjaminffb11072016-11-13 10:32:10 +0900107 "C4204" # nonstandard extension used: non-constant aggregate initializer
108 "C4221" # nonstandard extension used : 'identifier' : cannot be
109 # initialized using address of automatic variable
Brian Smithefed2212015-01-28 16:20:02 -0800110 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
111 # possible loss of data
112 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
113 # possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500114 "C4267" # conversion from 'size_t' to 'int', possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -0500115 "C4371" # layout of class may have changed from a previous version of the
116 # compiler due to better packing of member '...'
117 "C4388" # signed/unsigned mismatch
Brian Smithefed2212015-01-28 16:20:02 -0800118 "C4296" # '>=' : expression is always true
119 "C4350" # behavior change: 'std::_Wrap_alloc...'
120 "C4365" # '=' : conversion from 'size_t' to 'int',
121 # signed/unsigned mismatch
122 "C4389" # '!=' : signed/unsigned mismatch
David Benjamin7acd6bc2016-05-02 12:57:01 -0400123 "C4464" # relative include path contains '..'
Brian Smithefed2212015-01-28 16:20:02 -0800124 "C4510" # 'argument' : default constructor could not be generated
125 "C4512" # 'argument' : assignment operator could not be generated
126 "C4514" # 'function': unreferenced inline function has been removed
127 "C4548" # expression before comma has no effect; expected expression with
128 # side-effect" caused by FD_* macros.
129 "C4610" # struct 'argument' can never be instantiated - user defined
130 # constructor required.
David Benjamin7acd6bc2016-05-02 12:57:01 -0400131 "C4623" # default constructor was implicitly defined as deleted
David Benjamin3673be72015-02-11 15:12:05 -0500132 "C4625" # copy constructor could not be generated because a base class
133 # copy constructor is inaccessible or deleted
134 "C4626" # assignment operator could not be generated because a base class
135 # assignment operator is inaccessible or deleted
David Benjamin96628432017-01-19 19:05:47 -0500136 "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
137 # '0' for 'directives'
138 # Disable this because GTest uses it everywhere.
Brian Smithefed2212015-01-28 16:20:02 -0800139 "C4706" # assignment within conditional expression
140 "C4710" # 'function': function not inlined
141 "C4711" # function 'function' selected for inline expansion
142 "C4800" # 'int' : forcing value to bool 'true' or 'false'
143 # (performance warning)
144 "C4820" # 'bytes' bytes padding added after construct 'member_name'
David Benjamin96628432017-01-19 19:05:47 -0500145 "C5026" # move constructor was implicitly defined as deleted
David Benjamin7acd6bc2016-05-02 12:57:01 -0400146 "C5027" # move assignment operator was implicitly defined as deleted
147 )
148 set(MSVC_LEVEL4_WARNINGS_LIST
149 # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
150 "C4265" # class has virtual functions, but destructor is not virtual
151 )
Brian Smithefed2212015-01-28 16:20:02 -0800152 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
153 ${MSVC_DISABLED_WARNINGS_LIST})
David Benjamin7acd6bc2016-05-02 12:57:01 -0400154 string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
155 ${MSVC_LEVEL4_WARNINGS_LIST})
Brian Smithdc6c1b82016-01-17 22:21:42 -1000156 set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
157 set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
David Benjamine2568c42017-08-16 15:25:27 -0400158endif()
159
160if(WIN32)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800161 add_definitions(-D_HAS_EXCEPTIONS=0)
Brian Smitha87de9b2015-01-28 20:34:47 -0800162 add_definitions(-DWIN32_LEAN_AND_MEAN)
David Benjamin0e434b92015-04-02 13:20:01 -0400163 add_definitions(-DNOMINMAX)
David Benjamin9b6ff442017-06-15 20:44:30 -0400164 # Allow use of fopen.
165 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
166 # VS 2017 and higher supports STL-only warning suppressions.
167 add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
Adam Langley95c29f32014-06-20 12:00:00 -0700168endif()
169
David Benjaminb826c0d2015-02-28 00:00:44 -0500170if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
David Benjamin02afbd32017-10-05 15:04:08 -0400171 CLANG)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800172 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
173 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
Adam Langley07100c62015-01-16 15:20:54 -0800174endif()
175
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400176if(CMAKE_COMPILER_IS_GNUCXX)
David Benjamin02afbd32017-10-05 15:04:08 -0400177 if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
David Benjamin2e8ba2d2016-06-09 16:22:26 -0400178 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
179 else()
180 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
181 endif()
182endif()
183
184# pthread_rwlock_t requires a feature flag.
185if(NOT WIN32)
186 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
Adam Langley6f2e7332015-05-15 12:01:29 -0700187endif()
188
Adam Langley9a4beb82015-11-09 13:57:26 -0800189if(FUZZ)
David Benjamin02afbd32017-10-05 15:04:08 -0400190 if(NOT CLANG)
Alessandro Ghedinib6f69272016-09-28 22:14:01 +0100191 message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
Adam Langley9a4beb82015-11-09 13:57:26 -0800192 endif()
193
David Benjaminec978dd2016-11-04 18:59:33 -0400194 add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
195 set(RUNNER_ARGS "-deterministic")
196
197 if(NOT NO_FUZZER_MODE)
198 add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
199 set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
200 endif()
David Benjaminbc5b2a22016-03-01 22:57:32 -0500201
David Benjamin08ab59b2017-05-10 12:02:58 -0400202 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
203 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
Adam Langley9a4beb82015-11-09 13:57:26 -0800204 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
Adam Langley7104cc92015-11-10 15:00:51 -0800205 link_directories(.)
Adam Langley9a4beb82015-11-09 13:57:26 -0800206endif()
207
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700208add_definitions(-DBORINGSSL_IMPLEMENTATION)
209
David Benjamin507c1ee2015-01-28 00:50:21 -0500210if (BUILD_SHARED_LIBS)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800211 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
212 # Enable position-independent code globally. This is needed because
213 # some library targets are OBJECT libraries.
214 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
David Benjamin507c1ee2015-01-28 00:50:21 -0500215endif()
216
Adam Langley1bcd10c2016-12-16 10:48:23 -0800217if (MSAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400218 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800219 message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
220 endif()
221
222 if (ASAN)
223 message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
224 endif()
225
226 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
227 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
228 set(OPENSSL_NO_ASM "1")
229endif()
230
231if (ASAN)
David Benjamin02afbd32017-10-05 15:04:08 -0400232 if(NOT CLANG)
Adam Langley1bcd10c2016-12-16 10:48:23 -0800233 message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
234 endif()
235
David Benjamin0d3c9632017-02-28 14:58:00 -0500236 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
237 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 -0800238 set(OPENSSL_NO_ASM "1")
239endif()
240
David Benjaminc367ee52017-11-21 08:16:42 -0500241if(CFI)
242 if(NOT CLANG)
243 message(FATAL_ERROR "Cannot enable CFI unless using Clang")
244 endif()
245
246 # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
247 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
248 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
249 # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
250 # with -flto. That, in turn, can't handle -ggdb.
251 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
252 string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
253 string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
254 # -flto causes object files to contain LLVM bitcode. Mixing those with
255 # assembly output in the same static library breaks the linker.
256 set(OPENSSL_NO_ASM "1")
257endif()
258
David Benjamind035ab32016-12-27 12:15:56 -0500259if (GCOV)
260 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
261 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
262endif()
263
David Benjaminaff72a32017-04-06 23:26:04 -0400264if(FIPS)
265 add_definitions(-DBORINGSSL_FIPS)
Adam Langleyf64a6ee2017-05-17 13:05:50 -0700266 if(FIPS_BREAK_TEST)
267 add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
268 endif()
269 # Delocate does not work for ASan and MSan builds.
270 if(NOT ASAN AND NOT MSAN)
271 set(FIPS_DELOCATE "1")
272 endif()
David Benjaminaff72a32017-04-06 23:26:04 -0400273endif()
274
275# CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
276# architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
277# alone, and expects all architecture-specific logic to be conditioned within
278# the source files rather than the build. This does not work for our assembly
279# files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
280# builds.
281if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
282 list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
283 if (NOT ${NUM_ARCHES} EQUAL 1)
284 message(FATAL_ERROR "Universal binaries not supported.")
285 endif()
286 list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
287endif()
288
David Benjamin27b08e92015-05-04 15:16:57 -0400289if (OPENSSL_NO_ASM)
290 add_definitions(-DOPENSSL_NO_ASM)
291 set(ARCH "generic")
David Benjaminaff72a32017-04-06 23:26:04 -0400292elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
293 set(ARCH "x86_64")
294elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
295 set(ARCH "x86_64")
296elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
297 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
298 if (CMAKE_CL_64)
299 set(ARCH "x86_64")
300 else()
301 set(ARCH "x86")
302 endif()
303elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
304 set(ARCH "x86")
305elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
306 set(ARCH "x86")
307elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
308 set(ARCH "x86")
309elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
310 set(ARCH "aarch64")
311elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
312 set(ARCH "aarch64")
313elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
314 set(ARCH "arm")
315elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
316 # Just to avoid the “unknown processor” error.
317 set(ARCH "generic")
318elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
319 set(ARCH "ppc64le")
320else()
321 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
David Benjamin27b08e92015-05-04 15:16:57 -0400322endif()
323
David Benjaminaff72a32017-04-06 23:26:04 -0400324if (ANDROID AND ${ARCH} STREQUAL "arm")
325 # The Android-NDK CMake files somehow fail to set the -march flag for
326 # assembly files. Without this flag, the compiler believes that it's
327 # building for ARMv5.
328 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
329endif()
330
David Benjaminf5beb882017-10-27 10:43:15 -0400331if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
David Benjaminaff72a32017-04-06 23:26:04 -0400332 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
333 # but clang defaults to 64-bit builds on OS X unless otherwise told.
334 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
335 set(ARCH "x86_64")
Adam Langleyfd499932017-04-04 14:21:43 -0700336endif()
337
David Benjamin96628432017-01-19 19:05:47 -0500338# Add minimal googletest targets. The provided one has many side-effects, and
339# googletest has a very straightforward build.
340add_library(gtest third_party/googletest/src/gtest-all.cc)
341target_include_directories(gtest PRIVATE third_party/googletest)
David Benjamin96628432017-01-19 19:05:47 -0500342
343include_directories(third_party/googletest/include)
344
David Benjamin301afaf2015-10-14 21:34:40 -0400345# Declare a dummy target to build all unit tests. Test targets should inject
346# themselves as dependencies next to the target definition.
347add_custom_target(all_tests)
348
David Benjamin3ecd0a52017-05-19 15:26:18 -0400349add_custom_command(
350 OUTPUT crypto_test_data.cc
351 COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
352 ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
353 DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
354 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
355
356add_library(crypto_test_data OBJECT crypto_test_data.cc)
357
Adam Langley95c29f32014-06-20 12:00:00 -0700358add_subdirectory(crypto)
Andres Erbsen5b280a82017-10-30 15:58:33 +0000359add_subdirectory(third_party/fiat)
Adam Langley95c29f32014-06-20 12:00:00 -0700360add_subdirectory(ssl)
361add_subdirectory(ssl/test)
Martin Kreichgauer118355c2017-05-12 15:34:45 -0700362add_subdirectory(fipstools)
Adam Langley95c29f32014-06-20 12:00:00 -0700363add_subdirectory(tool)
Adam Langleyc004dfc2015-02-03 10:45:12 -0800364add_subdirectory(decrepit)
David Benjamin301afaf2015-10-14 21:34:40 -0400365
Adam Langley9a4beb82015-11-09 13:57:26 -0800366if(FUZZ)
David Benjamin1e5cb822017-05-10 16:07:56 -0400367 if(LIBFUZZER_FROM_DEPS)
368 file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
369 add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
370 # libFuzzer does not pass our aggressive warnings. It also must be built
371 # without -fsanitize-coverage options or clang crashes.
David Benjamin6fb16cc2017-07-14 11:02:39 -0400372 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 -0400373 endif()
374
Adam Langley9a4beb82015-11-09 13:57:26 -0800375 add_subdirectory(fuzz)
376endif()
377
David Benjamin301afaf2015-10-14 21:34:40 -0400378if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
379 # USES_TERMINAL is only available in CMake 3.2 or later.
380 set(MAYBE_USES_TERMINAL USES_TERMINAL)
381endif()
382
383add_custom_target(
384 run_tests
385 COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
386 ${CMAKE_BINARY_DIR}
Adam Langleyd5c72c82016-09-23 16:43:17 -0700387 COMMAND cd ssl/test/runner &&
388 ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
389 ${RUNNER_ARGS}
David Benjamin301afaf2015-10-14 21:34:40 -0400390 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
391 DEPENDS all_tests bssl_shim
392 ${MAYBE_USES_TERMINAL})