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.
 
 
 
 
 
 

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