blob: 0a741661ec3523684a7cf660d9bd5869d6aad82d [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
David Benjamin3ce3c362015-02-23 13:06:19 -05005find_package(Perl REQUIRED)
6
Brian Smith1d75c8b2015-01-23 17:25:44 -08007if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Adam Langley4a0f0c42015-01-28 16:37:10 -08008 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -ggdb -fvisibility=hidden")
9 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ggdb -std=c++0x -fvisibility=hidden")
Adam Langley95c29f32014-06-20 12:00:00 -070010elseif(MSVC)
Brian Smithefed2212015-01-28 16:20:02 -080011 set(MSVC_DISABLED_WARNINGS_LIST
12 "C4100" # 'exarg' : unreferenced formal parameter
13 "C4127" # conditional expression is constant
14 "C4200" # nonstandard extension used : zero-sized array in
15 # struct/union.
David Benjamin3673be72015-02-11 15:12:05 -050016 "C4210" # nonstandard extension used : function given file scope
Brian Smithefed2212015-01-28 16:20:02 -080017 "C4242" # 'function' : conversion from 'int' to 'uint8_t',
18 # possible loss of data
19 "C4244" # 'function' : conversion from 'int' to 'uint8_t',
20 # possible loss of data
21 "C4245" # 'initializing' : conversion from 'long' to
22 # 'unsigned long', signed/unsigned mismatch
David Benjamin3673be72015-02-11 15:12:05 -050023 "C4267" # conversion from 'size_t' to 'int', possible loss of data
24 "C4311" # 'type cast' : pointer truncation from 'uint8_t *' to 'long'
25 # TODO(davidben): Fix the s3_pkt.c's alignment code to avoid this.
26 "C4371" # layout of class may have changed from a previous version of the
27 # compiler due to better packing of member '...'
28 "C4388" # signed/unsigned mismatch
Brian Smithefed2212015-01-28 16:20:02 -080029 "C4296" # '>=' : expression is always true
30 "C4350" # behavior change: 'std::_Wrap_alloc...'
31 "C4365" # '=' : conversion from 'size_t' to 'int',
32 # signed/unsigned mismatch
33 "C4389" # '!=' : signed/unsigned mismatch
34 "C4510" # 'argument' : default constructor could not be generated
35 "C4512" # 'argument' : assignment operator could not be generated
36 "C4514" # 'function': unreferenced inline function has been removed
37 "C4548" # expression before comma has no effect; expected expression with
38 # side-effect" caused by FD_* macros.
39 "C4610" # struct 'argument' can never be instantiated - user defined
40 # constructor required.
David Benjamin3673be72015-02-11 15:12:05 -050041 "C4625" # copy constructor could not be generated because a base class
42 # copy constructor is inaccessible or deleted
43 "C4626" # assignment operator could not be generated because a base class
44 # assignment operator is inaccessible or deleted
Brian Smithefed2212015-01-28 16:20:02 -080045 "C4701" # potentially uninitialized local variable 'mdlen' used
46 "C4706" # assignment within conditional expression
47 "C4710" # 'function': function not inlined
48 "C4711" # function 'function' selected for inline expansion
49 "C4800" # 'int' : forcing value to bool 'true' or 'false'
50 # (performance warning)
51 "C4820" # 'bytes' bytes padding added after construct 'member_name'
52 "C4996" # 'read': The POSIX name for this item is deprecated. Instead,
53 # use the ISO C++ conformant name: _read.
54 )
55 string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
56 ${MSVC_DISABLED_WARNINGS_LIST})
57 set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
58 set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR}")
Adam Langley4a0f0c42015-01-28 16:37:10 -080059 add_definitions(-D_HAS_EXCEPTIONS=0)
Brian Smitha87de9b2015-01-28 20:34:47 -080060 add_definitions(-DWIN32_LEAN_AND_MEAN)
Adam Langley95c29f32014-06-20 12:00:00 -070061endif()
62
Brian Smith1d75c8b2015-01-23 17:25:44 -080063if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.5.99") OR
64 CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Adam Langley4a0f0c42015-01-28 16:37:10 -080065 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
66 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
Adam Langley07100c62015-01-16 15:20:54 -080067endif()
68
Adam Langleyeb7d2ed2014-07-30 16:02:14 -070069add_definitions(-DBORINGSSL_IMPLEMENTATION)
70
David Benjamin507c1ee2015-01-28 00:50:21 -050071if (BUILD_SHARED_LIBS)
Adam Langley4a0f0c42015-01-28 16:37:10 -080072 add_definitions(-DBORINGSSL_SHARED_LIBRARY)
73 # Enable position-independent code globally. This is needed because
74 # some library targets are OBJECT libraries.
75 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
David Benjamin507c1ee2015-01-28 00:50:21 -050076endif()
77
Adam Langley95c29f32014-06-20 12:00:00 -070078if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
Adam Langley4a0f0c42015-01-28 16:37:10 -080079 set(ARCH "x86_64")
Piotr Sikora1d8adf12014-07-31 03:09:49 -070080elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
Adam Langley4a0f0c42015-01-28 16:37:10 -080081 set(ARCH "x86_64")
Adam Langley95c29f32014-06-20 12:00:00 -070082elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
Adam Langley4a0f0c42015-01-28 16:37:10 -080083 # cmake reports AMD64 on Windows, but we might be building for 32-bit.
84 if (CMAKE_CL_64)
85 set(ARCH "x86_64")
86 else()
87 set(ARCH "x86")
88 endif()
Adam Langley95c29f32014-06-20 12:00:00 -070089elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
Adam Langley4a0f0c42015-01-28 16:37:10 -080090 set(ARCH "x86")
Piotr Sikora1d8adf12014-07-31 03:09:49 -070091elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
Adam Langley4a0f0c42015-01-28 16:37:10 -080092 set(ARCH "x86")
Lukas Tribusd83f38c2014-08-11 13:27:44 -070093elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
Adam Langley4a0f0c42015-01-28 16:37:10 -080094 set(ARCH "x86")
Adam Langley95c29f32014-06-20 12:00:00 -070095elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
Adam Langley4a0f0c42015-01-28 16:37:10 -080096 set(ARCH "arm")
Adam Langley3e652652015-01-09 15:44:37 -080097elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
Adam Langley4a0f0c42015-01-28 16:37:10 -080098 set(ARCH "aarch64")
Adam Langley95c29f32014-06-20 12:00:00 -070099else()
Adam Langley4a0f0c42015-01-28 16:37:10 -0800100 message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
Adam Langley95c29f32014-06-20 12:00:00 -0700101endif()
102
Nico Weberdeb52842014-11-18 12:14:46 -0800103if (${ARCH} STREQUAL "x86" AND APPLE)
Adam Langley4a0f0c42015-01-28 16:37:10 -0800104 # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
105 # but clang defaults to 64-bit builds on OS X unless otherwise told.
106 # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
107 set(ARCH "x86_64")
Nico Weberdeb52842014-11-18 12:14:46 -0800108endif()
109
Adam Langley95c29f32014-06-20 12:00:00 -0700110add_subdirectory(crypto)
111add_subdirectory(ssl)
112add_subdirectory(ssl/test)
113add_subdirectory(tool)