You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

230 lines
8.7 KiB

  1. cmake_minimum_required (VERSION 2.8.10)
  2. # Defer enabling C and CXX languages.
  3. project (BoringSSL NONE)
  4. if(WIN32)
  5. # On Windows, prefer cl over gcc if both are available. By default most of
  6. # the CMake generators prefer gcc, even on Windows.
  7. set(CMAKE_GENERATOR_CC cl)
  8. endif()
  9. enable_language(C)
  10. enable_language(CXX)
  11. if(ANDROID)
  12. # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
  13. # found. However, ninja will still find them in $PATH if we just name them.
  14. if(NOT PERL_EXECUTABLE)
  15. set(PERL_EXECUTABLE "perl")
  16. endif()
  17. if(NOT GO_EXECUTABLE)
  18. set(GO_EXECUTABLE "go")
  19. endif()
  20. else()
  21. find_package(Perl REQUIRED)
  22. find_program(GO_EXECUTABLE go)
  23. endif()
  24. if (NOT GO_EXECUTABLE)
  25. message(FATAL_ERROR "Could not find Go")
  26. endif()
  27. if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  28. set(C_CXX_FLAGS "-Wall -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -ggdb -fvisibility=hidden -fno-common")
  29. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  30. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof")
  31. endif()
  32. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
  33. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ${C_CXX_FLAGS} -Wmissing-declarations")
  34. # Clang's integerated assembler does not support debug symbols.
  35. if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  36. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-g")
  37. endif()
  38. elseif(MSVC)
  39. set(MSVC_DISABLED_WARNINGS_LIST
  40. "C4100" # 'exarg' : unreferenced formal parameter
  41. "C4127" # conditional expression is constant
  42. "C4200" # nonstandard extension used : zero-sized array in
  43. # struct/union.
  44. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  45. # possible loss of data
  46. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  47. # possible loss of data
  48. "C4245" # 'initializing' : conversion from 'long' to
  49. # 'unsigned long', signed/unsigned mismatch
  50. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  51. "C4371" # layout of class may have changed from a previous version of the
  52. # compiler due to better packing of member '...'
  53. "C4388" # signed/unsigned mismatch
  54. "C4296" # '>=' : expression is always true
  55. "C4350" # behavior change: 'std::_Wrap_alloc...'
  56. "C4365" # '=' : conversion from 'size_t' to 'int',
  57. # signed/unsigned mismatch
  58. "C4389" # '!=' : signed/unsigned mismatch
  59. "C4464" # relative include path contains '..'
  60. "C4510" # 'argument' : default constructor could not be generated
  61. "C4512" # 'argument' : assignment operator could not be generated
  62. "C4514" # 'function': unreferenced inline function has been removed
  63. "C4548" # expression before comma has no effect; expected expression with
  64. # side-effect" caused by FD_* macros.
  65. "C4610" # struct 'argument' can never be instantiated - user defined
  66. # constructor required.
  67. "C4623" # default constructor was implicitly defined as deleted
  68. "C4625" # copy constructor could not be generated because a base class
  69. # copy constructor is inaccessible or deleted
  70. "C4626" # assignment operator could not be generated because a base class
  71. # assignment operator is inaccessible or deleted
  72. "C4706" # assignment within conditional expression
  73. "C4710" # 'function': function not inlined
  74. "C4711" # function 'function' selected for inline expansion
  75. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  76. # (performance warning)
  77. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  78. "C5027" # move assignment operator was implicitly defined as deleted
  79. )
  80. set(MSVC_LEVEL4_WARNINGS_LIST
  81. # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
  82. "C4265" # class has virtual functions, but destructor is not virtual
  83. )
  84. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  85. ${MSVC_DISABLED_WARNINGS_LIST})
  86. string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
  87. ${MSVC_LEVEL4_WARNINGS_LIST})
  88. set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  89. set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  90. set(CMAKE_ASM_NASM_FLAGS "-g cv8")
  91. add_definitions(-D_HAS_EXCEPTIONS=0)
  92. add_definitions(-DWIN32_LEAN_AND_MEAN)
  93. add_definitions(-DNOMINMAX)
  94. add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Allow use of fopen
  95. endif()
  96. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  97. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  98. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  99. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  100. endif()
  101. if(CMAKE_COMPILER_IS_GNUCXX)
  102. if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
  103. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  104. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
  105. else()
  106. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  107. endif()
  108. endif()
  109. # pthread_rwlock_t requires a feature flag.
  110. if(NOT WIN32)
  111. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
  112. endif()
  113. if(FUZZ)
  114. if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  115. message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  116. endif()
  117. add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
  118. set(RUNNER_ARGS "-deterministic")
  119. if(NOT NO_FUZZER_MODE)
  120. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  121. set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
  122. endif()
  123. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  124. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  125. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  126. link_directories(.)
  127. endif()
  128. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  129. if (BUILD_SHARED_LIBS)
  130. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  131. # Enable position-independent code globally. This is needed because
  132. # some library targets are OBJECT libraries.
  133. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  134. endif()
  135. if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  136. set(ARCH "x86_64")
  137. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  138. set(ARCH "x86_64")
  139. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  140. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  141. if (CMAKE_CL_64)
  142. set(ARCH "x86_64")
  143. else()
  144. set(ARCH "x86")
  145. endif()
  146. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  147. set(ARCH "x86")
  148. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  149. set(ARCH "x86")
  150. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  151. set(ARCH "x86")
  152. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
  153. set(ARCH "arm")
  154. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
  155. set(ARCH "arm")
  156. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
  157. set(ARCH "arm")
  158. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  159. set(ARCH "aarch64")
  160. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
  161. # Just to avoid the “unknown processor” error.
  162. else()
  163. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  164. endif()
  165. if (ANDROID AND ${ARCH} STREQUAL "arm")
  166. # The Android-NDK CMake files somehow fail to set the -march flag for
  167. # assembly files. Without this flag, the compiler believes that it's
  168. # building for ARMv5.
  169. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
  170. endif()
  171. if (${ARCH} STREQUAL "x86" AND APPLE)
  172. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  173. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  174. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  175. set(ARCH "x86_64")
  176. endif()
  177. if (OPENSSL_NO_ASM)
  178. add_definitions(-DOPENSSL_NO_ASM)
  179. set(ARCH "generic")
  180. endif()
  181. # Declare a dummy target to build all unit tests. Test targets should inject
  182. # themselves as dependencies next to the target definition.
  183. add_custom_target(all_tests)
  184. add_subdirectory(crypto)
  185. add_subdirectory(ssl)
  186. add_subdirectory(ssl/test)
  187. add_subdirectory(tool)
  188. add_subdirectory(decrepit)
  189. if(FUZZ)
  190. add_subdirectory(fuzz)
  191. endif()
  192. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  193. # USES_TERMINAL is only available in CMake 3.2 or later.
  194. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  195. endif()
  196. add_custom_target(
  197. run_tests
  198. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  199. ${CMAKE_BINARY_DIR}
  200. COMMAND cd ssl/test/runner &&
  201. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  202. ${RUNNER_ARGS}
  203. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  204. DEPENDS all_tests bssl_shim
  205. ${MAYBE_USES_TERMINAL})