25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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