• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required (VERSION 2.8.10)
2
3project (BoringSSL)
4
5if(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()
14
15if (NOT GO_EXECUTABLE)
16  message(FATAL_ERROR "Could not find Go")
17endif()
18
19if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
20  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")
22elseif(MSVC)
23  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
34      "C4267" # conversion from 'size_t' to 'int', possible loss of data
35      "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
38      "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.
50      "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
54      "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}")
67  add_definitions(-D_HAS_EXCEPTIONS=0)
68  add_definitions(-DWIN32_LEAN_AND_MEAN)
69  add_definitions(-DNOMINMAX)
70endif()
71
72if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
73   CMAKE_CXX_COMPILER_ID MATCHES "Clang")
74  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
75  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
76endif()
77
78if((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
83if(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")
91  link_directories(.)
92endif()
93
94add_definitions(-DBORINGSSL_IMPLEMENTATION)
95
96if (BUILD_SHARED_LIBS)
97  add_definitions(-DBORINGSSL_SHARED_LIBRARY)
98  # Enable position-independent code globally. This is needed because
99  # some library targets are OBJECT libraries.
100  set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
101endif()
102
103if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
104  set(ARCH "x86_64")
105elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
106  set(ARCH "x86_64")
107elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
108  # cmake reports AMD64 on Windows, but we might be building for 32-bit.
109  if (CMAKE_CL_64)
110    set(ARCH "x86_64")
111  else()
112    set(ARCH "x86")
113  endif()
114elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
115  set(ARCH "x86")
116elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
117  set(ARCH "x86")
118elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
119  set(ARCH "x86")
120elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
121  set(ARCH "arm")
122elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
123  set(ARCH "arm")
124elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
125  set(ARCH "arm")
126elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
127  set(ARCH "aarch64")
128else()
129  message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
130endif()
131
132if (ANDROID AND ${ARCH} STREQUAL "arm")
133  # The Android-NDK CMake files somehow fail to set the -march flag for
134  # assembly files. Without this flag, the compiler believes that it's
135  # building for ARMv5.
136  set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
137endif()
138
139if (${ARCH} STREQUAL "x86" AND APPLE)
140  # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
141  # but clang defaults to 64-bit builds on OS X unless otherwise told.
142  # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
143  set(ARCH "x86_64")
144endif()
145
146if (OPENSSL_NO_ASM)
147  add_definitions(-DOPENSSL_NO_ASM)
148  set(ARCH "generic")
149endif()
150
151# Declare a dummy target to build all unit tests. Test targets should inject
152# themselves as dependencies next to the target definition.
153add_custom_target(all_tests)
154
155add_subdirectory(crypto)
156add_subdirectory(ssl)
157add_subdirectory(ssl/test)
158add_subdirectory(tool)
159add_subdirectory(decrepit)
160
161if(FUZZ)
162  add_subdirectory(fuzz)
163endif()
164
165if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
166  # USES_TERMINAL is only available in CMake 3.2 or later.
167  set(MAYBE_USES_TERMINAL USES_TERMINAL)
168endif()
169
170add_custom_target(
171    run_tests
172    COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
173            ${CMAKE_BINARY_DIR}
174    COMMAND cd ssl/test/runner
175    COMMAND ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
176    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
177    DEPENDS all_tests bssl_shim
178    ${MAYBE_USES_TERMINAL})
179