2015-01-16 23:20:54 +00:00
|
|
|
cmake_minimum_required (VERSION 2.8.10)
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2016-02-06 02:58:39 +00:00
|
|
|
# Defer enabling C and CXX languages.
|
|
|
|
project (BoringSSL NONE)
|
|
|
|
|
|
|
|
if(WIN32)
|
|
|
|
# On Windows, prefer cl over gcc if both are available. By default most of
|
|
|
|
# the CMake generators prefer gcc, even on Windows.
|
|
|
|
set(CMAKE_GENERATOR_CC cl)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
enable_language(C)
|
|
|
|
enable_language(CXX)
|
2014-06-20 20:00:00 +01:00
|
|
|
|
2015-04-29 01:46:58 +01:00
|
|
|
if(ANDROID)
|
|
|
|
# Android-NDK CMake files reconfigure the path and so Go and Perl won't be
|
|
|
|
# found. However, ninja will still find them in $PATH if we just name them.
|
2016-05-19 14:28:14 +01:00
|
|
|
if(NOT PERL_EXECUTABLE)
|
|
|
|
set(PERL_EXECUTABLE "perl")
|
|
|
|
endif()
|
|
|
|
if(NOT GO_EXECUTABLE)
|
|
|
|
set(GO_EXECUTABLE "go")
|
|
|
|
endif()
|
2015-04-29 01:46:58 +01:00
|
|
|
else()
|
|
|
|
find_package(Perl REQUIRED)
|
|
|
|
find_program(GO_EXECUTABLE go)
|
|
|
|
endif()
|
2015-02-23 18:06:19 +00:00
|
|
|
|
2015-03-05 06:19:27 +00:00
|
|
|
if (NOT GO_EXECUTABLE)
|
|
|
|
message(FATAL_ERROR "Could not find Go")
|
|
|
|
endif()
|
|
|
|
|
2015-01-24 01:25:44 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-01-17 20:03:28 +00:00
|
|
|
set(C_CXX_FLAGS "-Wall -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -ggdb -fvisibility=hidden")
|
2016-03-19 01:25:28 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x ${C_CXX_FLAGS} -Wmissing-declarations")
|
2014-06-20 20:00:00 +01:00
|
|
|
elseif(MSVC)
|
2015-01-29 00:20:02 +00:00
|
|
|
set(MSVC_DISABLED_WARNINGS_LIST
|
|
|
|
"C4100" # 'exarg' : unreferenced formal parameter
|
|
|
|
"C4127" # conditional expression is constant
|
|
|
|
"C4200" # nonstandard extension used : zero-sized array in
|
|
|
|
# struct/union.
|
|
|
|
"C4242" # 'function' : conversion from 'int' to 'uint8_t',
|
|
|
|
# possible loss of data
|
|
|
|
"C4244" # 'function' : conversion from 'int' to 'uint8_t',
|
|
|
|
# possible loss of data
|
|
|
|
"C4245" # 'initializing' : conversion from 'long' to
|
|
|
|
# 'unsigned long', signed/unsigned mismatch
|
2015-02-11 20:12:05 +00:00
|
|
|
"C4267" # conversion from 'size_t' to 'int', possible loss of data
|
|
|
|
"C4371" # layout of class may have changed from a previous version of the
|
|
|
|
# compiler due to better packing of member '...'
|
|
|
|
"C4388" # signed/unsigned mismatch
|
2015-01-29 00:20:02 +00:00
|
|
|
"C4296" # '>=' : expression is always true
|
|
|
|
"C4350" # behavior change: 'std::_Wrap_alloc...'
|
|
|
|
"C4365" # '=' : conversion from 'size_t' to 'int',
|
|
|
|
# signed/unsigned mismatch
|
|
|
|
"C4389" # '!=' : signed/unsigned mismatch
|
2016-05-02 17:57:01 +01:00
|
|
|
"C4464" # relative include path contains '..'
|
2015-01-29 00:20:02 +00:00
|
|
|
"C4510" # 'argument' : default constructor could not be generated
|
|
|
|
"C4512" # 'argument' : assignment operator could not be generated
|
|
|
|
"C4514" # 'function': unreferenced inline function has been removed
|
|
|
|
"C4548" # expression before comma has no effect; expected expression with
|
|
|
|
# side-effect" caused by FD_* macros.
|
|
|
|
"C4610" # struct 'argument' can never be instantiated - user defined
|
|
|
|
# constructor required.
|
2016-05-02 17:57:01 +01:00
|
|
|
"C4623" # default constructor was implicitly defined as deleted
|
2015-02-11 20:12:05 +00:00
|
|
|
"C4625" # copy constructor could not be generated because a base class
|
|
|
|
# copy constructor is inaccessible or deleted
|
|
|
|
"C4626" # assignment operator could not be generated because a base class
|
|
|
|
# assignment operator is inaccessible or deleted
|
2015-01-29 00:20:02 +00:00
|
|
|
"C4706" # assignment within conditional expression
|
|
|
|
"C4710" # 'function': function not inlined
|
|
|
|
"C4711" # function 'function' selected for inline expansion
|
|
|
|
"C4800" # 'int' : forcing value to bool 'true' or 'false'
|
|
|
|
# (performance warning)
|
|
|
|
"C4820" # 'bytes' bytes padding added after construct 'member_name'
|
2016-05-02 17:57:01 +01:00
|
|
|
"C5027" # move assignment operator was implicitly defined as deleted
|
|
|
|
)
|
|
|
|
set(MSVC_LEVEL4_WARNINGS_LIST
|
|
|
|
# See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
|
|
|
|
"C4265" # class has virtual functions, but destructor is not virtual
|
|
|
|
)
|
2015-01-29 00:20:02 +00:00
|
|
|
string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
|
|
|
|
${MSVC_DISABLED_WARNINGS_LIST})
|
2016-05-02 17:57:01 +01:00
|
|
|
string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
|
|
|
|
${MSVC_LEVEL4_WARNINGS_LIST})
|
Fix build when using Visual Studio 2015 Update 1.
Many of the compatibility issues are described at
https://msdn.microsoft.com/en-us/library/mt612856.aspx. The macros
that suppressed warnings on a per-function basis no longer work in
Update 1, so replace them with #pragmas. Update 1 warns when |size_t|
arguments to |printf| are casted, so stop doing that casting.
Unfortunately, this requires an ugly hack to continue working in
MSVC 2013 as MSVC 2013 doesn't support "%zu". Finally, Update 1 has new
warnings, some of which need to be suppressed.
---
Updated by davidben to give up on suppressing warnings in crypto/x509 and
crypto/x509v3 as those directories aren't changed much from upstream. In each
of these cases, upstream opted just blindly initialize the variable, so do the
same. Also switch C4265 to level 4, per Microsoft's recommendation and work
around a bug in limits.h that happens to get fixed by Google include order
style.
(limits.h is sensitive to whether corecrt.h, pulled in by stddef.h and some
other headers, is included before it. The reason it affected just one file is
we often put the file's header first, which means base.h is pulling in
stddef.h. Relying on this is ugly, but it's no worse than what everything else
is doing and this doesn't seem worth making something as tame as limits.h so
messy to use.)
Change-Id: I02d1f935356899f424d3525d03eca401bfa3e6cd
Reviewed-on: https://boringssl-review.googlesource.com/7480
Reviewed-by: David Benjamin <davidben@google.com>
2016-01-18 08:21:42 +00:00
|
|
|
set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
|
|
|
|
set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
|
2015-01-29 00:37:10 +00:00
|
|
|
add_definitions(-D_HAS_EXCEPTIONS=0)
|
2015-01-29 04:34:47 +00:00
|
|
|
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
2015-04-02 18:20:01 +01:00
|
|
|
add_definitions(-DNOMINMAX)
|
2016-05-19 16:49:59 +01:00
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Allow use of fopen
|
2014-06-20 20:00:00 +01:00
|
|
|
endif()
|
|
|
|
|
2015-02-28 05:00:44 +00:00
|
|
|
if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
|
2015-01-24 01:25:44 +00:00
|
|
|
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
|
2015-01-16 23:20:54 +00:00
|
|
|
endif()
|
|
|
|
|
2016-06-09 21:22:26 +01:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
|
|
|
|
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
|
|
|
|
else()
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# pthread_rwlock_t requires a feature flag.
|
|
|
|
if(NOT WIN32)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
|
2015-05-15 20:01:29 +01:00
|
|
|
endif()
|
|
|
|
|
2015-11-09 21:57:26 +00:00
|
|
|
if(FUZZ)
|
|
|
|
if(!CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
message("You need to build with Clang for fuzzing to work")
|
|
|
|
endif()
|
|
|
|
|
2016-03-02 03:57:32 +00:00
|
|
|
add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
|
2016-03-02 03:57:46 +00:00
|
|
|
set(RUNNER_ARGS "-fuzzer")
|
2016-03-02 03:57:32 +00:00
|
|
|
|
2016-03-03 17:50:10 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
|
2015-11-09 21:57:26 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
2015-11-10 23:00:51 +00:00
|
|
|
link_directories(.)
|
2015-11-09 21:57:26 +00:00
|
|
|
endif()
|
|
|
|
|
2014-07-31 00:02:14 +01:00
|
|
|
add_definitions(-DBORINGSSL_IMPLEMENTATION)
|
|
|
|
|
2015-01-28 05:50:21 +00:00
|
|
|
if (BUILD_SHARED_LIBS)
|
2015-01-29 00:37:10 +00:00
|
|
|
add_definitions(-DBORINGSSL_SHARED_LIBRARY)
|
|
|
|
# Enable position-independent code globally. This is needed because
|
|
|
|
# some library targets are OBJECT libraries.
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
|
2015-01-28 05:50:21 +00:00
|
|
|
endif()
|
|
|
|
|
2014-06-20 20:00:00 +01:00
|
|
|
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "x86_64")
|
2014-07-31 11:09:49 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "x86_64")
|
2014-06-20 20:00:00 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
|
2015-01-29 00:37:10 +00:00
|
|
|
# cmake reports AMD64 on Windows, but we might be building for 32-bit.
|
|
|
|
if (CMAKE_CL_64)
|
|
|
|
set(ARCH "x86_64")
|
|
|
|
else()
|
|
|
|
set(ARCH "x86")
|
|
|
|
endif()
|
2014-06-20 20:00:00 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "x86")
|
2014-07-31 11:09:49 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "x86")
|
2014-08-11 21:27:44 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "x86")
|
2014-06-20 20:00:00 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "arm")
|
2015-05-29 14:06:45 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
|
|
|
|
set(ARCH "arm")
|
2015-04-29 01:46:58 +01:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
|
|
|
|
set(ARCH "arm")
|
2015-01-09 23:44:37 +00:00
|
|
|
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
|
2015-01-29 00:37:10 +00:00
|
|
|
set(ARCH "aarch64")
|
2014-06-20 20:00:00 +01:00
|
|
|
else()
|
2015-01-29 00:37:10 +00:00
|
|
|
message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
|
2014-06-20 20:00:00 +01:00
|
|
|
endif()
|
|
|
|
|
2015-04-29 01:46:58 +01:00
|
|
|
if (ANDROID AND ${ARCH} STREQUAL "arm")
|
|
|
|
# The Android-NDK CMake files somehow fail to set the -march flag for
|
|
|
|
# assembly files. Without this flag, the compiler believes that it's
|
|
|
|
# building for ARMv5.
|
2015-05-29 14:06:45 +01:00
|
|
|
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
|
2015-04-29 01:46:58 +01:00
|
|
|
endif()
|
|
|
|
|
2014-11-18 20:14:46 +00:00
|
|
|
if (${ARCH} STREQUAL "x86" AND APPLE)
|
2015-01-29 00:37:10 +00:00
|
|
|
# With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
|
|
|
|
# but clang defaults to 64-bit builds on OS X unless otherwise told.
|
|
|
|
# Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
|
|
|
|
set(ARCH "x86_64")
|
2014-11-18 20:14:46 +00:00
|
|
|
endif()
|
|
|
|
|
2015-05-04 20:16:57 +01:00
|
|
|
if (OPENSSL_NO_ASM)
|
|
|
|
add_definitions(-DOPENSSL_NO_ASM)
|
|
|
|
set(ARCH "generic")
|
|
|
|
endif()
|
|
|
|
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
# Declare a dummy target to build all unit tests. Test targets should inject
|
|
|
|
# themselves as dependencies next to the target definition.
|
|
|
|
add_custom_target(all_tests)
|
|
|
|
|
2014-06-20 20:00:00 +01:00
|
|
|
add_subdirectory(crypto)
|
|
|
|
add_subdirectory(ssl)
|
|
|
|
add_subdirectory(ssl/test)
|
|
|
|
add_subdirectory(tool)
|
2015-02-03 18:45:12 +00:00
|
|
|
add_subdirectory(decrepit)
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
|
2015-11-09 21:57:26 +00:00
|
|
|
if(FUZZ)
|
|
|
|
add_subdirectory(fuzz)
|
|
|
|
endif()
|
|
|
|
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
|
|
|
|
# USES_TERMINAL is only available in CMake 3.2 or later.
|
|
|
|
set(MAYBE_USES_TERMINAL USES_TERMINAL)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_target(
|
|
|
|
run_tests
|
|
|
|
COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
|
|
|
|
${CMAKE_BINARY_DIR}
|
|
|
|
COMMAND cd ssl/test/runner
|
|
|
|
COMMAND ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
|
2016-03-02 03:57:46 +00:00
|
|
|
${RUNNER_ARGS}
|
Add a run_tests target to run all tests.
It's very annoying having to remember the right incant every time I want
to switch around between my build, build-release, build-asan, etc.,
output directories.
Unfortunately, this target is pretty unfriendly without CMake 3.2+ (and
Ninja 1.5+). This combination gives a USES_TERMINAL flag to
add_custom_target which uses Ninja's "console" pool, otherwise the
output buffering gets in the way. Ubuntu LTS is still on an older CMake,
so do a version check in the meantime.
CMake also has its own test mechanism (CTest), but this doesn't use it.
It seems to prefer knowing what all the tests are and then tries to do
its own output management and parallelizing and such. We already have
our own runners. all_tests.go could actually be converted tidily, but
generate_build_files.py also needs to read it, and runner.go has very
specific needs.
Naming the target ninja -C build test would be nice, but CTest squats
that name and CMake grumps when you use a reserved name, so I've gone
with run_tests.
Change-Id: Ibd20ebd50febe1b4e91bb19921f3bbbd9fbcf66c
Reviewed-on: https://boringssl-review.googlesource.com/6270
Reviewed-by: Adam Langley <alangley@gmail.com>
2015-10-15 02:34:40 +01:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
DEPENDS all_tests bssl_shim
|
|
|
|
${MAYBE_USES_TERMINAL})
|