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.
 
 
 
 
 
 

231 lines
8.9 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. "C4204" # nonstandard extension used: non-constant aggregate initializer
  45. "C4221" # nonstandard extension used : 'identifier' : cannot be
  46. # initialized using address of automatic variable
  47. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  48. # possible loss of data
  49. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  50. # possible loss of data
  51. "C4245" # 'initializing' : conversion from 'long' to
  52. # 'unsigned long', signed/unsigned mismatch
  53. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  54. "C4371" # layout of class may have changed from a previous version of the
  55. # compiler due to better packing of member '...'
  56. "C4388" # signed/unsigned mismatch
  57. "C4296" # '>=' : expression is always true
  58. "C4350" # behavior change: 'std::_Wrap_alloc...'
  59. "C4365" # '=' : conversion from 'size_t' to 'int',
  60. # signed/unsigned mismatch
  61. "C4389" # '!=' : signed/unsigned mismatch
  62. "C4464" # relative include path contains '..'
  63. "C4510" # 'argument' : default constructor could not be generated
  64. "C4512" # 'argument' : assignment operator could not be generated
  65. "C4514" # 'function': unreferenced inline function has been removed
  66. "C4548" # expression before comma has no effect; expected expression with
  67. # side-effect" caused by FD_* macros.
  68. "C4610" # struct 'argument' can never be instantiated - user defined
  69. # constructor required.
  70. "C4623" # default constructor was implicitly defined as deleted
  71. "C4625" # copy constructor could not be generated because a base class
  72. # copy constructor is inaccessible or deleted
  73. "C4626" # assignment operator could not be generated because a base class
  74. # assignment operator is inaccessible or deleted
  75. "C4706" # assignment within conditional expression
  76. "C4710" # 'function': function not inlined
  77. "C4711" # function 'function' selected for inline expansion
  78. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  79. # (performance warning)
  80. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  81. "C5027" # move assignment operator was implicitly defined as deleted
  82. )
  83. set(MSVC_LEVEL4_WARNINGS_LIST
  84. # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
  85. "C4265" # class has virtual functions, but destructor is not virtual
  86. )
  87. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  88. ${MSVC_DISABLED_WARNINGS_LIST})
  89. string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
  90. ${MSVC_LEVEL4_WARNINGS_LIST})
  91. set(CMAKE_C_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  92. set(CMAKE_CXX_FLAGS "-Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  93. set(CMAKE_ASM_NASM_FLAGS "-g cv8")
  94. add_definitions(-D_HAS_EXCEPTIONS=0)
  95. add_definitions(-DWIN32_LEAN_AND_MEAN)
  96. add_definitions(-DNOMINMAX)
  97. add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Allow use of fopen
  98. endif()
  99. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  100. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  101. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  102. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  103. endif()
  104. if(CMAKE_COMPILER_IS_GNUCXX)
  105. if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR
  106. CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  107. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
  108. else()
  109. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  110. endif()
  111. endif()
  112. # pthread_rwlock_t requires a feature flag.
  113. if(NOT WIN32)
  114. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
  115. endif()
  116. if(FUZZ)
  117. if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  118. message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  119. endif()
  120. add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
  121. set(RUNNER_ARGS "-deterministic")
  122. if(NOT NO_FUZZER_MODE)
  123. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  124. set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
  125. endif()
  126. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  127. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  128. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  129. link_directories(.)
  130. endif()
  131. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  132. if (BUILD_SHARED_LIBS)
  133. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  134. # Enable position-independent code globally. This is needed because
  135. # some library targets are OBJECT libraries.
  136. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  137. endif()
  138. if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  139. set(ARCH "x86_64")
  140. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  141. set(ARCH "x86_64")
  142. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  143. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  144. if (CMAKE_CL_64)
  145. set(ARCH "x86_64")
  146. else()
  147. set(ARCH "x86")
  148. endif()
  149. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  150. set(ARCH "x86")
  151. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  152. set(ARCH "x86")
  153. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  154. set(ARCH "x86")
  155. elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
  156. set(ARCH "arm")
  157. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  158. set(ARCH "aarch64")
  159. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
  160. # Just to avoid the “unknown processor” error.
  161. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
  162. set(ARCH "ppc64le")
  163. else()
  164. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  165. endif()
  166. if (ANDROID AND ${ARCH} STREQUAL "arm")
  167. # The Android-NDK CMake files somehow fail to set the -march flag for
  168. # assembly files. Without this flag, the compiler believes that it's
  169. # building for ARMv5.
  170. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
  171. endif()
  172. if (${ARCH} STREQUAL "x86" AND APPLE)
  173. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  174. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  175. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  176. set(ARCH "x86_64")
  177. endif()
  178. if (OPENSSL_NO_ASM)
  179. add_definitions(-DOPENSSL_NO_ASM)
  180. set(ARCH "generic")
  181. endif()
  182. # Declare a dummy target to build all unit tests. Test targets should inject
  183. # themselves as dependencies next to the target definition.
  184. add_custom_target(all_tests)
  185. add_subdirectory(crypto)
  186. add_subdirectory(ssl)
  187. add_subdirectory(ssl/test)
  188. add_subdirectory(tool)
  189. add_subdirectory(decrepit)
  190. if(FUZZ)
  191. add_subdirectory(fuzz)
  192. endif()
  193. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  194. # USES_TERMINAL is only available in CMake 3.2 or later.
  195. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  196. endif()
  197. add_custom_target(
  198. run_tests
  199. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  200. ${CMAKE_BINARY_DIR}
  201. COMMAND cd ssl/test/runner &&
  202. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  203. ${RUNNER_ARGS}
  204. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  205. DEPENDS all_tests bssl_shim
  206. ${MAYBE_USES_TERMINAL})