Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

404 lignes
16 KiB

  1. cmake_minimum_required (VERSION 2.8.11)
  2. # Report AppleClang separately from Clang. Their version numbers are different.
  3. # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html
  4. if(POLICY CMP0025)
  5. cmake_policy(SET CMP0025 NEW)
  6. endif()
  7. # Defer enabling C and CXX languages.
  8. project (BoringSSL NONE)
  9. if(WIN32)
  10. # On Windows, prefer cl over gcc if both are available. By default most of
  11. # the CMake generators prefer gcc, even on Windows.
  12. set(CMAKE_GENERATOR_CC cl)
  13. endif()
  14. include(sources.cmake)
  15. enable_language(C)
  16. enable_language(CXX)
  17. if(ANDROID)
  18. # Android-NDK CMake files reconfigure the path and so Go and Perl won't be
  19. # found. However, ninja will still find them in $PATH if we just name them.
  20. if(NOT PERL_EXECUTABLE)
  21. set(PERL_EXECUTABLE "perl")
  22. endif()
  23. if(NOT GO_EXECUTABLE)
  24. set(GO_EXECUTABLE "go")
  25. endif()
  26. else()
  27. find_package(Perl REQUIRED)
  28. find_program(GO_EXECUTABLE go)
  29. endif()
  30. if (NOT GO_EXECUTABLE)
  31. message(FATAL_ERROR "Could not find Go")
  32. endif()
  33. if (BORINGSSL_ALLOW_CXX_RUNTIME)
  34. add_definitions(-DBORINGSSL_ALLOW_CXX_RUNTIME)
  35. endif()
  36. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  37. set(CLANG 1)
  38. endif()
  39. if(CMAKE_COMPILER_IS_GNUCXX OR CLANG)
  40. # Note clang-cl is odd and sets both CLANG and MSVC. We base our configuration
  41. # primarily on our normal Clang one.
  42. set(C_CXX_FLAGS "-Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings")
  43. if(MSVC)
  44. # clang-cl sets different default warnings than clang. It also treats -Wall
  45. # as -Weverything, to match MSVC. Instead -W3 is the alias for -Wall.
  46. # See http://llvm.org/viewvc/llvm-project?view=revision&revision=319116
  47. set(C_CXX_FLAGS "${C_CXX_FLAGS} -W3 -Wno-unused-parameter -fmsc-version=1900")
  48. # googletest suppresses warning C4996 via a pragma, but clang-cl does not
  49. # honor it. Suppress it here to compensate. See https://crbug.com/772117.
  50. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-deprecated-declarations")
  51. else()
  52. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wall -ggdb -fvisibility=hidden -fno-common")
  53. endif()
  54. if(CLANG)
  55. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics")
  56. else()
  57. # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
  58. # and declare that the code is trying to free a stack pointer.
  59. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object")
  60. endif()
  61. if(CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  62. set(C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough")
  63. endif()
  64. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CXX_FLAGS} -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes")
  65. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CXX_FLAGS} -Wmissing-declarations")
  66. if(NOT MSVC)
  67. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  68. if(APPLE)
  69. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  70. endif()
  71. if(NOT BORINGSSL_ALLOW_CXX_RUNTIME)
  72. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
  73. endif()
  74. endif()
  75. # In GCC, -Wmissing-declarations is the C++ spelling of -Wmissing-prototypes
  76. # and using the wrong one is an error. In Clang, -Wmissing-prototypes is the
  77. # spelling for both and -Wmissing-declarations is some other warning.
  78. #
  79. # https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Warning-Options.html#Warning-Options
  80. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-prototypes
  81. # https://clang.llvm.org/docs/DiagnosticsReference.html#wmissing-declarations
  82. if(CLANG)
  83. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-prototypes")
  84. endif()
  85. if(CMAKE_COMPILER_IS_GNUCXX AND "4.8" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
  86. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-array-bounds")
  87. endif()
  88. elseif(MSVC)
  89. set(MSVC_DISABLED_WARNINGS_LIST
  90. "C4061" # enumerator 'identifier' in switch of enum 'enumeration' is not
  91. # explicitly handled by a case label
  92. # Disable this because it flags even when there is a default.
  93. "C4100" # 'exarg' : unreferenced formal parameter
  94. "C4127" # conditional expression is constant
  95. "C4200" # nonstandard extension used : zero-sized array in
  96. # struct/union.
  97. "C4204" # nonstandard extension used: non-constant aggregate initializer
  98. "C4221" # nonstandard extension used : 'identifier' : cannot be
  99. # initialized using address of automatic variable
  100. "C4242" # 'function' : conversion from 'int' to 'uint8_t',
  101. # possible loss of data
  102. "C4244" # 'function' : conversion from 'int' to 'uint8_t',
  103. # possible loss of data
  104. "C4267" # conversion from 'size_t' to 'int', possible loss of data
  105. "C4371" # layout of class may have changed from a previous version of the
  106. # compiler due to better packing of member '...'
  107. "C4388" # signed/unsigned mismatch
  108. "C4296" # '>=' : expression is always true
  109. "C4350" # behavior change: 'std::_Wrap_alloc...'
  110. "C4365" # '=' : conversion from 'size_t' to 'int',
  111. # signed/unsigned mismatch
  112. "C4389" # '!=' : signed/unsigned mismatch
  113. "C4464" # relative include path contains '..'
  114. "C4510" # 'argument' : default constructor could not be generated
  115. "C4512" # 'argument' : assignment operator could not be generated
  116. "C4514" # 'function': unreferenced inline function has been removed
  117. "C4548" # expression before comma has no effect; expected expression with
  118. # side-effect" caused by FD_* macros.
  119. "C4610" # struct 'argument' can never be instantiated - user defined
  120. # constructor required.
  121. "C4623" # default constructor was implicitly defined as deleted
  122. "C4625" # copy constructor could not be generated because a base class
  123. # copy constructor is inaccessible or deleted
  124. "C4626" # assignment operator could not be generated because a base class
  125. # assignment operator is inaccessible or deleted
  126. "C4668" # 'symbol' is not defined as a preprocessor macro, replacing with
  127. # '0' for 'directives'
  128. # Disable this because GTest uses it everywhere.
  129. "C4706" # assignment within conditional expression
  130. "C4710" # 'function': function not inlined
  131. "C4711" # function 'function' selected for inline expansion
  132. "C4800" # 'int' : forcing value to bool 'true' or 'false'
  133. # (performance warning)
  134. "C4820" # 'bytes' bytes padding added after construct 'member_name'
  135. "C5026" # move constructor was implicitly defined as deleted
  136. "C5027" # move assignment operator was implicitly defined as deleted
  137. )
  138. set(MSVC_LEVEL4_WARNINGS_LIST
  139. # See https://connect.microsoft.com/VisualStudio/feedback/details/1217660/warning-c4265-when-using-functional-header
  140. "C4265" # class has virtual functions, but destructor is not virtual
  141. )
  142. string(REPLACE "C" " -wd" MSVC_DISABLED_WARNINGS_STR
  143. ${MSVC_DISABLED_WARNINGS_LIST})
  144. string(REPLACE "C" " -w4" MSVC_LEVEL4_WARNINGS_STR
  145. ${MSVC_LEVEL4_WARNINGS_LIST})
  146. set(CMAKE_C_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  147. set(CMAKE_CXX_FLAGS "-utf-8 -Wall -WX ${MSVC_DISABLED_WARNINGS_STR} ${MSVC_LEVEL4_WARNINGS_STR}")
  148. endif()
  149. if(WIN32)
  150. add_definitions(-D_HAS_EXCEPTIONS=0)
  151. add_definitions(-DWIN32_LEAN_AND_MEAN)
  152. add_definitions(-DNOMINMAX)
  153. # Allow use of fopen.
  154. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  155. # VS 2017 and higher supports STL-only warning suppressions.
  156. add_definitions("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987")
  157. endif()
  158. if((CMAKE_COMPILER_IS_GNUCXX AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.7.99") OR
  159. CLANG)
  160. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
  161. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
  162. endif()
  163. if(CMAKE_COMPILER_IS_GNUCXX)
  164. if ((CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8.99") OR CLANG)
  165. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
  166. else()
  167. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  168. endif()
  169. endif()
  170. # pthread_rwlock_t requires a feature flag.
  171. if(NOT WIN32)
  172. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
  173. endif()
  174. if(FUZZ)
  175. if(NOT CLANG)
  176. message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
  177. endif()
  178. add_definitions(-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE)
  179. set(RUNNER_ARGS "-deterministic")
  180. if(NOT NO_FUZZER_MODE)
  181. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  182. set(RUNNER_ARGS ${RUNNER_ARGS} "-fuzzer" "-shim-config" "fuzzer_mode.json")
  183. endif()
  184. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
  185. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,trace-pc-guard")
  186. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  187. link_directories(.)
  188. endif()
  189. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  190. if (BUILD_SHARED_LIBS)
  191. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  192. # Enable position-independent code globally. This is needed because
  193. # some library targets are OBJECT libraries.
  194. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  195. endif()
  196. if (MSAN)
  197. if(NOT CLANG)
  198. message(FATAL_ERROR "Cannot enable MSAN unless using Clang")
  199. endif()
  200. if (ASAN)
  201. message(FATAL_ERROR "ASAN and MSAN are mutually exclusive")
  202. endif()
  203. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  204. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
  205. set(OPENSSL_NO_ASM "1")
  206. endif()
  207. if (ASAN)
  208. if(NOT CLANG)
  209. message(FATAL_ERROR "Cannot enable ASAN unless using Clang")
  210. endif()
  211. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  212. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
  213. set(OPENSSL_NO_ASM "1")
  214. endif()
  215. if(CFI)
  216. if(NOT CLANG)
  217. message(FATAL_ERROR "Cannot enable CFI unless using Clang")
  218. endif()
  219. # TODO(crbug.com/785442): Remove -fsanitize-cfi-icall-generalize-pointers.
  220. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
  221. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=cfi -fno-sanitize-trap=cfi -fsanitize-cfi-icall-generalize-pointers -flto")
  222. # We use Chromium's copy of clang, which requires -fuse-ld=lld if building
  223. # with -flto. That, in turn, can't handle -ggdb.
  224. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
  225. string(REPLACE "-ggdb" "-g" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  226. string(REPLACE "-ggdb" "-g" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  227. # -flto causes object files to contain LLVM bitcode. Mixing those with
  228. # assembly output in the same static library breaks the linker.
  229. set(OPENSSL_NO_ASM "1")
  230. endif()
  231. if (GCOV)
  232. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  233. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  234. endif()
  235. if(FIPS)
  236. add_definitions(-DBORINGSSL_FIPS)
  237. if(FIPS_BREAK_TEST)
  238. add_definitions("-DBORINGSSL_FIPS_BREAK_${FIPS_BREAK_TEST}=1")
  239. endif()
  240. # Delocate does not work for ASan and MSan builds.
  241. if(NOT ASAN AND NOT MSAN)
  242. set(FIPS_DELOCATE "1")
  243. endif()
  244. endif()
  245. if(OPENSSL_SMALL)
  246. add_definitions(-DOPENSSL_SMALL)
  247. endif()
  248. # CMake's iOS support uses Apple's multiple-architecture toolchain. It takes an
  249. # architecture list from CMAKE_OSX_ARCHITECTURES, leaves CMAKE_SYSTEM_PROCESSOR
  250. # alone, and expects all architecture-specific logic to be conditioned within
  251. # the source files rather than the build. This does not work for our assembly
  252. # files, so we fix CMAKE_SYSTEM_PROCESSOR and only support single-architecture
  253. # builds.
  254. if (NOT OPENSSL_NO_ASM AND CMAKE_OSX_ARCHITECTURES)
  255. list(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHES)
  256. if (NOT ${NUM_ARCHES} EQUAL 1)
  257. message(FATAL_ERROR "Universal binaries not supported.")
  258. endif()
  259. list(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_SYSTEM_PROCESSOR)
  260. endif()
  261. if (OPENSSL_NO_ASM)
  262. add_definitions(-DOPENSSL_NO_ASM)
  263. set(ARCH "generic")
  264. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  265. set(ARCH "x86_64")
  266. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  267. set(ARCH "x86_64")
  268. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  269. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  270. if (CMAKE_CL_64)
  271. set(ARCH "x86_64")
  272. else()
  273. set(ARCH "x86")
  274. endif()
  275. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  276. set(ARCH "x86")
  277. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  278. set(ARCH "x86")
  279. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  280. set(ARCH "x86")
  281. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  282. set(ARCH "aarch64")
  283. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
  284. set(ARCH "aarch64")
  285. elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm*")
  286. set(ARCH "arm")
  287. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "mips")
  288. # Just to avoid the “unknown processor” error.
  289. set(ARCH "generic")
  290. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "ppc64le")
  291. set(ARCH "ppc64le")
  292. else()
  293. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  294. endif()
  295. if (ANDROID AND NOT ANDROID_NDK_REVISION AND ${ARCH} STREQUAL "arm")
  296. # The third-party Android-NDK CMake files somehow fail to set the -march flag
  297. # for assembly files. Without this flag, the compiler believes that it's
  298. # building for ARMv5.
  299. set(CMAKE_ASM_FLAGS "-march=${CMAKE_SYSTEM_PROCESSOR} ${CMAKE_ASM_FLAGS}")
  300. endif()
  301. if (${ARCH} STREQUAL "x86" AND APPLE AND ${CMAKE_VERSION} VERSION_LESS "3.0")
  302. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  303. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  304. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  305. set(ARCH "x86_64")
  306. endif()
  307. # Add minimal googletest targets. The provided one has many side-effects, and
  308. # googletest has a very straightforward build.
  309. add_library(boringssl_gtest third_party/googletest/src/gtest-all.cc)
  310. target_include_directories(boringssl_gtest PRIVATE third_party/googletest)
  311. include_directories(third_party/googletest/include)
  312. # Declare a dummy target to build all unit tests. Test targets should inject
  313. # themselves as dependencies next to the target definition.
  314. add_custom_target(all_tests)
  315. add_custom_command(
  316. OUTPUT crypto_test_data.cc
  317. COMMAND ${GO_EXECUTABLE} run util/embed_test_data.go ${CRYPTO_TEST_DATA} >
  318. ${CMAKE_CURRENT_BINARY_DIR}/crypto_test_data.cc
  319. DEPENDS util/embed_test_data.go ${CRYPTO_TEST_DATA}
  320. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  321. add_library(crypto_test_data OBJECT crypto_test_data.cc)
  322. add_subdirectory(crypto)
  323. add_subdirectory(third_party/fiat)
  324. add_subdirectory(ssl)
  325. add_subdirectory(ssl/test)
  326. add_subdirectory(fipstools)
  327. add_subdirectory(tool)
  328. add_subdirectory(decrepit)
  329. if(FUZZ)
  330. if(LIBFUZZER_FROM_DEPS)
  331. file(GLOB LIBFUZZER_SOURCES "util/bot/libFuzzer/*.cpp")
  332. add_library(Fuzzer STATIC ${LIBFUZZER_SOURCES})
  333. # libFuzzer does not pass our aggressive warnings. It also must be built
  334. # without -fsanitize-coverage options or clang crashes.
  335. set_target_properties(Fuzzer PROPERTIES COMPILE_FLAGS "-Wno-shadow -Wno-format-nonliteral -Wno-missing-prototypes -fsanitize-coverage=0")
  336. endif()
  337. add_subdirectory(fuzz)
  338. endif()
  339. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  340. # USES_TERMINAL is only available in CMake 3.2 or later.
  341. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  342. endif()
  343. add_custom_target(
  344. run_tests
  345. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  346. ${CMAKE_BINARY_DIR}
  347. COMMAND cd ssl/test/runner &&
  348. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  349. ${RUNNER_ARGS}
  350. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  351. DEPENDS all_tests bssl_shim
  352. ${MAYBE_USES_TERMINAL})