blob: c05e645a90e23e4ca94b8f572cb2e90eac0bf7b3 [file] [log] [blame]
Adam Langley07100c62015-01-16 15:20:54 -08001cmake_minimum_required (VERSION 2.8.10)
Adam Langley95c29f32014-06-20 12:00:00 -07002
3project (BoringSSL)
4
Adam Langley843ab662015-04-28 17:46:58 -07005if(ANDROID)
6 # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
7 # found. However, ninja will still find them in $PATH if we just name them.
8 set(PERL_EXECUTABLE "perl")
9 set(GO_EXECUTABLE "go")
10else()
11 find_package(Perl REQUIRED)
12 find_program(GO_EXECUTABLE go)
13endif()
David Benjamin3ce3c362015-02-23 13:06:19 -050014
David Benjamind27eda02015-03-05 01:19:27 -050015if (NOT GO_EXECUTABLE)
16 message(FATAL_ERROR "Could not find Go")
17endif()
18
Brian Smith1d75c8b2015-01-23 17:25:44 -080019if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Adam Langleyd9e81732015-10-30 13:43:49 -070020 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wsign-compare -Wmissing-field-initializers -ggdb -fvisibility=hidden")
21 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wsign-compare -Wmissing-field-initializers -ggdb -std=c++0x -fvisibility=hidden")
Adam Langley95c29f32014-06-20 12:00:00 -070022elseif(MSVC)
Brian Smithefed2212015-01-28 16:20:02 -080023 set(MSVC_DISABLED_WARNINGS_LIST
24 "C4100" # 'exarg' : unreferenced formal parameter
25 "C4127" # conditional expression is constant
26 "C4200" # nonstandard extension used : zero-sized array in
27 # struct/union.
28 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
29 # possible loss of data
30 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
31 # possible loss of data
32 "C4245" # 'initializing' : conversion from 'long' to
33 # 'unsigned long', signed/unsigned mismatch
David Benjamin3673be72015-02-11 15:12:05 -050034 "C4267" # conversion from 'size_t' to 'int', possible loss of data
David Benjamin3673be72015-02-11 15:12:05 -050035 "C4371" # layout of class may have changed from a previous version of the
36 # compiler due to better packing of member '...'
37 "C4388" # signed/unsigned mismatch
Brian Smithefed2212015-01-28 16:20:02 -080038 "C4296" # '>=' : expression is always true
39 "C4350" # behavior change: 'std::_Wrap_alloc...'
40 "C4365" # '=' : conversion from 'size_t' to 'int',
41 # signed/unsigned mismatch
42 "C4389" # '!=' : signed/unsigned mismatch
43 "C4510" # 'argument' : default constructor could not be generated
44 "C4512" # 'argument' : assignment operator could not be generated
45 "C4514" # 'function': unreferenced inline function has been removed
46 "C4548" # expression before comma has no effect; expected expression with
47 # side-effect" caused by FD_* macros.
48 "C4610" # struct 'argument' can never be instantiated - user defined
49 # constructor required.
David Benjamin3673be72015-02-11 15:12:05 -050050 "C4625" # copy constructor could not be generated because a base class
51 # copy constructor is inaccessible or deleted
52 "C4626" # assignment operator could not be generated because a base class
53 # assignment operator is inaccessible or deleted
Brian Smithefed2212015-01-28 16:20:02 -080054 "C4706" # assignment within conditional expression
55 "C4710" # 'function': function not inlined
56 "C4711" # function 'function' selected for inline expansion
57 "C4800" # 'int' : forcing value to bool 'true' or 'false'
58 # (performance warning)
59 "C4820" # 'bytes' bytes padding added after construct 'member_name'
60 "C4996" # 'read': The POSIX name for this item is deprecated. Instead,
61 # use the ISO C++ conformant name: _read.
62 )
63 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
64 ${MSVC_DISABLED_WARNINGS_LIST})
65 set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
66 set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
Adam Langley4a0f0c42015-01-28 16:37:10 -080067 add_definitions(-D_HAS_EXCEPTIONS=0)
Brian Smitha87de9b2015-01-28 20:34:47 -080068 add_definitions(-DWIN32_LEAN_AND_MEAN)
David Benjamin0e434b92015-04-02 13:20:01 -040069 add_definitions(-DNOMINMAX)
Adam Langley95c29f32014-06-20 12:00:00 -070070endif()
71
David Benjaminb826c0d2015-02-28 00:00:44 -050072if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
Brian Smith1d75c8b2015-01-23 17:25:44 -080073 CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Adam Langley4a0f0c42015-01-28 16:37:10 -080074 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
75 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
Adam Langley07100c62015-01-16 15:20:54 -080076endif()
77
Adam Langley6f2e7332015-05-15 12:01:29 -070078if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
79 CMAKE_CXX_COMPILER_ID MATCHES "Clang")
80 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_XOPEN_SOURCE=700")
81endif()
82
Adam Langley9a4beb82015-11-09 13:57:26 -080083if(FUZZ)
84 if(!CMAKE_CXX_COMPILER_ID MATCHES "Clang")
85 message("You need to build with Clang for fuzzing to work")
86 endif()
87
88 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls")
89 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls")
90 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
91endif()
92
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070093add_definitions(-DBORINGSSL_IMPLEMENTATION)
94
David Benjamin507c1ee2015-01-28 00:50:21 -050095if (BUILD_SHARED_LIBS)
Adam Langley4a0f0c42015-01-28 16:37:10 -080096 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
97 # Enable position-independent code globally. This is needed because
98 # some library targets are OBJECT libraries.
99 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
David Benjamin507c1ee2015-01-28 00:50:21 -0500100endif()
101
Adam Langley95c29f32014-06-20 12:00:00 -0700102if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800103 set(ARCH "x86_64")
Piotr Sikora1d8adf12014-07-31 03:09:49 -0700104elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800105 set(ARCH "x86_64")
Adam Langley95c29f32014-06-20 12:00:00 -0700106elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800107 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
108 if (CMAKE_CL_64)
109 set(ARCH "x86_64")
110 else()
111 set(ARCH "x86")
112 endif()
Adam Langley95c29f32014-06-20 12:00:00 -0700113elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800114 set(ARCH "x86")
Piotr Sikora1d8adf12014-07-31 03:09:49 -0700115elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800116 set(ARCH "x86")
Lukas Tribusd83f38c2014-08-11 13:27:44 -0700117elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800118 set(ARCH "x86")
Adam Langley95c29f32014-06-20 12:00:00 -0700119elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800120 set(ARCH "arm")
Joel Klinghed1550a842015-05-29 15:06:45 +0200121elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
122 set(ARCH "arm")
Adam Langley843ab662015-04-28 17:46:58 -0700123elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
124 set(ARCH "arm")
Adam Langley3e652652015-01-09 15:44:37 -0800125elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
Adam Langley4a0f0c42015-01-28 16:37:10 -0800126 set(ARCH "aarch64")
Adam Langley95c29f32014-06-20 12:00:00 -0700127else()
Adam Langley4a0f0c42015-01-28 16:37:10 -0800128 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
Adam Langley95c29f32014-06-20 12:00:00 -0700129endif()
130
Adam Langley843ab662015-04-28 17:46:58 -0700131if (ANDROID AND ${ARCH} STREQUAL "arm")
132 # The Android-NDK CMake files somehow fail to set the -march flag for
133 # assembly files. Without this flag, the compiler believes that it's
134 # building for ARMv5.
Joel Klinghed1550a842015-05-29 15:06:45 +0200135 set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
Adam Langley843ab662015-04-28 17:46:58 -0700136endif()
137
Nico Weberdeb52842014-11-18 12:14:46 -0800138if (${ARCH} STREQUAL "x86" AND APPLE)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800139 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
140 # but clang defaults to 64-bit builds on OS X unless otherwise told.
141 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
142 set(ARCH "x86_64")
Nico Weberdeb52842014-11-18 12:14:46 -0800143endif()
144
David Benjamin27b08e92015-05-04 15:16:57 -0400145if (OPENSSL_NO_ASM)
146 add_definitions(-DOPENSSL_NO_ASM)
147 set(ARCH "generic")
148endif()
149
David Benjamin301afaf2015-10-14 21:34:40 -0400150# Declare a dummy target to build all unit tests. Test targets should inject
151# themselves as dependencies next to the target definition.
152add_custom_target(all_tests)
153
Adam Langley95c29f32014-06-20 12:00:00 -0700154add_subdirectory(crypto)
155add_subdirectory(ssl)
156add_subdirectory(ssl/test)
157add_subdirectory(tool)
Adam Langleyc004dfc2015-02-03 10:45:12 -0800158add_subdirectory(decrepit)
David Benjamin301afaf2015-10-14 21:34:40 -0400159
Adam Langley9a4beb82015-11-09 13:57:26 -0800160if(FUZZ)
161 add_subdirectory(fuzz)
162endif()
163
David Benjamin301afaf2015-10-14 21:34:40 -0400164if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
165 # USES_TERMINAL is only available in CMake 3.2 or later.
166 set(MAYBE_USES_TERMINAL USES_TERMINAL)
167endif()
168
169add_custom_target(
170 run_tests
171 COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
172 ${CMAKE_BINARY_DIR}
173 COMMAND cd ssl/test/runner
174 COMMAND ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
175 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
176 DEPENDS all_tests bssl_shim
177 ${MAYBE_USES_TERMINAL})