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.
 
 
 
 
 
 

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