Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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