Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CMakeLists.txt 8.4 KiB

Fix build when using Visual Studio 2015 Update 1. Many of the compatibility issues are described at https://msdn.microsoft.com/en-us/library/mt612856.aspx. The macros that suppressed warnings on a per-function basis no longer work in Update 1, so replace them with #pragmas. Update 1 warns when |size_t| arguments to |printf| are casted, so stop doing that casting. Unfortunately, this requires an ugly hack to continue working in MSVC 2013 as MSVC 2013 doesn't support "%zu". Finally, Update 1 has new warnings, some of which need to be suppressed. --- Updated by davidben to give up on suppressing warnings in crypto/x509 and crypto/x509v3 as those directories aren't changed much from upstream. In each of these cases, upstream opted just blindly initialize the variable, so do the same. Also switch C4265 to level 4, per Microsoft's recommendation and work around a bug in limits.h that happens to get fixed by Google include order style. (limits.h is sensitive to whether corecrt.h, pulled in by stddef.h and some other headers, is included before it. The reason it affected just one file is we often put the file's header first, which means base.h is pulling in stddef.h. Relying on this is ugly, but it's no worse than what everything else is doing and this doesn't seem worth making something as tame as limits.h so messy to use.) Change-Id: I02d1f935356899f424d3525d03eca401bfa3e6cd Reviewed-on: https://boringssl-review.googlesource.com/7480 Reviewed-by: David Benjamin <davidben@google.com>
před 8 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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(!CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  115. message("You need to build with Clang for fuzzing to work")
  116. endif()
  117. add_definitions(-DBORINGSSL_UNSAFE_FUZZER_MODE)
  118. set(RUNNER_ARGS "-fuzzer")
  119. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  120. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=edge,indirect-calls,8bit-counters")
  121. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  122. link_directories(.)
  123. endif()
  124. add_definitions(-DBORINGSSL_IMPLEMENTATION)
  125. if (BUILD_SHARED_LIBS)
  126. add_definitions(-DBORINGSSL_SHARED_LIBRARY)
  127. # Enable position-independent code globally. This is needed because
  128. # some library targets are OBJECT libraries.
  129. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  130. endif()
  131. if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
  132. set(ARCH "x86_64")
  133. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "amd64")
  134. set(ARCH "x86_64")
  135. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64")
  136. # cmake reports AMD64 on Windows, but we might be building for 32-bit.
  137. if (CMAKE_CL_64)
  138. set(ARCH "x86_64")
  139. else()
  140. set(ARCH "x86")
  141. endif()
  142. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86")
  143. set(ARCH "x86")
  144. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
  145. set(ARCH "x86")
  146. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
  147. set(ARCH "x86")
  148. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
  149. set(ARCH "arm")
  150. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv6")
  151. set(ARCH "arm")
  152. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a")
  153. set(ARCH "arm")
  154. elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
  155. set(ARCH "aarch64")
  156. else()
  157. message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR})
  158. endif()
  159. if (ANDROID AND ${ARCH} STREQUAL "arm")
  160. # The Android-NDK CMake files somehow fail to set the -march flag for
  161. # assembly files. Without this flag, the compiler believes that it's
  162. # building for ARMv5.
  163. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${CMAKE_SYSTEM_PROCESSOR}")
  164. endif()
  165. if (${ARCH} STREQUAL "x86" AND APPLE)
  166. # With CMake 2.8.x, ${CMAKE_SYSTEM_PROCESSOR} evalutes to i386 on OS X,
  167. # but clang defaults to 64-bit builds on OS X unless otherwise told.
  168. # Set ARCH to x86_64 so clang and CMake agree. This is fixed in CMake 3.
  169. set(ARCH "x86_64")
  170. endif()
  171. if (OPENSSL_NO_ASM)
  172. add_definitions(-DOPENSSL_NO_ASM)
  173. set(ARCH "generic")
  174. endif()
  175. # Declare a dummy target to build all unit tests. Test targets should inject
  176. # themselves as dependencies next to the target definition.
  177. add_custom_target(all_tests)
  178. add_subdirectory(crypto)
  179. add_subdirectory(ssl)
  180. add_subdirectory(ssl/test)
  181. add_subdirectory(tool)
  182. add_subdirectory(decrepit)
  183. if(FUZZ)
  184. add_subdirectory(fuzz)
  185. endif()
  186. if (NOT ${CMAKE_VERSION} VERSION_LESS "3.2")
  187. # USES_TERMINAL is only available in CMake 3.2 or later.
  188. set(MAYBE_USES_TERMINAL USES_TERMINAL)
  189. endif()
  190. add_custom_target(
  191. run_tests
  192. COMMAND ${GO_EXECUTABLE} run util/all_tests.go -build-dir
  193. ${CMAKE_BINARY_DIR}
  194. COMMAND cd ssl/test/runner &&
  195. ${GO_EXECUTABLE} test -shim-path $<TARGET_FILE:bssl_shim>
  196. ${RUNNER_ARGS}
  197. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  198. DEPENDS all_tests bssl_shim
  199. ${MAYBE_USES_TERMINAL})