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.
 
 
 
 
 
 

333 lignes
13 KiB

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