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 -ggdb -fvisibility=hidden")
21  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -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      "C4210" # nonstandard extension used : function given file scope
29      "C4242" # 'function' : conversion from 'int' to 'uint8_t',
30              # possible loss of data
31      "C4244" # 'function' : conversion from 'int' to 'uint8_t',
32              # possible loss of data
33      "C4245" # 'initializing' : conversion from 'long' to
34              # 'unsigned long', signed/unsigned mismatch
35      "C4267" # conversion from 'size_t' to 'int', possible loss of data
36      "C4371" # layout of class may have changed from a previous version of the
37              # compiler due to better packing of member '...'
38      "C4388" # signed/unsigned mismatch
39      "C4296" # '>=' : expression is always true
40      "C4350" # behavior change: 'std::_Wrap_alloc...'
41      "C4365" # '=' : conversion from 'size_t' to 'int',
42              # signed/unsigned mismatch
43      "C4389" # '!=' : signed/unsigned mismatch
44      "C4510" # 'argument' : default constructor could not be generated
45      "C4512" # 'argument' : assignment operator could not be generated
46      "C4514" # 'function': unreferenced inline function has been removed
47      "C4548" # expression before comma has no effect; expected expression with
48              # side-effect" caused by FD_* macros.
49      "C4610" # struct 'argument' can never be instantiated - user defined
50              # constructor required.
51      "C4625" # copy constructor could not be generated because a base class
52              # copy constructor is inaccessible or deleted
53      "C4626" # assignment operator could not be generated because a base class
54              # assignment operator is inaccessible or deleted
55      "C4706" # assignment within conditional expression
56      "C4710" # 'function': function not inlined
57      "C4711" # function 'function' selected for inline expansion
58      "C4800" # 'int' : forcing value to bool 'true' or 'false'
59              # (performance warning)
60      "C4820" # 'bytes' bytes padding added after construct 'member_name'
61      "C4996" # 'read': The POSIX name for this item is deprecated. Instead,
62              # use the ISO C++ conformant name: _read.
63     )
64  string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
65                            ${MSVC_DISABLED_WARNINGS_LIST})
66  set(CMAKE_C_FLAGS   "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
67  set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
68  add_definitions(-D_HAS_EXCEPTIONS=0)
69  add_definitions(-DWIN32_LEAN_AND_MEAN)
70  add_definitions(-DNOMINMAX)
71endif()
72
73if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
74   CMAKE_CXX_COMPILER_ID MATCHES "Clang")
75  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
76  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
77endif()
78
79if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
80   CMAKE_CXX_COMPILER_ID MATCHES "Clang")
81 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_XOPEN_SOURCE=700")
82endif()
83
84add_definitions(-DBORINGSSL_IMPLEMENTATION)
85
86if (BUILD_SHARED_LIBS)
87  add_definitions(-DBORINGSSL_SHARED_LIBRARY)
88  # Enable position-independent code globally. This is needed because
89  # some library targets are OBJECT libraries.
90  set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
91endif()
92
93if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
94  set(ARCH "x86_64")
95elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
96  set(ARCH "x86_64")
97elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
98  # cmake reports AMD64 on Windows, but we might be building for 32-bit.
99  if (CMAKE_CL_64)
100    set(ARCH "x86_64")
101  else()
102    set(ARCH "x86")
103  endif()
104elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
105  set(ARCH "x86")
106elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
107  set(ARCH "x86")
108elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
109  set(ARCH "x86")
110elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
111  set(ARCH "arm")
112elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
113  set(ARCH "arm")
114elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
115  set(ARCH "arm")
116elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
117  set(ARCH "aarch64")
118else()
119  message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
120endif()
121
122if (ANDROID AND ${ARCH} STREQUAL "arm")
123  # The Android-NDK CMake files somehow fail to set the -march flag for
124  # assembly files. Without this flag, the compiler believes that it's
125  # building for ARMv5.
126  set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
127endif()
128
129if (${ARCH} STREQUAL "x86" AND APPLE)
130  # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
131  # but clang defaults to 64-bit builds on OS X unless otherwise told.
132  # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
133  set(ARCH "x86_64")
134endif()
135
136if (OPENSSL_NO_ASM)
137  add_definitions(-DOPENSSL_NO_ASM)
138  set(ARCH "generic")
139endif()
140
141add_subdirectory(crypto)
142add_subdirectory(ssl)
143add_subdirectory(ssl/test)
144add_subdirectory(tool)
145add_subdirectory(decrepit)
146